* [PATCH] usb: musb: fix gadget state on disconnect
@ 2025-06-24 14:09 Drew Hamilton
2025-06-24 14:16 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Drew Hamilton @ 2025-06-24 14:09 UTC (permalink / raw)
To: Bin Liu, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, Drew Hamilton, Yehowshua Immanuel
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.
Tested against 82f2b0b97b36ee3fcddf0f0780a9a0825d52fec3.
Co-authored-by: Yehowshua Immanuel <yehowshua.immanuel@twosixtech.com>
Signed-off-by: Yehowshua Immanuel <yehowshua.immanuel@twosixtech.com>
Signed-off-by: Drew Hamilton <drew.hamilton@zetier.com>
---
drivers/usb/musb/musb_gadget.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 6869c58367f2..caf4d4cd4b75 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1913,6 +1913,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
* gadget driver here and have everything work;
* that currently misbehaves.
*/
+ usb_gadget_set_state(g, USB_STATE_NOTATTACHED);
/* Force check of devctl register for PM runtime */
pm_runtime_mark_last_busy(musb->controller);
@@ -2019,6 +2020,7 @@ void musb_g_disconnect(struct musb *musb)
case OTG_STATE_B_PERIPHERAL:
case OTG_STATE_B_IDLE:
musb_set_state(musb, OTG_STATE_B_IDLE);
+ usb_gadget_set_state(&musb->g, USB_STATE_NOTATTACHED);
break;
case OTG_STATE_B_SRP_INIT:
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: musb: fix gadget state on disconnect
2025-06-24 14:09 [PATCH] usb: musb: fix gadget state on disconnect Drew Hamilton
@ 2025-06-24 14:16 ` Greg Kroah-Hartman
2025-06-26 17:35 ` Drew Hamilton
0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-06-24 14:16 UTC (permalink / raw)
To: Drew Hamilton; +Cc: Bin Liu, linux-usb, linux-kernel, Yehowshua Immanuel
On Tue, Jun 24, 2025 at 10:09:30AM -0400, Drew Hamilton wrote:
> 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.
>
> Tested against 82f2b0b97b36ee3fcddf0f0780a9a0825d52fec3.
Nit, git ids are written as:
82f2b0b97b36 ("Linux 6.15-rc6")
Or you could have used the tag "6.15-rc6" as we all know that, but
really, this shouldn't be needed at all.
What it does show is you missed the many thousands of changes that have
gone into the tree since -rc6, is this still an issue in 6.16-rc3?
> Co-authored-by: Yehowshua Immanuel <yehowshua.immanuel@twosixtech.com>
> Signed-off-by: Yehowshua Immanuel <yehowshua.immanuel@twosixtech.com>
> Signed-off-by: Drew Hamilton <drew.hamilton@zetier.com>
What commit id does this fix?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: musb: fix gadget state on disconnect
2025-06-24 14:16 ` Greg Kroah-Hartman
@ 2025-06-26 17:35 ` Drew Hamilton
2025-06-30 13:39 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Drew Hamilton @ 2025-06-26 17:35 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Bin Liu, linux-usb, linux-kernel, Yehowshua Immanuel
On Tue, Jun 24, 2025 at 10:16:30AM -0400, Greg Kroah-Hartman wrote:
> What it does show is you missed the many thousands of changes that have
> gone into the tree since -rc6, is this still an issue in 6.16-rc3?
Retested against v6.16-rc3 and confirmed both that without the patch the
issue is still present, as well as that the patch still resolves the issue.
> What commit id does this fix?
It seems like this issue has existed for the MUSB driver since the UDC
'state' sysfs attribute was defined in v3.1.
Thanks,
Drew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: musb: fix gadget state on disconnect
2025-06-26 17:35 ` Drew Hamilton
@ 2025-06-30 13:39 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-06-30 13:39 UTC (permalink / raw)
To: Drew Hamilton; +Cc: Bin Liu, linux-usb, linux-kernel, Yehowshua Immanuel
On Thu, Jun 26, 2025 at 01:35:39PM -0400, Drew Hamilton wrote:
> On Tue, Jun 24, 2025 at 10:16:30AM -0400, Greg Kroah-Hartman wrote:
> > What it does show is you missed the many thousands of changes that have
> > gone into the tree since -rc6, is this still an issue in 6.16-rc3?
>
> Retested against v6.16-rc3 and confirmed both that without the patch the
> issue is still present, as well as that the patch still resolves the issue.
>
> > What commit id does this fix?
>
> It seems like this issue has existed for the MUSB driver since the UDC
> 'state' sysfs attribute was defined in v3.1.
Great, can you please fix up the changelog and add the needed Fixes: and
cc: stable line to the patch and send a v2?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-30 13:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 14:09 [PATCH] usb: musb: fix gadget state on disconnect Drew Hamilton
2025-06-24 14:16 ` Greg Kroah-Hartman
2025-06-26 17:35 ` Drew Hamilton
2025-06-30 13:39 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).