Commit cfe919b5 authored by Chuansheng Liu's avatar Chuansheng Liu Committed by Felipe Balbi

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.

[ balbi@ti.com: also fix comment's indentation ]
Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Reviewed-by: default avatarDavid Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: default avatarChuansheng Liu <chuansheng.liu@intel.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 8bebbe8d
...@@ -838,19 +838,21 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -838,19 +838,21 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
ret = -EINTR; ret = -EINTR;
usb_ep_dequeue(ep->ep, req); usb_ep_dequeue(ep->ep, req);
} else { } else {
/* /*
* XXX We may end up silently droping data here. * XXX We may end up silently droping data
* Since data_len (i.e. req->length) may be bigger * here. Since data_len (i.e. req->length) may
* than len (after being rounded up to maxpacketsize), * be bigger than len (after being rounded up
* we may end up with more data then user space has * to maxpacketsize), we may end up with more
* space for. * data then user space has space for.
*/ */
ret = ep->status; ret = ep->status;
if (io_data->read && ret > 0 && if (io_data->read && ret > 0) {
unlikely(copy_to_user(io_data->buf, data, ret = min_t(size_t, ret, io_data->len);
min_t(size_t, ret,
io_data->len)))) if (unlikely(copy_to_user(io_data->buf,
ret = -EFAULT; data, ret)))
ret = -EFAULT;
}
} }
kfree(data); kfree(data);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment