Skip to content

Commit cb10f68

Browse files
Wesley Chenggregkh
authored andcommitted
usb: dwc3: gadget: Avoid runtime resume if disabling pullup
If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped. This fixes an issue where the following condition occurs: usb_gadget_remove_driver() -->usb_gadget_disconnect() -->dwc3_gadget_pullup(0) -->pm_runtime_get_sync() -> ret = 0 -->pm_runtime_put() [async] -->usb_gadget_udc_stop() -->dwc3_gadget_stop() -->dwc->gadget_driver = NULL ... dwc3_suspend_common() -->dwc3_gadget_suspend() -->DWC3 halt/stop routine skipped, driver_data == NULL This leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled. Fixes: 77adb8b ("usb: dwc3: gadget: Allow runtime suspend if UDC unbinded") Cc: stable <[email protected]> Acked-by: Felipe Balbi <[email protected]> Signed-off-by: Wesley Cheng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d25d850 commit cb10f68

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
22562256
}
22572257
}
22582258

2259+
/*
2260+
* Avoid issuing a runtime resume if the device is already in the
2261+
* suspended state during gadget disconnect. DWC3 gadget was already
2262+
* halted/stopped during runtime suspend.
2263+
*/
2264+
if (!is_on) {
2265+
pm_runtime_barrier(dwc->dev);
2266+
if (pm_runtime_suspended(dwc->dev))
2267+
return 0;
2268+
}
2269+
22592270
/*
22602271
* Check the return value for successful resume, or error. For a
22612272
* successful resume, the DWC3 runtime PM resume routine will handle

0 commit comments

Comments
 (0)