Skip to content

Commit 630a1de

Browse files
Kuen-Han Tsaigregkh
authored andcommitted
usb: dwc3: Abort suspend on soft disconnect failure
When dwc3_gadget_soft_disconnect() fails, dwc3_suspend_common() keeps going with the suspend, resulting in a period where the power domain is off, but the gadget driver remains connected. Within this time frame, invoking vbus_event_work() will cause an error as it attempts to access DWC3 registers for endpoint disabling after the power domain has been completely shut down. Abort the suspend sequence when dwc3_gadget_suspend() cannot halt the controller and proceeds with a soft connect. Fixes: 9f8a67b ("usb: dwc3: gadget: fix gadget suspend/resume") Cc: stable <stable@kernel.org> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Signed-off-by: Kuen-Han Tsai <khtsai@google.com> Link: https://lore.kernel.org/r/20250528100315.2162699-1-khtsai@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e2c421 commit 630a1de

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

drivers/usb/dwc3/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
24222422
{
24232423
u32 reg;
24242424
int i;
2425+
int ret;
24252426

24262427
if (!pm_runtime_suspended(dwc->dev) && !PMSG_IS_AUTO(msg)) {
24272428
dwc->susphy_state = (dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)) &
@@ -2440,7 +2441,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
24402441
case DWC3_GCTL_PRTCAP_DEVICE:
24412442
if (pm_runtime_suspended(dwc->dev))
24422443
break;
2443-
dwc3_gadget_suspend(dwc);
2444+
ret = dwc3_gadget_suspend(dwc);
2445+
if (ret)
2446+
return ret;
24442447
synchronize_irq(dwc->irq_gadget);
24452448
dwc3_core_exit(dwc);
24462449
break;
@@ -2475,7 +2478,9 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
24752478
break;
24762479

24772480
if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
2478-
dwc3_gadget_suspend(dwc);
2481+
ret = dwc3_gadget_suspend(dwc);
2482+
if (ret)
2483+
return ret;
24792484
synchronize_irq(dwc->irq_gadget);
24802485
}
24812486

drivers/usb/dwc3/gadget.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,26 +4821,22 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)
48214821
int ret;
48224822

48234823
ret = dwc3_gadget_soft_disconnect(dwc);
4824-
if (ret)
4825-
goto err;
4826-
4827-
spin_lock_irqsave(&dwc->lock, flags);
4828-
if (dwc->gadget_driver)
4829-
dwc3_disconnect_gadget(dwc);
4830-
spin_unlock_irqrestore(&dwc->lock, flags);
4831-
4832-
return 0;
4833-
4834-
err:
48354824
/*
48364825
* Attempt to reset the controller's state. Likely no
48374826
* communication can be established until the host
48384827
* performs a port reset.
48394828
*/
4840-
if (dwc->softconnect)
4829+
if (ret && dwc->softconnect) {
48414830
dwc3_gadget_soft_connect(dwc);
4831+
return -EAGAIN;
4832+
}
48424833

4843-
return ret;
4834+
spin_lock_irqsave(&dwc->lock, flags);
4835+
if (dwc->gadget_driver)
4836+
dwc3_disconnect_gadget(dwc);
4837+
spin_unlock_irqrestore(&dwc->lock, flags);
4838+
4839+
return 0;
48444840
}
48454841

48464842
int dwc3_gadget_resume(struct dwc3 *dwc)

0 commit comments

Comments
 (0)