From: sashiko-bot@kernel.org
To: "Konrad Dybcio" <konrad.dybcio@oss.qualcomm.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: gadget: destroy connect_mutex after usb_del_gadget
Date: Mon, 23 Nov 2026 20:30:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-229992@kernel.org> (raw)
In-Reply-To: <20261123-topic-dwc3_gadget_fix-v1-1-dec7679b81b7@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: dwc3: gadget: missing Fixes trailer for commit 1ff77cbefe5a
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] usb: dwc3: gadget: premature connect_mutex and work
teardown in dwc3_gadget_exit() [1]
--
commit 12a4a58348a4c5787efa091b578e45677e1
Author: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> usb: dwc3: gadget: destroy connect_mutex after usb_del_gadget
>
> usb_del_gadget() unbinds the function driver, which may still call
> dwc3_gadget_pullup() and take connect_mutex. Destroying the mutex
> before that point leaves a live lock behind during teardown.
>
> Avoid it.
>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
[Severity: Low]
Should this include a Fixes tag for the commit that introduced
connect_mutex and placed mutex_destroy() before usb_del_gadget()?
Fixes: 1ff77cbefe5a ("usb: dwc3: gadget: fix IRQ storm on invalid event buffer count")
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index a76f669a796c2..673f4bffb8ca8 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -5027,9 +5027,9 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
> return;
>
> cancel_work_sync(&dwc->err_recovery_work);
> - mutex_destroy(&dwc->connect_mutex);
> dwc3_enable_susphy(dwc, true);
> usb_del_gadget(dwc->gadget);
> + mutex_destroy(&dwc->connect_mutex);
> dwc3_gadget_free_endpoints(dwc);
> usb_put_gadget(dwc->gadget);
> dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce,
[Severity: Critical]
This problem wasn't introduced by this patch, but can
dwc->err_recovery_work still be rescheduled before usb_del_gadget()
finishes [1]?
dwc->irq_gadget remains active until usb_del_gadget() stops the UDC and
calls dwc3_gadget_stop() -> free_irq():
CPU0 <hardirq>
dwc3_gadget_exit()
cancel_work_sync(&dwc->err_recovery_work)
dwc3_check_event_buf()
schedule_work(&dwc->err_recovery_work)
usb_del_gadget()
...
dwc3_gadget_stop()
free_irq(dwc->irq_gadget, ...)
mutex_destroy(&dwc->connect_mutex)
dwc3_gadget_free_endpoints(dwc)
usb_put_gadget(dwc->gadget)
dwc3_err_recovery_work()
mutex_lock(&dwc->connect_mutex)
... <-- use-after-free
Should cancel_work_sync(&dwc->err_recovery_work) also be moved after
usb_del_gadget() (right before mutex_destroy())?
[1] https://sashiko.dev/#/bug/linux-daa55f7b-cbeb-467d-b442-1d3982b1d885
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-topic-dwc3_gadget_fix-v1-1-dec7679b81b7@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-11-23 20:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:13 [PATCH] usb: dwc3: gadget: destroy connect_mutex after usb_del_gadget Konrad Dybcio
2026-11-23 20:30 ` sashiko-bot [this message]
2026-11-26 8:38 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-229992@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.