Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/4] DWC3 concurrency fixes
@ 2026-11-26 13:01 Konrad Dybcio
  2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Konrad Dybcio @ 2026-11-26 13:01 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman, Jiazi Liu, Wesley Cheng,
	Felipe Balbi
  Cc: linux-usb, Konrad Dybcio, sashiko-bot

Couple of concurrency fixes found by a clanker. Smoke tested on a
Snapdragon-based Fairphone 5, no obvious regressions.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
Konrad Dybcio (4):
      usb: dwc3: gadget: serialize connection bitfield writes
      usb: dwc3: gadget: clear softconnect on stop and failed pullup
      usb: dwc3: gadget: serialize resume against error recovery
      usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget

 drivers/usb/dwc3/gadget.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
---
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
change-id: 20261126-topic-usb_dwc3_fixups-e191ec3d5512

Best regards,
--  
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes
  2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
@ 2026-11-26 13:01 ` Konrad Dybcio
  2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Konrad Dybcio @ 2026-11-26 13:01 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman, Jiazi Liu, Wesley Cheng,
	Felipe Balbi
  Cc: linux-usb, Konrad Dybcio

From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

softconnect and pullups_connected are bitfields that share their storage
with dwc->connected, which is written under dwc->lock from IRQ context.
Unprotected writes to these bitfields can race with the IRQ's updates to
the shared storage.

Take dwc->lock around the softconnect assignment in dwc3_gadget_pullup()
and the pullups_connected assignments in dwc3_gadget_run_stop().

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/usb/dwc3/gadget.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 702cbc8475a8..4fab2d57e7d3 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2680,6 +2680,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
 	u32			reg;
 	u32			timeout = 2000;
 	u32			saved_config = 0;
+	unsigned long		flags;
 
 	if (pm_runtime_suspended(dwc->dev))
 		return 0;
@@ -2723,11 +2724,15 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
 		reg |= DWC3_DCTL_RUN_STOP;
 
 		__dwc3_gadget_set_speed(dwc);
+		spin_lock_irqsave(&dwc->lock, flags);
 		dwc->pullups_connected = true;
+		spin_unlock_irqrestore(&dwc->lock, flags);
 	} else {
 		reg &= ~DWC3_DCTL_RUN_STOP;
 
+		spin_lock_irqsave(&dwc->lock, flags);
 		dwc->pullups_connected = false;
+		spin_unlock_irqrestore(&dwc->lock, flags);
 	}
 
 	dwc3_pre_run_stop(dwc, is_on);
@@ -2851,11 +2856,14 @@ static int dwc3_gadget_soft_connect(struct dwc3 *dwc)
 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 {
 	struct dwc3		*dwc = gadget_to_dwc(g);
+	unsigned long		flags;
 	int			ret;
 
 	is_on = !!is_on;
 
+	spin_lock_irqsave(&dwc->lock, flags);
 	dwc->softconnect = is_on;
+	spin_unlock_irqrestore(&dwc->lock, flags);
 
 	/*
 	 * Avoid issuing a runtime resume if the device is already in the

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup
  2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
  2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
@ 2026-11-26 13:01 ` Konrad Dybcio
  2026-11-26 13:22   ` sashiko-bot
  2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Konrad Dybcio @ 2026-11-26 13:01 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman, Jiazi Liu, Wesley Cheng,
	Felipe Balbi
  Cc: linux-usb, Konrad Dybcio

From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

dwc3_gadget_pullup() sets softconnect before its runtime PM check, so
a failed pullup(1) leaves it set while gadget->connected stays false.
The unbind path then skips pullup(0), and softconnect is never cleared.

Clear softconnect in dwc3_gadget_stop(), so a stopped controller is not
reconnected by err_recovery_work. Take connect_mutex around the clear,
since err_recovery_work reads softconnect under that mutex and would
otherwise race with the store.

Also clear softconnect when pullup(1) fails, both on the runtime PM
error path and when dwc3_gadget_soft_connect() fails, so a failed
connect does not leave softconnect set for stop or err_recovery_work to
act on.

Fixes: 8217f07a5023 ("usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind")
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/usb/dwc3/gadget.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4fab2d57e7d3..d7e22b559876 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2884,8 +2884,12 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 	ret = pm_runtime_get_sync(dwc->dev);
 	if (!ret || ret < 0) {
 		pm_runtime_put(dwc->dev);
-		if (ret < 0)
+		if (ret < 0) {
 			pm_runtime_set_suspended(dwc->dev);
+			spin_lock_irqsave(&dwc->lock, flags);
+			dwc->softconnect = 0;
+			spin_unlock_irqrestore(&dwc->lock, flags);
+		}
 		return ret;
 	}
 
@@ -2902,6 +2906,11 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 		ret = dwc3_gadget_soft_disconnect(dwc);
 	else
 		ret = dwc3_gadget_soft_connect(dwc);
+	if (ret) {
+		spin_lock_irqsave(&dwc->lock, flags);
+		dwc->softconnect = 0;
+		spin_unlock_irqrestore(&dwc->lock, flags);
+	}
 	mutex_unlock(&dwc->connect_mutex);
 
 	pm_runtime_put(dwc->dev);
@@ -3130,10 +3139,13 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 	if (dwc->sys_wakeup)
 		device_wakeup_disable(dwc->sysdev);
 
+	mutex_lock(&dwc->connect_mutex);
 	spin_lock_irqsave(&dwc->lock, flags);
 	dwc->gadget_driver	= NULL;
+	dwc->softconnect = 0;
 	dwc->max_cfg_eps = 0;
 	spin_unlock_irqrestore(&dwc->lock, flags);
+	mutex_unlock(&dwc->connect_mutex);
 
 	free_irq(dwc->irq_gadget, dwc->ev_buf);
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery
  2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
  2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
  2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
@ 2026-11-26 13:01 ` Konrad Dybcio
  2026-11-26 13:22   ` sashiko-bot
  2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
  2026-11-26 13:22 ` [PATCH v2 0/4] DWC3 concurrency fixes sashiko-bot
  4 siblings, 1 reply; 9+ messages in thread
From: Konrad Dybcio @ 2026-11-26 13:01 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman, Jiazi Liu, Wesley Cheng,
	Felipe Balbi
  Cc: linux-usb, Konrad Dybcio

From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

dwc3_gadget_resume() calls dwc3_gadget_soft_connect() without taking
connect_mutex, allowing it to race with err_recovery_work's disconnect
and reconnect sequence.

Take connect_mutex before checking gadget_driver and softconnect, and
hold it through the soft-connect operation. This also serializes the
state check against dwc3_gadget_stop().

Preserve softconnect on resume failure so a later resume can retry the
requested connection.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/usb/dwc3/gadget.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index d7e22b559876..8f40e8dfa3f2 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -8,6 +8,7 @@
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  */
 
+#include <linux/cleanup.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
 #include <linux/property.h>
@@ -5081,6 +5082,8 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)
 
 int dwc3_gadget_resume(struct dwc3 *dwc)
 {
+	guard(mutex)(&dwc->connect_mutex);
+
 	if (!dwc->gadget_driver || !dwc->softconnect)
 		return 0;
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget
  2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
                   ` (2 preceding siblings ...)
  2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
@ 2026-11-26 13:01 ` Konrad Dybcio
  2026-11-26 13:15   ` sashiko-bot
  2026-11-26 13:22 ` [PATCH v2 0/4] DWC3 concurrency fixes sashiko-bot
  4 siblings, 1 reply; 9+ messages in thread
From: Konrad Dybcio @ 2026-11-26 13:01 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman, Jiazi Liu, Wesley Cheng,
	Felipe Balbi
  Cc: linux-usb, Konrad Dybcio, sashiko-bot

From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

dwc3_gadget_exit() cancels err_recovery_work before usb_del_gadget(),
but the work can still be queued while the gadget is being unbound:

- The gadget IRQ is only freed in dwc3_gadget_stop(), which runs from
  usb_del_gadget() when the gadget driver is unbound. An interrupt
  before that point can queue the work from dwc3_check_event_buf().
- The unbind path calls pullup(0), which stops the endpoints. An
  End Transfer timeout there also queues the work, from
  __dwc3_stop_active_transfer().

Either can requeue the work after the cancel, so it may run after the
endpoints have been freed.

Move cancel_work_sync() to after usb_del_gadget(). Once it returns,
the IRQ is freed, so no interrupt can queue the work again. The
pullup(0) path has also completed by then, so the End Transfer timeout
cannot queue it either.

Fixes: 1ff77cbefe5a ("usb: dwc3: gadget: fix IRQ storm on invalid event buffer count")
Fixes: 61575534fb05 ("usb: dwc3: gadget: Recover from End Transfer timeout")
Reported-by: sashiko-bot@kernel.org
Closes: https://lore.kernel.org/all/sashiko-outbox-229992@kernel.org/
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/usb/dwc3/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8f40e8dfa3f2..3c20f2ef6457 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -5047,9 +5047,9 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 	if (!dwc->gadget)
 		return;
 
-	cancel_work_sync(&dwc->err_recovery_work);
 	dwc3_enable_susphy(dwc, true);
 	usb_del_gadget(dwc->gadget);
+	cancel_work_sync(&dwc->err_recovery_work);
 	dwc3_gadget_free_endpoints(dwc);
 	usb_put_gadget(dwc->gadget);
 	dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce,

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget
  2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
@ 2026-11-26 13:15   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 13:15 UTC (permalink / raw)
  To: Konrad Dybcio; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc3: gadget: pullup(0) bypasses connect_mutex during
  err_recovery_work
--

commit 3b95ee598d65cf846e93b3b11ae644862c07819a
Author: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget

This commit moves cancel_work_sync(&dwc->err_recovery_work) to after
usb_del_gadget() in dwc3_gadget_exit() so that work queued during gadget
unbind is canceled before freeing endpoints.

> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 8f40e8dfa3f21..3c20f2ef64576 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -5047,9 +5047,9 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
>  	if (!dwc->gadget)
>  		return;
>  
> -	cancel_work_sync(&dwc->err_recovery_work);
>  	dwc3_enable_susphy(dwc, true);
>  	usb_del_gadget(dwc->gadget);
> +	cancel_work_sync(&dwc->err_recovery_work);
>  	dwc3_gadget_free_endpoints(dwc);
>  	usb_put_gadget(dwc->gadget);
>  	dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce,

[Severity: Medium]
Can an in-flight dwc3_err_recovery_work() restart the controller and EP0
DMA after usb_del_gadget()'s pullup(0) returns early?

kworker                           CPU0
dwc3_err_recovery_work()
  mutex_lock(&dwc->connect_mutex)
  dwc3_gadget_soft_disconnect()
    dwc->pullups_connected = false
  if (dwc->softconnect)
                                  dwc3_gadget_exit()
                                    usb_del_gadget()
                                      ...
                                      dwc3_gadget_pullup(g, 0)
                                        dwc->softconnect = false
                                        if (pullups_connected == is_on)
                                          return 0;
  dwc3_gadget_soft_connect()
    __dwc3_gadget_start()
    dwc3_gadget_run_stop(dwc, true)
  mutex_unlock(&dwc->connect_mutex)
                                    cancel_work_sync(&dwc->err_recovery_work)
                                    dwc3_gadget_free_endpoints(dwc)
                                    dma_free_coherent(..., dwc->ep0_trb, ...)
                                      <-- controller and EP0 DMA active

In dwc3_gadget_pullup(), dwc->pullups_connected == is_on is checked before
acquiring dwc->connect_mutex:

drivers/usb/dwc3/gadget.c:dwc3_gadget_pullup() {
    ...
	if (dwc->pullups_connected == is_on) {
		pm_runtime_put(dwc->dev);
		return 0;
	}

	synchronize_irq(dwc->irq_gadget);

	/* Serialize against dwc3_err_recovery_work() */
	mutex_lock(&dwc->connect_mutex);
    ...
}

Because cancel_work_sync() now runs after usb_del_gadget(),
dwc3_err_recovery_work() can run concurrently with gadget unbind.  Once
dwc3_err_recovery_work() clears dwc->pullups_connected and passes the
dwc->softconnect check, dwc3_gadget_pullup(g, 0) sees
pullups_connected == false and returns early without waiting on
dwc->connect_mutex.  dwc3_err_recovery_work() then calls
dwc3_gadget_soft_connect(), leaving the controller running with active DMA
on dwc->ep0_trb when dwc3_gadget_exit() frees the endpoints and coherent
buffers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-topic-usb_dwc3_fixups-v2-0-c0cc2b75c518@oss.qualcomm.com?part=4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery
  2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
@ 2026-11-26 13:22   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 13:22 UTC (permalink / raw)
  To: Konrad Dybcio; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: dwc3: gadget: missing Fixes trailer for commit 1ff77cbefe5a
--

commit 60d5b6f1be4788382a79ae6d53042b9cab66f822
Author: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

> usb: dwc3: gadget: serialize resume against error recovery
>
> dwc3_gadget_resume() calls dwc3_gadget_soft_connect() without taking
> connect_mutex, allowing it to race with err_recovery_work's disconnect
> and reconnect sequence.
>
> Take connect_mutex before checking gadget_driver and softconnect, and
> hold it through the soft-connect operation. This also serializes the
> state check against dwc3_gadget_stop().
>
> Preserve softconnect on resume failure so a later resume can retry the
> requested connection.
>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

[Severity: Low]
This fixes a race with the error recovery sequence introduced in commit
1ff77cbefe5a ("usb: dwc3: gadget: fix IRQ storm on invalid event buffer
count").  Should this include:

  Fixes: 1ff77cbefe5a ("usb: dwc3: gadget: fix IRQ storm on invalid event buffer count")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-topic-usb_dwc3_fixups-v2-0-c0cc2b75c518@oss.qualcomm.com?part=3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup
  2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
@ 2026-11-26 13:22   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 13:22 UTC (permalink / raw)
  To: Konrad Dybcio; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc3: gadget: race with dwc3_err_recovery_work() on
  softconnect
--

commit a9997a16426be60f4fb31e8b8d1b87b342415fd2
Author: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

usb: dwc3: gadget: clear softconnect on stop and failed pullup

This commit clears dwc->softconnect when dwc3_gadget_pullup() fails and when
dwc3_gadget_stop() stops the gadget under connect_mutex.

> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 4fab2d57e7d3b..d7e22b5598768 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2884,8 +2884,12 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  	ret = pm_runtime_get_sync(dwc->dev);
>  	if (!ret || ret < 0) {
>  		pm_runtime_put(dwc->dev);
> -		if (ret < 0)
> +		if (ret < 0) {
>  			pm_runtime_set_suspended(dwc->dev);
> +			spin_lock_irqsave(&dwc->lock, flags);
> +			dwc->softconnect = 0;
> +			spin_unlock_irqrestore(&dwc->lock, flags);
> +		}
>  		return ret;
>  	}
>  
> @@ -2902,6 +2906,11 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  		ret = dwc3_gadget_soft_disconnect(dwc);
>  	else
>  		ret = dwc3_gadget_soft_connect(dwc);
> +	if (ret) {
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc->softconnect = 0;
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +	}
>  	mutex_unlock(&dwc->connect_mutex);
>  
>  	pm_runtime_put(dwc->dev);
> @@ -3130,10 +3139,13 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>  	if (dwc->sys_wakeup)
>  		device_wakeup_disable(dwc->sysdev);
>  
> +	mutex_lock(&dwc->connect_mutex);
>  	spin_lock_irqsave(&dwc->lock, flags);
>  	dwc->gadget_driver	= NULL;
> +	dwc->softconnect = 0;
>  	dwc->max_cfg_eps = 0;
>  	spin_unlock_irqrestore(&dwc->lock, flags);
> +	mutex_unlock(&dwc->connect_mutex);
>  
>  	free_irq(dwc->irq_gadget, dwc->ev_buf);
>  

[Severity: Medium]
Can dwc3_err_recovery_work() still reconnect the controller during unbind,
or act on a failed pullup(1), because dwc3_gadget_pullup() updates
dwc->softconnect and checks dwc->pullups_connected outside
dwc->connect_mutex?

On the unbind path, dwc3_err_recovery_work() temporarily clears
dwc->pullups_connected before reconnecting:

CPU0 (kworker)                    CPU1 (gadget unbind)
dwc3_err_recovery_work()
  mutex_lock(&dwc->connect_mutex)
  dwc3_gadget_soft_disconnect()
    dwc->pullups_connected = false
  if (dwc->softconnect)
                                  dwc3_gadget_pullup(g, 0)
                                    dwc->softconnect = 0
                                    if (dwc->pullups_connected == 0)
                                      return 0
    dwc3_gadget_soft_connect()
      dwc->pullups_connected = true
  mutex_unlock(&dwc->connect_mutex)
                                  dwc3_gadget_stop(g)
                                    mutex_lock(&dwc->connect_mutex)
                                    dwc->gadget_driver = NULL
                                    dwc->softconnect = 0
                                    mutex_unlock(&dwc->connect_mutex)
                                    free_irq(dwc->irq_gadget, ...)
                                      <-- controller left running

Similarly, because dwc3_gadget_pullup(g, 1) sets dwc->softconnect = 1
before pm_runtime_get_sync() and before taking connect_mutex, an
in-progress dwc3_err_recovery_work() can observe dwc->softconnect == 1 and
call dwc3_gadget_soft_connect() even if pm_runtime_get_sync() subsequently
fails and rolls dwc->softconnect back to 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-topic-usb_dwc3_fixups-v2-0-c0cc2b75c518@oss.qualcomm.com?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/4] DWC3 concurrency fixes
  2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
                   ` (3 preceding siblings ...)
  2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
@ 2026-11-26 13:22 ` sashiko-bot
  4 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 13:22 UTC (permalink / raw)
  To: Konrad Dybcio; +Cc: linux-usb

Sashiko has finished reviewing this 4-patch series:

- Patch 1: no issues found.
- Patch 2 ("usb: dwc3: gadget: clear softconnect on stop and fai..."): 1
  potential issue (1 Medium)
- Patch 3 ("usb: dwc3: gadget: serialize resume against error re..."): 1
  potential issue (1 Low)
- Patch 4 ("usb: dwc3: gadget: cancel err_recovery_work after us..."): 1
  potential issue (1 Medium)

Detailed reviews have been sent as separate replies to patches 2-4.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-topic-usb_dwc3_fixups-v2-0-c0cc2b75c518@oss.qualcomm.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-26 13:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
2026-11-26 13:15   ` sashiko-bot
2026-11-26 13:22 ` [PATCH v2 0/4] DWC3 concurrency fixes sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox