usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop
Subsystems (3)
PATCH 1/1 usb: gadget: bcm63xx_udc: don't sleep under spinlock in udc_stop
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.
--- drivers/usb/gadget/udc/bcm63xx_udc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/gadget/udc/bcm63xx_udc.c +1 -3
@@ -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 ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 12 lines
bcm63xx_udc_stop()clearsudc->driverand then calls msleep(100) plus the PHY/clock teardown while still holdingudc->lock, which is taken withspin_lock_irqsave(). Sleeping in that atomic context triggers "BUG:
scheduling while atomic" (and aCONFIG_DEBUG_ATOMIC_SLEEPsplat) 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 thebcm63xx_select_phy_mode()/set_clocks()teardown only touch hardware and are already called without the lock during init, so drop the lock right after clearingudc->driverand run the sleep and teardown unlocked.
Quoted 3 lines
Fixes 613065e53cb1 ("usb: gadget: bcm63xx UDC driver")Signed-off-by Hyunjung Ko <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Greg Kroah-Hartman
maintainerQuoted 24 lines · Hyunjung Ko
bcm63xx_udc_stop()clearsudc->driverand then calls msleep(100) plus the PHY/clock teardown while still holdingudc->lock, which is taken withspin_lock_irqsave(). Sleeping in that atomic context triggers "BUG:
scheduling while atomic" (and aCONFIG_DEBUG_ATOMIC_SLEEPsplat) 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 thebcm63xx_select_phy_mode()/set_clocks()teardown only touch hardware and are already called without the lock during init, so drop the lock right after clearingudc->driverand run the sleep and teardown unlocked.Fixes 613065e53cb1 ("usb: gadget: bcm63xx UDC driver")Signed-off-by Hyunjung Ko <[email protected]>--- drivers/usb/gadget/udc/bcm63xx_udc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/usb/gadget/udc/bcm63xx_udc.c +0
-0
drivers/usb/gadget/udc/bcm63xx_udc.c static int bcm63xx_udc_stop(struct usb_gadget *gadget) · line 1851
Quoted 6 lines
drivers/usb/gadget/udc/bcm63xx_udc.c +1
-1@@ -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);
Why is a lock needed to write a single atomic value?
thanks,
greg k-h