Skip to content

Commit 9bb4b5e

Browse files
Juno Choigregkh
authored andcommitted
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: af076a4 ("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>
1 parent eba2936 commit 9bb4b5e

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/usb/dwc2/gadget.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,9 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget)
46074607
/* Exit clock gating when driver is stopped. */
46084608
if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
46094609
hsotg->bus_suspended && !hsotg->params.no_clock_gating) {
4610+
spin_lock_irqsave(&hsotg->lock, flags);
46104611
dwc2_gadget_exit_clock_gating(hsotg, 0);
4612+
spin_unlock_irqrestore(&hsotg->lock, flags);
46114613
}
46124614

46134615
/* all endpoints should be shutdown */

0 commit comments

Comments
 (0)