Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop
@ 2026-11-11  7:23 Hyunjung Ko
  2026-11-11  7:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Hyunjung Ko @ 2026-11-11  7:23 UTC (permalink / raw)
  To: Kevin Cernekee, Neill Kapron
  Cc: Greg Kroah-Hartman, Felipe Balbi, Sebastian Andrzej Siewior,
	linux-usb, linux-kernel, Hyunjung Ko, stable

bcm63xx_udc_stop() clears udc->driver and then calls msleep(100) plus the
PHY/clock teardown while still holding udc->lock, which is taken with
spin_lock_irqsave(). Sleeping in that atomic context triggers "BUG:
scheduling while atomic" (and a CONFIG_DEBUG_ATOMIC_SLEEP splat) when the
gadget driver is unbound.

The lock is only needed to clear udc->driver, which serializes against the
interrupt handler. The settle delay and the bcm63xx_select_phy_mode() /
set_clocks() teardown only touch hardware and are already called without
the lock during init, so drop the lock right after clearing udc->driver
and run the sleep and teardown unlocked.

Fixes: 613065e53cb1 ("usb: gadget: bcm63xx UDC driver")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
 drivers/usb/gadget/udc/bcm63xx_udc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c
index ba91b1ebbf57..269063d19f10 100644
--- a/drivers/usb/gadget/udc/bcm63xx_udc.c
+++ b/drivers/usb/gadget/udc/bcm63xx_udc.c
@@ -1847,8 +1847,8 @@ static int bcm63xx_udc_stop(struct usb_gadget *gadget)
 	unsigned long flags;
 
 	spin_lock_irqsave(&udc->lock, flags);
-
 	udc->driver = NULL;
+	spin_unlock_irqrestore(&udc->lock, flags);
 
 	/*
 	 * If we switch the PHY too abruptly after dropping D+, the host
@@ -1861,8 +1861,6 @@ static int bcm63xx_udc_stop(struct usb_gadget *gadget)
 	bcm63xx_select_phy_mode(udc, false);
 	set_clocks(udc, false);
 
-	spin_unlock_irqrestore(&udc->lock, flags);
-
 	return 0;
 }
 
-- 
2.43.0

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

* Re: [PATCH] usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop
  2026-11-11  7:23 [PATCH] usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop Hyunjung Ko
@ 2026-11-11  7:32 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-11  7:32 UTC (permalink / raw)
  To: Hyunjung Ko; +Cc: linux-usb

> bcm63xx_udc_stop() clears udc->driver and then calls msleep(100) plus the
> PHY/clock teardown while still holding udc->lock, which is taken with
> spin_lock_irqsave(). Sleeping in that atomic context triggers "BUG:
> scheduling while atomic" (and a CONFIG_DEBUG_ATOMIC_SLEEP splat) when the
> gadget driver is unbound.
> 
> The lock is only needed to clear udc->driver, which serializes against the
> interrupt handler. The settle delay and the bcm63xx_select_phy_mode() /
> set_clocks() teardown only touch hardware and are already called without
> the lock during init, so drop the lock right after clearing udc->driver
> and run the sleep and teardown unlocked.
> 
> Fixes: 613065e53cb1 ("usb: gadget: bcm63xx UDC driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111072310.3005580-1-hj351016@gmail.com?part=1


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

end of thread, other threads:[~2026-11-11  7:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  7:23 [PATCH] usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop Hyunjung Ko
2026-11-11  7:32 ` sashiko-bot

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