[PATCH 4.14 06/23] usb: dwc3: gadget: Stop EP0 transfers during pullup disable

From: Greg Kroah-Hartman
Date: Wed Sep 01 2021 - 08:29:49 EST

From: Wesley Cheng <wcheng@xxxxxxxxxxxxxx>

commit 4a1e25c0a029b97ea4a3d423a6392bfacc3b2e39 upstream.

During a USB cable disconnect, or soft disconnect scenario, a pending
SETUP transaction may not be completed, leading to the following

dwc3 a600000.dwc3: timed out waiting for SETUP phase

If this occurs, then the entire pullup disable routine is skipped and
proper cleanup and halting of the controller does not complete.

Instead of returning an error (which is ignored from the UDC
perspective), allow the pullup disable routine to continue, which
will also handle disabling of EP0/1. This will end any active
transfers as well. Ensure to clear any delayed_status also, as the
timeout could happen within the STATUS stage.

Fixes: bb0147364850 ("usb: dwc3: gadget: don't clear RUN/STOP when it's invalid to do so")
Cc: <stable@xxxxxxxxxxxxxxx>
Reviewed-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx>
Acked-by: Felipe Balbi <balbi@xxxxxxxxxx>
Signed-off-by: Wesley Cheng <wcheng@xxxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/20210825042855.7977-1-wcheng@xxxxxxxxxxxxxx
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
drivers/usb/dwc3/gadget.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1799,10 +1799,8 @@ static int dwc3_gadget_pullup(struct usb

ret = wait_for_completion_timeout(&dwc->ep0_in_setup,
- if (ret == 0) {
- dev_err(dwc->dev, "timed out waiting for SETUP phase\n");
- return -ETIMEDOUT;
- }
+ if (ret == 0)
+ dev_warn(dwc->dev, "timed out waiting for SETUP phase\n");

spin_lock_irqsave(&dwc->lock, flags);
@@ -1936,6 +1934,7 @@ static int __dwc3_gadget_start(struct dw
/* begin to receive SETUP packets */
dwc->ep0state = EP0_SETUP_PHASE;
dwc->link_state = DWC3_LINK_STATE_SS_DIS;
+ dwc->delayed_status = false;