Skip to contentSkip to conversation

usb: gadget: f_fs: remove unused values and add immediate returns

PATCH In review Karol Przybylski 2 participants 4 messages Nov 6, 2024 – Dec 15, 2024 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: f_fs: remove unused values and add immediate returns

In case of faulty copy_from_user call inside ffs_epfile_ioctl, error code is saved in a variable. However, this variable is later overwritten in every possible path, which overshadows initial assignment.

This patch fixes it by returning the error code immediately and exiting the function.

Error discovered in coverity scan - CID 1583682

---
 drivers/usb/gadget/function/f_fs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/usb/gadget/function/f_fs.c +3 -6
index 2920f8000bbd..00f52c9bb716 100644
@@ -1735,8 +1735,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
 		int fd;
 
 		if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) {
-			ret = -EFAULT;
-			break;
+			return -EFAULT;
 		}
 
 		return ffs_dmabuf_attach(file, fd);
@@ -1746,8 +1745,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
 		int fd;
 
 		if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) {
-			ret = -EFAULT;
-			break;
+			return -EFAULT;
 		}
 
 		return ffs_dmabuf_detach(file, fd);
@@ -1757,8 +1755,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
 		struct usb_ffs_dmabuf_transfer_req req;
 
 		if (copy_from_user(&req, (void __user *)value, sizeof(req))) {
-			ret = -EFAULT;
-			break;
+			return -EFAULT;
 		}
 
 		return ffs_dmabuf_transfer(file, &req);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 4 lines · Karol Przybylski

In case of faulty copy_from_user call inside ffs_epfile_ioctl, error code is saved in a variable. However, this variable is later overwritten in every possible path, which overshadows initial assignment.

Quoted 8 lines

This patch fixes it by returning the error code immediately and exiting the function.

Error discovered in coverity scan - CID 1583682

---
 drivers/usb/gadget/function/f_fs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

What commit id does this fix?

How was this change tested?

thanks,

greg k-h

author
#2 lore raw
Quoted 8 lines · Greg KH
Quoted 6 lines · Karol Przybylski

In case of faulty copy_from_user call inside ffs_epfile_ioctl, error code is saved in a variable. However, this variable is later overwritten in every possible path, which overshadows initial assignment.

This patch fixes it by returning the error code immediately and exiting the function.

Quoted 8 lines
Quoted 6 lines

Error discovered in coverity scan - CID 1583682

---
 drivers/usb/gadget/function/f_fs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

What commit id does this fix?

7b07a2a7ca02a, usb: gadget: functionfs: Add DMABUF import interface

Quoted 2 lines

How was this change tested?

I compiled the kernel and ran it on my machine. Are there other ways to reliably test such change?

Quoted 4 lines

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 11 lines · Karol P
Quoted 10 lines · Greg KH
Quoted 8 lines · Karol Przybylski

In case of faulty copy_from_user call inside ffs_epfile_ioctl, error code is saved in a variable. However, this variable is later overwritten in every possible path, which overshadows initial assignment.

This patch fixes it by returning the error code immediately and exiting the function.

Error discovered in coverity scan - CID 1583682

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
---
 drivers/usb/gadget/function/f_fs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

What commit id does this fix?

7b07a2a7ca02a, usb: gadget: functionfs: Add DMABUF import interface

Then why not use the Fixes: tag?

Quoted 3 lines
Quoted 1 line

How was this change tested?

I compiled the kernel and ran it on my machine.

Did you exercise this codepath?

Quoted 1 line

Are there other ways to reliably test such change?

Exercise the codepath by using the module and passing in a value to test your change.

thanks,

greg k-h