From 31e42acec854b0b175ed59940da08479557b1647 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Mon, 23 Dec 2024 04:25:36 +0000 Subject: [PATCH] FROMGIT: usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UDC state in sysfs (/sys/class/udc//state) should accurately reflect the current state of the USB Device Controller. Currently, the UDC state is not handled consistently during gadget disconnection. While the disconnect interrupt path correctly sets the state to "not-attached", manual deconfiguration leaves the state in "configured", misrepresenting the actual situation. This commit ensures consistent UDC state handling by setting the state to "not-attached" after manual deconfiguration. This accurately reflects the UDC's state and provides a consistent behavior regardless of the disconnection method. Signed-off-by: Roy Luo Reviewed-by: André Draszik Tested-by: André Draszik Link: https://lore.kernel.org/r/20241223042536.1465299-1-royluo@google.com Signed-off-by: Greg Kroah-Hartman Bug: 339241080 (cherry picked from commit 1ff24d40b3c3c673d833c546f898133b80dffc39 git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-next) Signed-off-by: Roy Luo (cherry picked from https://android-review.googlesource.com/q/commit:3f924195e2221970e40c33cdca57933f4b63bf31) Merged-In: I6840073addbcbd2acd0145363e4e5aac2f7422ee Change-Id: I6840073addbcbd2acd0145363e4e5aac2f7422ee --- drivers/usb/dwc3/gadget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 56744b11e67c..b5a7e31c73c0 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2728,6 +2728,8 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) __dwc3_gadget_stop(dwc); spin_unlock_irqrestore(&dwc->lock, flags); + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); + return ret; }