Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: dwc2: gadget: Fix spin_lock/unlock mismatch in dwc2_hsotg_udc_stop()

dwc2_gadget_exit_clock_gating() internally calls call_gadget() macro,
which expects hsotg->lock to be held since it does spin_unlock/spin_lock
around the gadget driver callback invocation.

However, dwc2_hsotg_udc_stop() calls dwc2_gadget_exit_clock_gating()
without holding the lock. This leads to:
- spin_unlock on a lock that is not held (undefined behavior)
- The lock remaining held after dwc2_gadget_exit_clock_gating() returns,
causing a deadlock when spin_lock_irqsave() is called later in the
same function.

Fix this by acquiring hsotg->lock before calling
dwc2_gadget_exit_clock_gating() and releasing it afterwards, which
satisfies the locking requirement of the call_gadget() macro.

Fixes: af076a41f8a2 ("usb: dwc2: also exit clock_gating when stopping udc while suspended")
Cc: stable <stable@kernel.org>
Signed-off-by: Juno Choi <juno.choi@lge.com>
Link: https://patch.msgid.link/20260324014910.2798425-1-juno.choi@lge.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Juno Choi and committed by
Greg Kroah-Hartman
9bb4b5ed eba2936b

+2
+2
drivers/usb/dwc2/gadget.c
··· 4607 4607 /* Exit clock gating when driver is stopped. */ 4608 4608 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && 4609 4609 hsotg->bus_suspended && !hsotg->params.no_clock_gating) { 4610 + spin_lock_irqsave(&hsotg->lock, flags); 4610 4611 dwc2_gadget_exit_clock_gating(hsotg, 0); 4612 + spin_unlock_irqrestore(&hsotg->lock, flags); 4611 4613 } 4612 4614 4613 4615 /* all endpoints should be shutdown */