Skip to contentSkip to conversation

staging: goldfish_audio.c: sparse warning of incorrect type

PATCH In review Sudip Mukherjee 4 participants 5 messages Aug 31, 2014 – Sep 1, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: goldfish_audio.c: sparse warning of incorrect type

fixed sparse warning of incorrect type in argument 1 and incorrect type in argument 2
it was directly dereferencing a __iomem pointer , which will work in x86 but will fail in other architectures.

---

hi,
can you please reveiew the patch and check if the approach is correct. If it is correct then I can send another patch to correct the other similar warnings present in this file.

 drivers/staging/goldfish/goldfish_audio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/goldfish/goldfish_audio.c +9 -2
index c89d0b8..f9a13e7 100644
@@ -118,6 +118,7 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 	struct goldfish_audio *data = fp->private_data;
 	int length;
 	int result = 0;
+	void *buffer;
 
 	if (!data->read_supported)
 		return -ENODEV;
@@ -133,9 +134,15 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 						AUDIO_READ_BUFFER_AVAILABLE);
 
 		/* copy data to user space */
-		if (copy_to_user(buf, data->read_buffer, length))
+		buffer = kzalloc(length, GFP_KERNEL);
+		if (buffer == NULL)
+			return -ENOMEM;
+		memcpy_fromio(buffer, data->read_buffer, length);
+		if (copy_to_user((void __user *)buf, buffer, length)) {
+			kfree(buffer);
 			return -EFAULT;
-
+		}
+		kfree(buffer);
 		result += length;
 		buf += length;
 		count -= length;
Signature · 1 line
1.8.1.2
#1 lore raw

Adding Alan Cox, as he pushed this driver upstream...

Quoted 2 lines · Sudip Mukherjee

fixed sparse warning of incorrect type in argument 1 and incorrect type in argument 2
it was directly dereferencing a __iomem pointer , which will work in x86 but will fail in other architectures.

Please wrap your changelog comments at 72 columns...

Quoted 5 lines

---

hi,
can you please reveiew the patch and check if the approach is correct. If it is correct then I can send another patch to correct the other similar warnings present in this file.

I don't think this is correct, because:

Quoted 21 lines
 drivers/staging/goldfish/goldfish_audio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/goldfish/goldfish_audio.c +1 -1
index c89d0b8..f9a13e7 100644
@@ -118,6 +118,7 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 	struct goldfish_audio *data = fp->private_data;
 	int length;
 	int result = 0;
+	void *buffer;
 
 	if (!data->read_supported)
 		return -ENODEV;
@@ -133,9 +134,15 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 						AUDIO_READ_BUFFER_AVAILABLE);
 
 		/* copy data to user space */
-		if (copy_to_user(buf, data->read_buffer, length))

drivers/staging/goldfish/goldfish_audio.c static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, · line 145

Quoted 10 lines
drivers/staging/goldfish/goldfish_audio.c +8 -1
+		buffer = kzalloc(length, GFP_KERNEL);
+		if (buffer == NULL)
+			return -ENOMEM;
+		memcpy_fromio(buffer, data->read_buffer, length);
+		if (copy_to_user((void __user *)buf, buffer, length)) {
+			kfree(buffer);
 			return -EFAULT;
-
+		}
+		kfree(buffer);

The goldfish platform is an "emulator" so iomem is (or should be?) the same as "normal" memory here. So I think this is a false-positive.

But I could be totally wrong here, Alan?

thanks,

greg k-h

#2 lore raw
Quoted 1 line · Greg Kroah-Hartman

Adding Alan Cox, as he pushed this driver upstream...

It's sort of a false positive. The existing code will work fine.

Arguably all of this should be using the dma_ APIs.

Alan

#3 lore raw
In reply to Sudip Mukherjee

drivers/staging/goldfish/goldfish_audio.c static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, · line 141

Quoted 10 lines · Sudip Mukherjee
drivers/staging/goldfish/goldfish_audio.c +5 -1
@@ -133,9 +134,15 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 						AUDIO_READ_BUFFER_AVAILABLE);
 
 		/* copy data to user space */
-		if (copy_to_user(buf, data->read_buffer, length))
+		buffer = kzalloc(length, GFP_KERNEL);
+		if (buffer == NULL)
+			return -ENOMEM;
+		memcpy_fromio(buffer, data->read_buffer, length);
+		if (copy_to_user((void __user *)buf, buffer, length)) {
                                 ^^^^^^^^^^^^^^^

This cast shouldn't be needed.

regards,
dan carpenter

#4 lore raw
Quoted 12 lines · Dan Carpenter

drivers/staging/goldfish/goldfish_audio.c static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, · line 141

Quoted 10 lines · Sudip Mukherjee
drivers/staging/goldfish/goldfish_audio.c +5 -1
@@ -133,9 +134,15 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
 						AUDIO_READ_BUFFER_AVAILABLE);
 
 		/* copy data to user space */
-		if (copy_to_user(buf, data->read_buffer, length))
+		buffer = kzalloc(length, GFP_KERNEL);
+		if (buffer == NULL)
+			return -ENOMEM;
+		memcpy_fromio(buffer, data->read_buffer, length);
+		if (copy_to_user((void __user *)buf, buffer, length)) {
                                 ^^^^^^^^^^^^^^^
Quoted 5 lines

This cast shouldn't be needed.

regards,
dan carpenter

yes , its not needed . I just checked it again after removing the cast. Actually I gave it as sparse was showing warning for argument 1 also. I should have rechecked it after fixing the warning for argument2. Sorry for it. Anyways, if Alan confirms that this patch is actually needed then I will resubmit a modified patch.

thanks
Sudip