[PATCH v2 1/2] usb: dwc3: apple: unregister role switch before taking lock
From: Keisuke Tsukuda
Date: Tue Nov 17 2026 - 08:00:46 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Keisuke Tsukuda <tkdkei@xxxxxxxxxx>
---
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