This is a note to let you know that I've just added the patch titled usb: dwc3: gadget: Allow runtime suspend if UDC unbinded to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: usb-dwc3-gadget-allow-runtime-suspend-if-udc-unbinded.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 77adb8bdf4227257e26b7ff67272678e66a0b250 Mon Sep 17 00:00:00 2001 From: Wesley Cheng <wcheng@xxxxxxxxxxxxxx> Date: Tue, 29 Dec 2020 15:05:35 -0800 Subject: usb: dwc3: gadget: Allow runtime suspend if UDC unbinded From: Wesley Cheng <wcheng@xxxxxxxxxxxxxx> commit 77adb8bdf4227257e26b7ff67272678e66a0b250 upstream. The DWC3 runtime suspend routine checks for the USB connected parameter to determine if the controller can enter into a low power state. The connected state is only set to false after receiving a disconnect event. However, in the case of a device initiated disconnect (i.e. UDC unbind), the controller is halted and a disconnect event is never generated. Set the connected flag to false if issuing a device initiated disconnect to allow the controller to be suspended. Signed-off-by: Wesley Cheng <wcheng@xxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/1609283136-22140-2-git-send-email-wcheng@xxxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/usb/dwc3/gadget.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2126,6 +2126,17 @@ static int dwc3_gadget_pullup(struct usb } /* + * Check the return value for successful resume, or error. For a + * successful resume, the DWC3 runtime PM resume routine will handle + * the run stop sequence, so avoid duplicate operations here. + */ + ret = pm_runtime_get_sync(dwc->dev); + if (!ret || ret < 0) { + pm_runtime_put(dwc->dev); + return 0; + } + + /* * Synchronize any pending event handling before executing the controller * halt routine. */ @@ -2163,12 +2174,14 @@ static int dwc3_gadget_pullup(struct usb dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) % dwc->ev_buf->length; } + dwc->connected = false; } else { __dwc3_gadget_start(dwc); } ret = dwc3_gadget_run_stop(dwc, is_on, false); spin_unlock_irqrestore(&dwc->lock, flags); + pm_runtime_put(dwc->dev); return ret; } Patches currently in stable-queue which might be from wcheng@xxxxxxxxxxxxxx are queue-5.10/usb-dwc3-gadget-prevent-ep-queuing-while-stopping-transfers.patch queue-5.10/usb-dwc3-gadget-allow-runtime-suspend-if-udc-unbinded.patch