Skip to contentSkip to conversation

usb: dwc3: of-simple: fix use-after-free on remove

PATCH Johan Hovold 1 participant 1 message May 31, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The clocks have already been explicitly disabled and put as part of remove() so the runtime suspend callback must not be run when balancing the runtime PM usage count before returning.

Fixes 16adc674d0d6 ("usb: dwc3: add generic OF glue layer")

---

Changes in v2
- balance usage count only after disabling runtime PM to avoid racing with pm_runtime_suspend() as suggested by Alan

 drivers/usb/dwc3/dwc3-of-simple.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-of-simple.c +2 -1
index cb2ee96fd3e8..048922d549dd 100644
@@ -165,8 +165,9 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
 
 	reset_control_put(simple->resets);
 
-	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
+	pm_runtime_put_noidle(dev);
+	pm_runtime_set_suspended(dev);
 
 	return 0;
 }