This is a note to let you know that I've just added the patch titled usb: dwc3: gadget: Execute gadget stop after halting the controller to the 5.15-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-execute-gadget-stop-after-halting-the-controller.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 39674be56fba1cd3a03bf4617f523a35f85fd2c1 Mon Sep 17 00:00:00 2001 From: Wesley Cheng <quic_wcheng@xxxxxxxxxxx> Date: Thu, 20 Apr 2023 14:27:58 -0700 Subject: usb: dwc3: gadget: Execute gadget stop after halting the controller From: Wesley Cheng <quic_wcheng@xxxxxxxxxxx> commit 39674be56fba1cd3a03bf4617f523a35f85fd2c1 upstream. Do not call gadget stop until the poll for controller halt is completed. DEVTEN is cleared as part of gadget stop, so the intention to allow ep0 events to continue while waiting for controller halt is not happening. Fixes: c96683798e27 ("usb: dwc3: ep0: Don't prepare beyond Setup stage") Cc: stable@xxxxxxxxxxxxxxx Acked-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx> Signed-off-by: Wesley Cheng <quic_wcheng@xxxxxxxxxxx> Link: https://lore.kernel.org/r/20230420212759.29429-2-quic_wcheng@xxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/usb/dwc3/gadget.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2517,7 +2517,6 @@ static int dwc3_gadget_soft_disconnect(s * bit. */ dwc3_stop_active_transfers(dwc); - __dwc3_gadget_stop(dwc); spin_unlock_irqrestore(&dwc->lock, flags); /* @@ -2547,7 +2546,19 @@ static int dwc3_gadget_soft_disconnect(s * remaining event generated by the controller while polling for * DSTS.DEVCTLHLT. */ - return dwc3_gadget_run_stop(dwc, false); + ret = dwc3_gadget_run_stop(dwc, false); + + /* + * Stop the gadget after controller is halted, so that if needed, the + * events to update EP0 state can still occur while the run/stop + * routine polls for the halted state. DEVTEN is cleared as part of + * gadget stop. + */ + spin_lock_irqsave(&dwc->lock, flags); + __dwc3_gadget_stop(dwc); + spin_unlock_irqrestore(&dwc->lock, flags); + + return ret; } static int dwc3_gadget_soft_connect(struct dwc3 *dwc) Patches currently in stable-queue which might be from quic_wcheng@xxxxxxxxxxx are queue-5.15/usb-dwc3-gadget-refactor-ep0-forced-stall-restart-in.patch queue-5.15/usb-dwc3-gadget-submit-endxfer-command-if-delayed-du.patch queue-5.15/usb-dwc3-gadget-execute-gadget-stop-after-halting-the-controller.patch queue-5.15/usb-dwc3-gadget-handle-ep0-request-dequeuing-properl.patch queue-5.15/usb-dwc3-gadget-queue-pm-runtime-idle-on-disconnect-.patch queue-5.15/usb-dwc3-gadget-stall-and-restart-ep0-if-host-is-unr.patch queue-5.15/usb-dwc3-gadget-force-sending-delayed-status-during-.patch queue-5.15/usb-dwc3-gadget-wait-for-ep0-xfers-to-complete-durin.patch