From: Jing Lin gadgetfs_setup() receives the setup packet as const, but clamps an oversized control IN request by casting away the constness and writing the truncated length back into the caller's wLength field. The setup() callback has no business modifying the setup packet, and ctrl->wLength is only used afterwards when initializing event->u.setup. Store the clamped w_length into event->u.setup.wLength directly instead. Suggested-by: Alan Stern Signed-off-by: Jing Lin --- drivers/usb/gadget/legacy/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index 0b3210f87..5970f0c85 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -1600,10 +1600,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) if (w_length > RBUF_SIZE) { if (ctrl->bRequestType & USB_DIR_IN) { - /* Cast away the const, we are going to overwrite on purpose. */ - __le16 *temp = (__le16 *)&ctrl->wLength; - - *temp = cpu_to_le16(RBUF_SIZE); w_length = RBUF_SIZE; } else { spin_unlock(&dev->lock); @@ -1761,6 +1757,8 @@ delegate: /* state changes when reader collects event */ event = next_event (dev, GADGETFS_SETUP); event->u.setup = *ctrl; + /* Report the length we can actually handle */ + event->u.setup.wLength = cpu_to_le16(w_length); ep0_readable (dev); spin_unlock (&dev->lock); /* -- Git-155)