usb: gadget: fix check in sync read from ep in gadgetfs
authorBinyamin Sharet <s.binyamin@gmail.com>
Thu, 7 Jul 2016 19:22:04 +0000 (22:22 +0300)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 11 Aug 2016 12:09:46 +0000 (15:09 +0300)
When reading synchronously from a non-zero endpoint, gadgetfs will
return -EFAULT even if the read succeeds, due to a bad check of the
copy_to_iter() return value.

This fix compares the return value of copy_to_iter to the amount of
bytes that was passed, and only fails if they are not the same.

Signed-off-by: Binyamin Sharet <s.binyamin@gmail.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/gadget/legacy/inode.c

index aa3707b..8560f2f 100644 (file)
@@ -606,7 +606,7 @@ ep_read_iter(struct kiocb *iocb, struct iov_iter *to)
        }
        if (is_sync_kiocb(iocb)) {
                value = ep_io(epdata, buf, len);
-               if (value >= 0 && copy_to_iter(buf, value, to))
+               if (value >= 0 && (copy_to_iter(buf, value, to) != value))
                        value = -EFAULT;
        } else {
                struct kiocb_priv *priv = kzalloc(sizeof *priv, GFP_KERNEL);