Skip to contentSkip to conversation

usb: hub: Fix RPM teardown on usb_disconnect

PATCH New Deepak Sharma 1 participant 1 message Sep 15, 2025 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: hub: Fix RPM teardown on usb_disconnect

On usb_disconnect, the free-ing of the device structure of usb_device is not well synchornized with the RPM subsystem, which leads to a possible use-after-free

Add proper device's handling for unregistering from the runtime PM to usb_disconnect

---
 drivers/usb/core/hub.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/core/hub.c +6 -1
index 256fe8c86828..887d987f855e 100644
@@ -2329,8 +2329,13 @@ void usb_disconnect(struct usb_device **pdev)
 	/*
 	 * Ensure that the pm runtime code knows that the USB device
 	 * is in the process of being disconnected.
+	 * This is safe to do here, since all the code paths after
+	 * here will lead to eventual deletion of the device
 	 */
-	pm_runtime_barrier(&udev->dev);
+	pm_runtime_disable(&udev->dev);
+	pm_runtime_dont_use_autosuspend(&udev->dev);
+	pm_runtime_put_noidle(&udev->dev);
+	pm_runtime_set_suspended(&udev->dev);
 
 	usb_lock_device(udev);
 
Signature · 1 line
2.51.0