Skip to contentSkip to conversation

usb: remove redundant pm_runtime_dont_use_autosuspend calls()

PATCH New Joshua Crofts 2 participants 7 messages Nov 6

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

cover usb: remove redundant pm_runtime_dont_use_autosuspend calls()

Since commit d1706f9da9f4 ("PM: runtime: call pm_runtime_dont_use_autosuspend() on reinit()"), driver core is now responsible for undoing any
pm_runtime_use_autosuspend() calls on driver exit.

Remove the redundant function calls.

Joshua Crofts (3):
usb: chipidea: remove redundant pm_runtime_dont_use_autosuspend() call
usb: musb: remove redundant pm_runtime_dont_use_autosuspend() calls
usb: dwc3: remove redundant pm_runtime_dont_use_autosuspend() calls

 drivers/usb/chipidea/core.c  | 1 -
 drivers/usb/dwc3/core.c      | 2 --
 drivers/usb/dwc3/dwc3-am62.c | 1 -
 drivers/usb/musb/musb_core.c | 2 --
 4 files changed, 6 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/3 usb: chipidea: remove redundant pm_runtime_dont_use_autosuspend() call

Since commit d1706f9da9f4 ("PM: runtime: call pm_runtime_dont_use_autosuspend() on reinit()"), driver core is now responsible for undoing any
pm_runtime_use_autosuspend() calls on driver exit.

Remove the redundant function call.

---
 drivers/usb/chipidea/core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/chipidea/core.c +0 -1
index 3461dd763a6e..7edc512cc37d 100644
@@ -1250,7 +1250,6 @@ static void ci_hdrc_remove(struct platform_device *pdev)
 		usb_role_switch_unregister(ci->role_switch);
 
 	if (ci->supports_runtime_pm) {
-		pm_runtime_dont_use_autosuspend(&pdev->dev);
 		pm_runtime_get_sync(&pdev->dev);
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_put_noidle(&pdev->dev);
Signature · 1 line
2.47.3
#3 lore raw

PATCH 2/3 usb: musb: remove redundant pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts

Since commit d1706f9da9f4 ("PM: runtime: call pm_runtime_dont_use_autosuspend() on reinit()"), driver core is now responsible for undoing any
pm_runtime_use_autosuspend() calls on driver exit.

Remove the redundant function calls.

---
 drivers/usb/musb/musb_core.c | 2 --
 1 file changed, 2 deletions(-)
drivers/usb/musb/musb_core.c +0 -2
index 73ac25f53698..28e59b53fd02 100644
@@ -2576,7 +2576,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	usb_phy_shutdown(musb->xceiv);
 
 err_usb_phy_init:
-	pm_runtime_dont_use_autosuspend(musb->controller);
 	pm_runtime_put_sync(musb->controller);
 	pm_runtime_disable(musb->controller);
 
@@ -2644,7 +2643,6 @@ static void musb_remove(struct platform_device *pdev)
 	spin_unlock_irqrestore(&musb->lock, flags);
 	musb_platform_exit(musb);
 
-	pm_runtime_dont_use_autosuspend(musb->controller);
 	pm_runtime_put_sync(musb->controller);
 	pm_runtime_disable(musb->controller);
 	musb_phy_callback = NULL;
Signature · 1 line
2.47.3
#5 lore raw

PATCH 3/3 usb: dwc3: remove redundant pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts

Since commit d1706f9da9f4 ("PM: runtime: call pm_runtime_dont_use_autosuspend() on reinit()"), driver core is now responsible for undoing any
pm_runtime_use_autosuspend() calls on driver exit.

Remove the redundant function calls.

---
 drivers/usb/dwc3/core.c      | 2 --
 drivers/usb/dwc3/dwc3-am62.c | 1 -
 2 files changed, 3 deletions(-)
drivers/usb/dwc3/core.c +0 -2
index fd5c2cd36c59..c4f0aa962747 100644
@@ -2431,7 +2431,6 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
 err_allow_rpm:
 	pm_runtime_allow(dev);
 	pm_runtime_disable(dev);
-	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_set_suspended(dev);
 	pm_runtime_put_noidle(dev);
 err_disable_clks:
@@ -2486,7 +2485,6 @@ void dwc3_core_remove(struct dwc3 *dwc)
 
 	pm_runtime_allow(dwc->dev);
 	pm_runtime_disable(dwc->dev);
-	pm_runtime_dont_use_autosuspend(dwc->dev);
 	pm_runtime_put_noidle(dwc->dev);
 	/*
 	 * HACK: Clear the driver data, which is currently accessed by parent
drivers/usb/dwc3/dwc3-am62.c +0 -1
index d03b3950ce04..0df7e436aeb0 100644
@@ -322,7 +322,6 @@ static void dwc3_ti_remove(struct platform_device *pdev)
 
 	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
-	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_set_suspended(dev);
 }
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/3] usb: chipidea: remove redundant pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Since commit d1706f9da9f4 ("PM: runtime: call pm_runtime_dont_use_autosuspend() on reinit()"), driver core is now responsible for undoing any
pm_runtime_use_autosuspend() calls on driver exit.

Remove the redundant function call.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH 2/3] usb: musb: remove redundant pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] usb: musb: use-after-free in…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] usb: musb: use-after-free in musb_remove() [1] --

commit 288b4875a2dac2d67d03e8708cdad214c6870682
Author: Joshua Crofts <[email protected]>

usb: musb: remove redundant pm_runtime_dont_use_autosuspend() calls

This commit removes redundant pm_runtime_dont_use_autosuspend() calls in musb_init_controller() and musb_remove() since the driver core now handles this on driver exit.

Quoted 4 lines
drivers/usb/musb/musb_core.c +0 -0
index 73ac25f53698f..28e59b53fd02f 100644

[ ... ]

drivers/usb/musb/musb_core.c static void musb_remove(struct platform_device *pdev) · line 2648

Quoted 8 lines
drivers/usb/musb/musb_core.c +0 -1
@@ -2644,7 +2643,6 @@ static void musb_remove(struct platform_device *pdev)
 	spin_unlock_irqrestore(&musb->lock, flags);
 	musb_platform_exit(musb);
 
-	pm_runtime_dont_use_autosuspend(musb->controller);
 	pm_runtime_put_sync(musb->controller);
 	pm_runtime_disable(musb->controller);
 	musb_phy_callback = NULL;

[Severity: Critical]
This problem wasn't introduced by this patch, but can calling musb_platform_exit(musb) before usb_phy_shutdown(musb->xceiv) a few lines below cause a use-after-free on musb->xceiv [1]?

Platform exit callbacks such as da8xx_musb_exit() call usb_put_phy(musb->xceiv), which drops the final reference and frees the PHY before musb_remove() passes musb->xceiv to usb_phy_shutdown():

drivers/usb/musb/musb_core.c:musb_remove() {
	...
	musb_platform_exit(musb);

	pm_runtime_put_sync(musb->controller);
	pm_runtime_disable(musb->controller);
	musb_phy_callback = NULL;
	if (musb->dma_controller)
		musb_dma_controller_destroy(musb->dma_controller);
	usb_phy_shutdown(musb->xceiv);
	...
}

[1] https://sashiko.dev/#/bug/linux-d180c2b9-0006-4638-a22b-13df8c201235

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH 3/3] usb: dwc3: remove redundant pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] usb: dwc3: autosuspend left enabled on dwc3_core_probe() runtime error It also noticed 1 related…

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] usb: dwc3: autosuspend left enabled on dwc3_core_probe() runtime error
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] usb: dwc3-am62: unchecked pm_runtime_get_sync() in dwc3_ti_remove() [1]
--

commit ff359600a9a87664827e5cdde0c2f86b3442fcb7
Author: Joshua Crofts <[email protected]>

usb: dwc3: remove redundant pm_runtime_dont_use_autosuspend() calls

This commit removes pm_runtime_dont_use_autosuspend() calls from the error and removal paths in dwc3_core_probe(), dwc3_core_remove(), and dwc3_ti_remove().

drivers/usb/dwc3/core.c int dwc3_core_probe(const struct dwc3_probe_data *data) · line 2436

Quoted 12 lines
drivers/usb/dwc3/core.c +0 -1
index fd5c2cd36c595..c4f0aa9627477 100644
@@ -2431,7 +2431,6 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
 err_allow_rpm:
 	pm_runtime_allow(dev);
 	pm_runtime_disable(dev);
-	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_set_suspended(dev);
 	pm_runtime_put_noidle(dev);
 err_disable_clks:

[Severity: Low]
Can this leave dev->power.use_autosuspend enabled if dwc3_core_probe() fails at runtime without unbinding the driver?

In drivers/usb/dwc3/dwc3-apple.c, dwc3_apple_probe() can succeed in the DWC3_APPLE_PROBE_PENDING state without calling dwc3_core_probe(), and later invoke dwc3_usb_role_switch_set() -> dwc3_apple_init() -> dwc3_apple_core_init() -> dwc3_apple_core_probe() -> dwc3_core_probe() when a cable is connected. If dwc3_core_probe() fails after enabling autosuspend and unwinds via err_allow_rpm, the dwc3-apple driver remains bound so pm_runtime_reinit() does not run, leaving autosuspend enabled in sysfs and leaking the runtime PM usage reference if a negative delay was configured.

[ ... ]

drivers/usb/dwc3/dwc3-am62.c static void dwc3_ti_remove(struct platform_device *pdev) · line 326

Quoted 11 lines
drivers/usb/dwc3/dwc3-am62.c +0 -1
index d03b3950ce046..0df7e436aeb0d 100644
@@ -322,7 +322,6 @@ static void dwc3_ti_remove(struct platform_device *pdev)
 
 	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
-	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_set_suspended(dev);
 }

[Severity: High]
This problem wasn't introduced by this patch, but can an unchecked pm_runtime_get_sync() failure in dwc3_ti_remove() [1] cause a synchronous external abort when accessing USBSS_MODE_CONTROL?

drivers/usb/dwc3/dwc3-am62.c:dwc3_ti_remove() {
	...
	pm_runtime_get_sync(dev);
	device_init_wakeup(dev, false);
	of_platform_depopulate(dev);

	/* Clear mode valid bit */
	reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL);
	...
}

If runtime resume fails during unbind, the device remains suspended with its clocks gated while dwc3_ti_readl() and dwc3_ti_writel() access the hardware registers.

[1] https://sashiko.dev/#/bug/linux-413fac67-663c-422c-bdfa-d64685df2b24

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3