Skip to content

Commit af2d67c

Browse files
drewbh5yehowshuaimmanuelTST
authored andcommitted
usb: musb: fix gadget state on disconnect
commit 67a59f82196c8c4f50c83329f0577acfb1349b50 upstream. When unplugging the USB cable or disconnecting a gadget in usb peripheral mode with echo "" > /sys/kernel/config/usb_gadget/<your_gadget>/UDC, /sys/class/udc/musb-hdrc.0/state does not change from USB_STATE_CONFIGURED. Testing on dwc2/3 shows they both update the state to USB_STATE_NOTATTACHED. Add calls to usb_gadget_set_state in musb_g_disconnect and musb_gadget_stop to fix both cases. Fixes: 49401f4 ("usb: gadget: introduce gadget state tracking") Cc: [email protected] Co-authored-by: Yehowshua Immanuel <[email protected]> Signed-off-by: Yehowshua Immanuel <[email protected]> Signed-off-by: Drew Hamilton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a2c2458 commit af2d67c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/usb/musb/musb_gadget.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
19161916
* gadget driver here and have everything work;
19171917
* that currently misbehaves.
19181918
*/
1919+
usb_gadget_set_state(g, USB_STATE_NOTATTACHED);
19191920

19201921
/* Force check of devctl register for PM runtime */
19211922
pm_runtime_mark_last_busy(musb->controller);
@@ -2022,6 +2023,7 @@ void musb_g_disconnect(struct musb *musb)
20222023
case OTG_STATE_B_PERIPHERAL:
20232024
case OTG_STATE_B_IDLE:
20242025
musb_set_state(musb, OTG_STATE_B_IDLE);
2026+
usb_gadget_set_state(&musb->g, USB_STATE_NOTATTACHED);
20252027
break;
20262028
case OTG_STATE_B_SRP_INIT:
20272029
break;

0 commit comments

Comments
 (0)