Skip to contentSkip to conversation

usb: gadgetfs: return number of bytes on ep0 read request

PATCH In review Thomas Faber 2 participants 2 messages Mar 2, 2012 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadgetfs: return number of bytes on ep0 read request

A read from GadgetFS endpoint 0 during the data stage of a control request would always return 0 on success (as returned by wait_event_interruptible) despite having written data into the user buffer.
This patch makes it correctly set the return value to the number of bytes read.

---
 drivers/usb/gadget/inode.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/usb/gadget/inode.c +2 -0
index ae04266..4f18a0e 100644
@@ -1043,6 +1043,8 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 // FIXME don't call this with the spinlock held ...
 				if (copy_to_user (buf, dev->req->buf, len))
 					retval = -EFAULT;
+				else
+					retval = len;
 				clean_req (dev->gadget->ep0, dev->req);
 				/* NOTE userspace can't yet choose to stall */
 			}
Signature · 1 line
1.7.3.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Thomas Faber

A read from GadgetFS endpoint 0 during the data stage of a control request would always return 0 on success (as returned by wait_event_interruptible) despite having written data into the user buffer.
This patch makes it correctly set the return value to the number of bytes read.

Quoted 17 lines
---
 drivers/usb/gadget/inode.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/usb/gadget/inode.c +2 -0
index ae04266..4f18a0e 100644
@@ -1043,6 +1043,8 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
 // FIXME don't call this with the spinlock held ...
 				if (copy_to_user (buf, dev->req->buf, len))
 					retval = -EFAULT;
+				else
+					retval = len;
 				clean_req (dev->gadget->ep0, dev->req);
 				/* NOTE userspace can't yet choose to stall */
 			}
Signature · 4 lines
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--