[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1393918497-30916-1-git-send-email-chuansheng.liu@intel.com>
Date: Tue, 4 Mar 2014 15:34:57 +0800
From: Chuansheng Liu <chuansheng.liu@...el.com>
To: balbi@...com, gregkh@...uxfoundation.org
Cc: linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
mina86@...a86.com, david.a.cohen@...ux.intel.com,
Chuansheng Liu <chuansheng.liu@...el.com>
Subject: [PATCH v2] usb: gadget: return the right length in ffs_epfile_io()
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@...a86.com>
Reviewed-by: David Cohen <david.a.cohen@...ux.intel.com>
Signed-off-by: Chuansheng Liu <chuansheng.liu@...el.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists