mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: return the right length in ffs_epfile_io()
@ 2014-02-27  6:49 Chuansheng Liu
  2014-02-27 12:15 ` Michal Nazarewicz
  2014-03-03 16:30 ` Felipe Balbi
  0 siblings, 2 replies; 5+ messages in thread
From: Chuansheng Liu @ 2014-02-27  6:49 UTC (permalink / raw)
  To: balbi, gregkh, mina86
  Cc: linux-usb, linux-kernel, david.a.cohen, jin.can.zhuang,
	yu.y.wang, Chuansheng Liu

When the request length is aligned to maxpacketsize, sometimes
the return length ret > the user space requested len.

At that time, we will use min_t(size_t, ret, len) to limit the
size in case of user data buffer overflow.

But we need return the min_t(size_t, ret, len) to tell the user
space rightly also.

Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
---
 drivers/usb/gadget/f_fs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 2b43343..31ee7af 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -687,10 +687,12 @@ static ssize_t ffs_epfile_io(struct file *file,
 			 * space for.
 			 */
 			ret = ep->status;
-			if (read && ret > 0 &&
-			    unlikely(copy_to_user(buf, data,
-						  min_t(size_t, ret, len))))
-				ret = -EFAULT;
+			if (read && ret > 0) {
+				ret = min_t(size_t, ret, len);
+
+				if (unlikely(copy_to_user(buf, data, ret)))
+					ret = -EFAULT;
+			}
 		}
 	}
 
-- 
1.9.rc0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-04  7:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-27  6:49 [PATCH] usb: gadget: return the right length in ffs_epfile_io() Chuansheng Liu
2014-02-27 12:15 ` Michal Nazarewicz
2014-02-27 23:45   ` David Cohen
2014-03-03 16:30 ` Felipe Balbi
2014-03-04  7:47   ` Liu, Chuansheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome