[PATCH v2 1/2] usb: dwc3: apple: unregister role switch outside appledwc->lock
From: Ilia Snezhkov via B4 Relay
Date: Wed Nov 25 2026 - 19:53:38 EST
From: Ilia Snezhkov <iasnezhkov@xxxxxxxxx>
dwc3_apple_remove() holds appledwc->lock across
usb_role_switch_unregister(), while both dwc3_usb_role_switch_set() and
dwc3_usb_role_switch_get() acquire appledwc->lock.
Calling usb_role_switch_unregister() under appledwc->lock creates an
ABBA lock-order inversion against both sysfs attribute teardown
(device_unregister() -> kernfs_drain() waiting on an active role_show /
role_store callback) and synchronizing usb_role_switch_unregister()
against in-flight callbacks under sw->lock.
appledwc->role_sw is assigned once during probe and never modified
afterwards. Unregister the role switch before acquiring appledwc->lock
for hardware teardown.
Found and drafted with an AI coding assistant.
Fixes: 0ec946d32ef7 ("usb: dwc3: Add Apple Silicon DWC3 glue layer driver")
Signed-off-by: Ilia Snezhkov <iasnezhkov@xxxxxxxxx>
---
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
index 1f474a8..035aeeb 100644
--- a/drivers/usb/dwc3/dwc3-apple.c
+++ b/drivers/usb/dwc3/dwc3-apple.c
@@ -487,10 +487,10 @@ static void dwc3_apple_remove(struct platform_device *pdev)
struct dwc3 *dwc = platform_get_drvdata(pdev);
struct dwc3_apple *appledwc = to_dwc3_apple(dwc);
- guard(mutex)(&appledwc->lock);
-
usb_role_switch_unregister(appledwc->role_sw);
+ guard(mutex)(&appledwc->lock);
+
/*
* If we're still in DWC3_APPLE_PROBE_PENDING we never got any cable connected event and
* dwc3_core_probe was never called and there's hence no need to call dwc3_core_remove.
--
2.54.0 (Apple Git-157)