Skip to content

Commit

Permalink
usb: gadgetfs: return USB_GADGET_DELAYED_STATUS from setup()
Browse files Browse the repository at this point in the history
Return USB_GADGET_DELAYED_STATUS from the setup() callback for 0-length
transfers as a workaround to stop some UDC drivers (e.g. dwc3) from
automatically proceeding with the status stage.

This workaround should be removed once all UDC drivers are fixed to
always delay the status stage until a response is queued to EP0.

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Andrey Konovalov <andreyknvl@gmail.com>
Link: https://lore.kernel.org/r/a8d2b91f9890dc21daa359183e84879ff4525180.1693237258.git.andreyknvl@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Andrey Konovalov authored and Greg Kroah-Hartman committed Oct 2, 2023
1 parent cf9f7a6 commit fc85c59
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/usb/gadget/legacy/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#include <linux/usb/gadgetfs.h>
#include <linux/usb/gadget.h>
#include <linux/usb/composite.h> /* for USB_GADGET_DELAYED_STATUS */

/* Undef helpers from linux/usb/composite.h as gadgetfs redefines them */
#undef DBG
#undef ERROR
#undef INFO


/*
Expand Down Expand Up @@ -1511,7 +1517,16 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
event->u.setup = *ctrl;
ep0_readable (dev);
spin_unlock (&dev->lock);
return 0;
/*
* Return USB_GADGET_DELAYED_STATUS as a workaround to
* stop some UDC drivers (e.g. dwc3) from automatically
* proceeding with the status stage for 0-length
* transfers.
* Should be removed once all UDC drivers are fixed to
* always delay the status stage until a response is
* queued to EP0.
*/
return w_length == 0 ? USB_GADGET_DELAYED_STATUS : 0;
}
}

Expand Down

0 comments on commit fc85c59

Please sign in to comment.