usb: gadget: f_fs: Fix EFAULT generation for async read operations
authorLars-Peter Clausen <lars@metafoo.de>
Wed, 30 Mar 2016 11:49:14 +0000 (13:49 +0200)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 19 Apr 2016 08:11:56 +0000 (11:11 +0300)
commit332a5b446b7916d272c2a659a3b20909ce34d2c1
tree34e973d0bd8833e6916d8f825e36f4801d25e9bd
parent9bc07890f891267285716c09bfee58e239137d36
usb: gadget: f_fs: Fix EFAULT generation for async read operations

In the current implementation functionfs generates a EFAULT for async read
operations if the read buffer size is larger than the URB data size. Since
a application does not necessarily know how much data the host side is
going to send it typically supplies a buffer larger than the actual data,
which will then result in a EFAULT error.

This behaviour was introduced while refactoring the code to use iov_iter
interface in commit c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter
into io_data"). The original code took the minimum over the URB size and
the user buffer size and then attempted to copy that many bytes using
copy_to_user(). If copy_to_user() could not copy all data a EFAULT error
was generated. Restore the original behaviour by only generating a EFAULT
error when the number of bytes copied is not the size of the URB and the
target buffer has not been fully filled.

Commit 342f39a6c8d3 ("usb: gadget: f_fs: fix check in read operation")
already fixed the same problem for the synchronous read path.

Fixes: c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter into io_data")
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/gadget/function/f_fs.c