mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
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. [ [email protected]: also fix comment's indentation ] Acked-by: Michal Nazarewicz <[email protected]> Reviewed-by: David Cohen <[email protected]> Signed-off-by: Chuansheng Liu <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
This commit is contained in:
parent
8bebbe8dc6
commit
cfe919b53b
1 changed files with 15 additions and 13 deletions
|
|
@ -838,19 +838,21 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
|
|||
ret = -EINTR;
|
||||
usb_ep_dequeue(ep->ep, req);
|
||||
} else {
|
||||
/*
|
||||
* XXX We may end up silently droping data here.
|
||||
* Since data_len (i.e. req->length) may be bigger
|
||||
* than len (after being rounded up to maxpacketsize),
|
||||
* 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;
|
||||
/*
|
||||
* XXX We may end up silently droping data
|
||||
* here. Since data_len (i.e. req->length) may
|
||||
* be bigger than len (after being rounded up
|
||||
* to maxpacketsize), we may end up with more
|
||||
* data then user space has space for.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue