From nobody Sun Apr 5 13:04:58 2026 Received: from lgeamrelo12.lge.com (lgeamrelo12.lge.com [156.147.23.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0A591A239A for ; Tue, 24 Mar 2026 02:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774318756; cv=none; b=WN/uSL/vrGOg6y0QOkdGZFZRlY63+xp26GtTMeZYAc3I2GgBWJK4htrF/mWIsHH9reaBj0E3OpiRHTxMuvhQ8rLqJNM8BqDX+7jKV78xZ+zr+R/+1Kc3Pn5Xrn0aORwLQNr7nLG+jFLwV/BCOyJgKZONp7ppX3H/EqGfoLlIfzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774318756; c=relaxed/simple; bh=+DOTZt+pI31A1817AaaCzPVN5MLv6LUuwxHGo3nAfgA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SzZeLiaA4JrB5bTou/8u/UW9v1t088zEPMqGAUCZtpt/z8lZHLPlTExLYwAdWL3Nzx4aXTemg+SOzAwCYN9bhpUjXgZZx3p7rqVZHefXdrJhyFxGYTSVMbgH/buW0be3SLLcN9hUai3vMFSAmr2nadYnPNZAZow579/xRi5npzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo01.lge.com) (156.147.1.125) by 156.147.23.52 with ESMTP; 24 Mar 2026 10:49:10 +0900 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: juno.choi@lge.com Received: from unknown (HELO solarsun-desktop..) (10.157.93.226) by 156.147.1.125 with ESMTP; 24 Mar 2026 10:49:10 +0900 X-Original-SENDERIP: 10.157.93.226 X-Original-MAILFROM: juno.choi@lge.com From: "juno.choi" To: hminas@synopsys.com, gregkh@linuxfoundation.org Cc: m.grzeschik@pengutronix.de, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Juno Choi , stable@kernel.org Subject: [PATCH] usb: dwc2: gadget: Fix spin_lock/unlock mismatch in dwc2_hsotg_udc_stop() Date: Tue, 24 Mar 2026 10:49:10 +0900 Message-Id: <20260324014910.2798425-1-juno.choi@lge.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Juno Choi 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 w= hile suspended") Cc: stable@kernel.org Signed-off-by: Juno Choi --- drivers/usb/dwc2/gadget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 834fc02610a2..e88683b1268f 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4607,7 +4607,9 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gad= get) /* Exit clock gating when driver is stopped. */ if (hsotg->params.power_down =3D=3D DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && !hsotg->params.no_clock_gating) { + spin_lock_irqsave(&hsotg->lock, flags); dwc2_gadget_exit_clock_gating(hsotg, 0); + spin_unlock_irqrestore(&hsotg->lock, flags); } =20 /* all endpoints should be shutdown */ --=20 2.34.1