* [PATCH v1] usb: gadget: core: flush gadget workqueue after device removal
@ 2025-02-04 0:01 Roy Luo
2025-02-04 0:54 ` Thinh Nguyen
0 siblings, 1 reply; 3+ messages in thread
From: Roy Luo @ 2025-02-04 0:01 UTC (permalink / raw)
To: royluo, Thinh.Nguyen, gregkh, linux-usb, linux-kernel,
andre.draszik, elder, stern, crwulff, paul, jkeeping, yuanlinyu
usb_del_gadget() can lead to new work being scheduled in gadget->work
workqueue. This is observed, for example, with the dwc3 driver with the
following call stack:
device_del()
gadget_unbind_driver()
usb_gadget_disconnect_locked()
dwc3_gadget_pullup()
dwc3_gadget_soft_disconnect()
usb_gadget_set_state()
schedule_work(&gadget->work)
Move flush_work() after device_del() to ensure the workqueue is cleaned
up.
Fixes: 1ff24d40b3c3 ("usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration")
Signed-off-by: Roy Luo <royluo@google.com>
---
drivers/usb/gadget/udc/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index a6f46364be65..4b3d5075621a 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1543,8 +1543,8 @@ void usb_del_gadget(struct usb_gadget *gadget)
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
sysfs_remove_link(&udc->dev.kobj, "gadget");
- flush_work(&gadget->work);
device_del(&gadget->dev);
+ flush_work(&gadget->work);
ida_free(&gadget_id_numbers, gadget->id_number);
cancel_work_sync(&udc->vbus_work);
device_unregister(&udc->dev);
base-commit: f286757b644c226b6b31779da95a4fa7ab245ef5
--
2.48.1.362.g079036d154-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1] usb: gadget: core: flush gadget workqueue after device removal
2025-02-04 0:01 [PATCH v1] usb: gadget: core: flush gadget workqueue after device removal Roy Luo
@ 2025-02-04 0:54 ` Thinh Nguyen
2025-02-04 23:36 ` Roy Luo
0 siblings, 1 reply; 3+ messages in thread
From: Thinh Nguyen @ 2025-02-04 0:54 UTC (permalink / raw)
To: Roy Luo
Cc: Thinh Nguyen, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
andre.draszik@linaro.org, elder@kernel.org,
stern@rowland.harvard.edu, crwulff@gmail.com,
paul@crapouillou.net, jkeeping@inmusicbrands.com,
yuanlinyu@hihonor.com
On Tue, Feb 04, 2025, Roy Luo wrote:
> usb_del_gadget() can lead to new work being scheduled in gadget->work
> workqueue. This is observed, for example, with the dwc3 driver with the
> following call stack:
> device_del()
> gadget_unbind_driver()
> usb_gadget_disconnect_locked()
> dwc3_gadget_pullup()
> dwc3_gadget_soft_disconnect()
> usb_gadget_set_state()
> schedule_work(&gadget->work)
>
> Move flush_work() after device_del() to ensure the workqueue is cleaned
> up.
>
> Fixes: 1ff24d40b3c3 ("usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration")
The reference should be targeting the udc core. Probably want to Cc
stable also.
BR,
Thinh
> Signed-off-by: Roy Luo <royluo@google.com>
> ---
> drivers/usb/gadget/udc/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> index a6f46364be65..4b3d5075621a 100644
> --- a/drivers/usb/gadget/udc/core.c
> +++ b/drivers/usb/gadget/udc/core.c
> @@ -1543,8 +1543,8 @@ void usb_del_gadget(struct usb_gadget *gadget)
>
> kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
> sysfs_remove_link(&udc->dev.kobj, "gadget");
> - flush_work(&gadget->work);
> device_del(&gadget->dev);
> + flush_work(&gadget->work);
> ida_free(&gadget_id_numbers, gadget->id_number);
> cancel_work_sync(&udc->vbus_work);
> device_unregister(&udc->dev);
>
> base-commit: f286757b644c226b6b31779da95a4fa7ab245ef5
> --
> 2.48.1.362.g079036d154-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v1] usb: gadget: core: flush gadget workqueue after device removal
2025-02-04 0:54 ` Thinh Nguyen
@ 2025-02-04 23:36 ` Roy Luo
0 siblings, 0 replies; 3+ messages in thread
From: Roy Luo @ 2025-02-04 23:36 UTC (permalink / raw)
To: Thinh Nguyen
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, andre.draszik@linaro.org,
elder@kernel.org, stern@rowland.harvard.edu, crwulff@gmail.com,
paul@crapouillou.net, jkeeping@inmusicbrands.com,
yuanlinyu@hihonor.com
On Mon, Feb 3, 2025 at 4:55 PM Thinh Nguyen <Thinh.Nguyen@synopsys.com> wrote:
>
> On Tue, Feb 04, 2025, Roy Luo wrote:
> > usb_del_gadget() can lead to new work being scheduled in gadget->work
> > workqueue. This is observed, for example, with the dwc3 driver with the
> > following call stack:
> > device_del()
> > gadget_unbind_driver()
> > usb_gadget_disconnect_locked()
> > dwc3_gadget_pullup()
> > dwc3_gadget_soft_disconnect()
> > usb_gadget_set_state()
> > schedule_work(&gadget->work)
> >
> > Move flush_work() after device_del() to ensure the workqueue is cleaned
> > up.
> >
> > Fixes: 1ff24d40b3c3 ("usb: dwc3: gadget: Fix incorrect UDC state after manual deconfiguration")
>
> The reference should be targeting the udc core. Probably want to Cc
> stable also.
>
Thanks for the review, sending out v2.
Regards,
Roy Luo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-04 23:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 0:01 [PATCH v1] usb: gadget: core: flush gadget workqueue after device removal Roy Luo
2025-02-04 0:54 ` Thinh Nguyen
2025-02-04 23:36 ` Roy Luo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox