Skip to content

Commit

Permalink
usb: raw-gadget: fix return value of ep read ioctls
Browse files Browse the repository at this point in the history
They must return the number of bytes transferred during the data stage.

Fixes: 068fbff ("usb: raw-gadget: Fix copy_to/from_user() checks")
Fixes: f2c2e71 ("usb: gadget: add raw-gadget interface")
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
  • Loading branch information
Andrey Konovalov authored and Felipe Balbi committed May 9, 2020
1 parent 4748d39 commit 6e50764
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/usb/gadget/legacy/raw_gadget.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,14 @@ static int raw_ioctl_ep0_read(struct raw_dev *dev, unsigned long value)
if (IS_ERR(data))
return PTR_ERR(data);
ret = raw_process_ep0_io(dev, &io, data, false);
if (ret)
if (ret < 0)
goto free;

length = min(io.length, (unsigned int)ret);
if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
ret = -EFAULT;
else
ret = length;
free:
kfree(data);
return ret;
Expand Down Expand Up @@ -964,12 +966,14 @@ static int raw_ioctl_ep_read(struct raw_dev *dev, unsigned long value)
if (IS_ERR(data))
return PTR_ERR(data);
ret = raw_process_ep_io(dev, &io, data, false);
if (ret)
if (ret < 0)
goto free;

length = min(io.length, (unsigned int)ret);
if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
ret = -EFAULT;
else
ret = length;
free:
kfree(data);
return ret;
Expand Down

0 comments on commit 6e50764

Please sign in to comment.