Skip to contentSkip to conversation

usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration

PATCH In review Roy Luo 2 participants 2 messages Dec 23, 2024

Subsystems (2)
lore
Share & tools
lore

Roy Luo

author
#0 lore raw

PATCH 1/1 usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration

The UDC state in sysfs (/sys/class/udc/<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.

---
 drivers/usb/dwc3/gadget.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/dwc3/gadget.c +2 -0
index 83dc7304d701..fb4f6487c4ce 100644
@@ -2740,6 +2740,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;
 }
 

base-commit: 4bbf9020becbfd8fc2c3da790855b7042fad455b

Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Roy Luo

The UDC state in sysfs (/sys/class/udc/<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.

Quoted 7 lines

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.

---