mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keisuke Tsukuda <tkdkei@outlook.jp>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Sven Peter <sven@kernel.org>, Janne Grunau <j@jannau.net>,
	Neal Gompa <neal@gompa.dev>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"asahi@lists.linux.dev" <asahi@lists.linux.dev>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 1/2] usb: dwc3: apple: unregister role switch before taking lock
Date: Tue, 17 Nov 2026 13:00:17 +0000	[thread overview]
Message-ID: <20261117125825.27629-2-tkdkei@outlook.jp> (raw)
In-Reply-To: <20261117125825.27629-1-tkdkei@outlook.jp>

The Apple DWC3 role-switch callbacks take appledwc->lock while the
role-switch core holds sw->lock. The core needs to take sw->lock during
unregister to wait for callbacks. With the current remove order, this
would invert the locks: remove would hold appledwc->lock and wait for
sw->lock, while a callback could hold sw->lock and wait for
appledwc->lock.

Unregister the role switch before taking appledwc->lock. This lets the
core wait for callbacks before the device is torn down, without creating
a lock inversion when the role-switch core change is applied.

Cc: stable@vger.kernel.org
Signed-off-by: Keisuke Tsukuda <tkdkei@outlook.jp>
---
 drivers/usb/dwc3/dwc3-apple.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c
--- a/drivers/usb/dwc3/dwc3-apple.c
+++ b/drivers/usb/dwc3/dwc3-apple.c
@@ -487,9 +487,9 @@
 	struct dwc3 *dwc = platform_get_drvdata(pdev);
 	struct dwc3_apple *appledwc = to_dwc3_apple(dwc);
 
+	usb_role_switch_unregister(appledwc->role_sw);
+
 	guard(mutex)(&appledwc->lock);
-
-	usb_role_switch_unregister(appledwc->role_sw);
 
 	/*
 	 * If we're still in DWC3_APPLE_PROBE_PENDING we never got any cable connected event and

  reply	other threads:[~2026-11-17 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:59 [PATCH v2 0/2] usb: roles: wait for callbacks during unregister Keisuke Tsukuda
2026-11-17 13:00 ` Keisuke Tsukuda [this message]
2026-11-17 13:00 ` [PATCH v2 2/2] usb: roles: wait for callbacks on unregister Keisuke Tsukuda
2026-11-20 13:23   ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117125825.27629-2-tkdkei@outlook.jp \
    --to=tkdkei@outlook.jp \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=asahi@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=j@jannau.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neal@gompa.dev \
    --cc=sven@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®