All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: return the right length in ffs_epfile_io()
@ 2014-03-04  7:34 Chuansheng Liu
  2014-03-04 17:01 ` Sergei Shtylyov
  0 siblings, 1 reply; 7+ messages in thread
From: Chuansheng Liu @ 2014-03-04  7:34 UTC (permalink / raw)
  To: balbi, gregkh
  Cc: linux-usb, linux-kernel, mina86, david.a.cohen, 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.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
---
 drivers/usb/gadget/f_fs.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 42f7a0e..780f877 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -845,12 +845,14 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
 			 * we may end up with more data then user space has
 			 * space for.
 			 */
-			ret = ep->status;
-			if (io_data->read && ret > 0 &&
-			    unlikely(copy_to_user(io_data->buf, data,
-						  min_t(size_t, ret,
-						  io_data->len))))
-				ret = -EFAULT;
+				ret = ep->status;
+				if (io_data->read && ret > 0) {
+					ret = min_t(size_t, ret, io_data->len);
+
+					if (unlikely(copy_to_user(io_data->buf,
+						data, ret)))
+						ret = -EFAULT;
+				}
 			}
 			kfree(data);
 		}
-- 
1.9.rc0


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

end of thread, other threads:[~2014-03-05 15:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-04  7:34 [PATCH v2] usb: gadget: return the right length in ffs_epfile_io() Chuansheng Liu
2014-03-04 17:01 ` Sergei Shtylyov
2014-03-04 16:06   ` Felipe Balbi
2014-03-04 19:53     ` Michal Nazarewicz
2014-03-04 19:55       ` Felipe Balbi
2014-03-04 23:38         ` Liu, Chuansheng
2014-03-05 15:22           ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.