Skip to contentSkip to conversation

usb: add missing pm_runtime_dont_use_autosuspend() calls

PATCH In review Joshua Crofts 6 participants 16 messages Sep 15 – Sep 18

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

cover usb: add missing pm_runtime_dont_use_autosuspend() calls

Several drivers in the USB subsystem forget to call dont_use_autosuspend() on teardown or error, causing potential resource leaks. This series adds the missing calls.

The offending drivers were found using a semantic patch for Coccinelle I'm working on [1].

[1] https://lore.kernel.org/all/[email protected]/

Joshua Crofts (6):
usb: core: add missing pm_runtime_dont_use_autosuspend() call
usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call
usb: xhci: add missing pm_runtime_dont_use_autosuspend() calls
usb: typec: ucsi: ccg: add missing pm_runtime_dont_use_autosuspend()
call
usb: mtu3: add missing pm_runtime_dont_use_autosuspend() calls
usb: cdns3: add missing pm_runtime_dont_use_autosuspend() call

 drivers/usb/cdns3/cdns3-plat.c    | 1 +
 drivers/usb/core/hub.c            | 1 +
 drivers/usb/host/xhci-mtk.c       | 2 ++
 drivers/usb/host/xhci-plat.c      | 2 ++
 drivers/usb/mtu3/mtu3_plat.c      | 2 ++
 drivers/usb/typec/ucsi/ucsi_ccg.c | 1 +
 6 files changed, 9 insertions(+)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/6 usb: core: add missing pm_runtime_dont_use_autosuspend() call

The fail label in usb_new_device() disables pm_runtime on failure, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes fcc4a01eb866 ("USB: use the runtime-PM autosuspend implementation")
---
 drivers/usb/core/hub.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
index 3345b3298daf..dec6d5c49759 100644
@@ -2745,6 +2745,7 @@ int usb_new_device(struct usb_device *udev)
 fail:
 	usb_set_device_state(udev, USB_STATE_NOTATTACHED);
 	pm_runtime_disable(&udev->dev);
+	pm_runtime_dont_use_autosuspend(&udev->dev);
 	pm_runtime_set_suspended(&udev->dev);
 	return err;
 }
Signature · 1 line
2.47.3
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] usb: core: add missing pm_runtime_dont_use_autosuspend() call

Quoted 28 lines · Joshua Crofts

The fail label in usb_new_device() disables pm_runtime on failure, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes fcc4a01eb866 ("USB: use the runtime-PM autosuspend implementation")
---
 drivers/usb/core/hub.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
index 3345b3298daf..dec6d5c49759 100644
@@ -2745,6 +2745,7 @@ int usb_new_device(struct usb_device *udev)
 fail:
 	usb_set_device_state(udev, USB_STATE_NOTATTACHED);
 	pm_runtime_disable(&udev->dev);
+	pm_runtime_dont_use_autosuspend(&udev->dev);
 	pm_runtime_set_suspended(&udev->dev);
 	return err;
 }
Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH 1/6] usb: core: add missing pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts
Quoted 2 lines · Joshua Crofts

The fail label in usb_new_device() disables pm_runtime on failure, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

No it does not, as the device itself is about to be freed. Sure we could disable autosuspend again here, but it does not really matter.

You could consider balancing the runtime pm count as well, as I guess both of these could trip up static checkers (cf. [1]).

Quoted 6 lines

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes fcc4a01eb866 ("USB: use the runtime-PM autosuspend implementation")

But this one should not have a Fixes tag and does not need to be backported.

Quoted 10 lines
---
 drivers/usb/core/hub.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +0 -0
index 3345b3298daf..dec6d5c49759 100644

drivers/usb/core/hub.c int usb_new_device(struct usb_device *udev) · line 2751

Quoted 7 lines
drivers/usb/core/hub.c +1 -0
@@ -2745,6 +2745,7 @@ int usb_new_device(struct usb_device *udev)
 fail:
 	usb_set_device_state(udev, USB_STATE_NOTATTACHED);
 	pm_runtime_disable(&udev->dev);
+	pm_runtime_dont_use_autosuspend(&udev->dev);
 	pm_runtime_set_suspended(&udev->dev);
 	return err;
 }

Johan

[1] https://lore.kernel.org/all/[email protected]/

#4 lore raw

Re: [PATCH 1/6] usb: core: add missing pm_runtime_dont_use_autosuspend() call

Quoted 7 lines · On Wed, 16 Sep 2026 10:08:52 +0200 Johan Hovold <[email protected]> wrote:
Quoted 2 lines · Joshua Crofts

The fail label in usb_new_device() disables pm_runtime on failure, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

No it does not, as the device itself is about to be freed. Sure we could disable autosuspend again here, but it does not really matter.

Okay, commit message aside, you still need to call dont_use_autosuspend() on teardown as the driver doesn't use the devm_* counterparts. Currently (according to my cocci SmPL [1]) there are 195 instances of this in the kernel.

...

Quoted 2 lines

But this one should not have a Fixes tag and does not need to be backported.

Yeah, you already mentioned this in IIO once [2]. I found several instances of patches like these being backported however, so perhaps times have changed.

[1] https://lore.kernel.org/cocci/[email protected]/
[2] https://lore.kernel.org/linux-iio/[email protected]/

Signature · 2 lines
Kind regards,
Joshua Crofts
#5 lore raw

Re: [PATCH 1/6] usb: core: add missing pm_runtime_dont_use_autosuspend() call

Quoted 7 lines · Joshua Crofts
Quoted 4 lines · On Wed, 16 Sep 2026 10:08:52 +0200 Johan Hovold <[email protected]> wrote:
Quoted 2 lines · Joshua Crofts

The fail label in usb_new_device() disables pm_runtime on failure, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Quoted 6 lines
Quoted 3 lines

No it does not, as the device itself is about to be freed. Sure we could disable autosuspend again here, but it does not really matter.

Okay, commit message aside, you still need to call dont_use_autosuspend() on teardown as the driver doesn't use the devm_* counterparts.

No, you don't *need* to call it, but it is good practice to clean up after yourself even for the theoretical corner case of someone forcibly rebinding a different driver (which will soon also be tainting the kernel).

But in this particular case (usb core) where all callers *free* the device after the function returns it does not matter one bit.

Quoted 10 lines

Currently
(according to my cocci SmPL [1]) there are 195 instances of this in the kernel.

...

Quoted 2 lines

But this one should not have a Fixes tag and does not need to be backported.

Yeah, you already mentioned this in IIO once [2]. I found several instances of patches like these being backported however, so perhaps times have changed.

If you write a misleading commit message and add a CC stable tag, chances are that a maintainer will miss this when reviewing and then the commit gets backported.

That in no way means that you should continue doing so on purpose, that's bordering willful deception.

Johan

Quoted 2 lines

[1] https://lore.kernel.org/cocci/[email protected]/
[2] https://lore.kernel.org/linux-iio/[email protected]/

#6 lore raw

PATCH 2/6 usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts

The disable_pm label in xhci_mtk_probe() and xhci_mtk_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes 0cbd4b34cda9 ("xhci: mediatek: support MTK xHCI host controller")
Fixes 04284eb74e0c ("usb: xhci-mtk: add support runtime PM")
---
 drivers/usb/host/xhci-mtk.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-mtk.c +2 -0
index 60af5fe29bd4..eb483a267bf6 100644
@@ -700,6 +700,7 @@ static int xhci_mtk_probe(struct platform_device *pdev)
 disable_pm:
 	pm_runtime_put_noidle(dev);
 	pm_runtime_disable(dev);
+	pm_runtime_dont_use_autosuspend(dev);
 	return ret;
 }
 
@@ -731,6 +732,7 @@ static void xhci_mtk_remove(struct platform_device *pdev)
 	regulator_bulk_disable(BULK_VREGS_NUM, mtk->supplies);
 
 	pm_runtime_disable(dev);
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);
 }
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 2/6
#7 lore raw

Re: [PATCH 2/6] usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call

Quoted 4 lines · Joshua Crofts

The disable_pm label in xhci_mtk_probe() and xhci_mtk_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Quoted 8 lines

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes 0cbd4b34cda9 ("xhci: mediatek: support MTK xHCI host controller")
Fixes 04284eb74e0c ("usb: xhci-mtk: add support runtime PM")
#8 lore raw

Re: [PATCH 2/6] usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts
Quoted 3 lines · Joshua Crofts

The disable_pm label in xhci_mtk_probe() and xhci_mtk_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

No, there is no resource leak here either and this does not need to be backported.

The autosuspend setting is not restored, but that would only possibly have an impact in the theoretical corner case that someone forcibly rebinds a different driver that does not enable it.

Quoted 7 lines

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes 0cbd4b34cda9 ("xhci: mediatek: support MTK xHCI host controller")
Fixes 04284eb74e0c ("usb: xhci-mtk: add support runtime PM")

So, without having looked at the rest: none of these should be backported.

Johan

#9 lore raw

PATCH 3/6 usb: xhci: add missing pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts

The disable_runtime label in xhci_plat_probe() and xhci_plat_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes b0c69b4bace3 ("usb: host: plat: Enable xHCI plat runtime PM")
---
 drivers/usb/host/xhci-plat.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-plat.c +2 -0
index 6fd595f81a30..29e743d6868e 100644
@@ -388,6 +388,7 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
 disable_runtime:
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 
 	return ret;
 }
@@ -461,6 +462,7 @@ void xhci_plat_remove(struct platform_device *dev)
 	usb_put_hcd(hcd);
 
 	pm_runtime_disable(&dev->dev);
+	pm_runtime_dont_use_autosuspend(&dev->dev);
 	pm_runtime_put_noidle(&dev->dev);
 	pm_runtime_set_suspended(&dev->dev);
 }
Signature · 1 line
2.47.3
#10 lore raw

PATCH 4/6 usb: typec: ucsi: ccg: add missing pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts

ucsi_ccg_remove() disables PM runtime on teardown, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes a94ecde41f7e ("usb: typec: ucsi: ccg: enable runtime pm support")
---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi_ccg.c +1 -0
index 91c2958a708c..9d3ebb255de7 100644
@@ -1519,6 +1519,7 @@ static void ucsi_ccg_remove(struct i2c_client *client)
 
 	cancel_work_sync(&uc->pm_work);
 	cancel_work_sync(&uc->work);
+	pm_runtime_dont_use_autosuspend(uc->dev);
 	pm_runtime_disable(uc->dev);
 	ucsi_unregister(uc->ucsi);
 	free_irq(uc->irq, uc);
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 4/6
#11 lore raw

Re: [PATCH 4/6] usb: typec: ucsi: ccg: add missing pm_runtime_dont_use_autosuspend() call

Quoted 10 lines · Joshua Crofts

ucsi_ccg_remove() disables PM runtime on teardown, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes a94ecde41f7e ("usb: typec: ucsi: ccg: enable runtime pm support")
Quoted 18 lines
---
 drivers/usb/typec/ucsi/ucsi_ccg.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi_ccg.c +1 -0
index 91c2958a708c..9d3ebb255de7 100644
@@ -1519,6 +1519,7 @@ static void ucsi_ccg_remove(struct i2c_client *client)
 
 	cancel_work_sync(&uc->pm_work);
 	cancel_work_sync(&uc->work);
+	pm_runtime_dont_use_autosuspend(uc->dev);
 	pm_runtime_disable(uc->dev);
 	ucsi_unregister(uc->ucsi);
 	free_irq(uc->irq, uc);
Signature · 1 line
2.47.3
Signature · 1 line
heikki
#12 lore raw

PATCH 5/6 usb: mtu3: add missing pm_runtime_dont_use_autosuspend() calls

In reply to Joshua Crofts

The comm_init_err label in mtu3_probe() and mtu3_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes df2069acb005 ("usb: Add MediaTek USB3 DRD driver")
Fixes fa6f59e28c61 ("usb: mtu3: support runtime PM for host mode")
---
 drivers/usb/mtu3/mtu3_plat.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/mtu3/mtu3_plat.c +2 -0
index b4f4c776adb9..ce64c36a98f7 100644
@@ -445,6 +445,7 @@ static int mtu3_probe(struct platform_device *pdev)
 comm_init_err:
 	pm_runtime_put_noidle(dev);
 	pm_runtime_disable(dev);
+	pm_runtime_dont_use_autosuspend(dev);
 	ssusb_debugfs_remove_root(ssusb);
 
 	return ret;
@@ -483,6 +484,7 @@ static void mtu3_remove(struct platform_device *pdev)
 	ssusb_rscs_exit(ssusb);
 	ssusb_debugfs_remove_root(ssusb);
 	pm_runtime_disable(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
 }
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 5/6
#13 lore raw

Re: [PATCH 5/6] usb: mtu3: add missing pm_runtime_dont_use_autosuspend() calls

Quoted 4 lines · Joshua Crofts

The comm_init_err label in mtu3_probe() and mtu3_remove() both call pm_runtime_disable() on error or device teardown, but don't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Quoted 8 lines

Add the missing pm_runtime_dont_use_autosuspend().

Found using Coccinelle.

Fixes df2069acb005 ("usb: Add MediaTek USB3 DRD driver")
Fixes fa6f59e28c61 ("usb: mtu3: support runtime PM for host mode")
#14 lore raw

PATCH 6/6 usb: cdns3: add missing pm_runtime_dont_use_autosuspend() call

In reply to Joshua Crofts

cdns3_plat_remove() calls pm_runtime_disable() on device teardown, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes f738957277ba ("usb: cdns3: Split core.c into cdns3-plat and core.c file")
---
 drivers/usb/cdns3/cdns3-plat.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/cdns3/cdns3-plat.c +1 -0
index e3f32c3e9535..b85d5d1c48fd 100644
@@ -219,6 +219,7 @@ static void cdns3_plat_remove(struct platform_device *pdev)
 	if (!(cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
 		pm_runtime_allow(dev);
 
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	cdns_remove(cdns);
Signature · 1 line
2.47.3
maintainer
#15 lore raw

Re: [PATCH 6/6] usb: cdns3: add missing pm_runtime_dont_use_autosuspend() call

Quoted 2 lines · Joshua Crofts

cdns3_plat_remove() calls pm_runtime_disable() on device teardown, but doesn't call pm_runtime_dont_use_autosuspend(), causing resource leaks.

Not a resource leak.

Quoted 7 lines

Add the missing pm_runtime_dont_use_autosuspend() call.

Found using Coccinelle.

Fixes f738957277ba ("usb: cdns3: Split core.c into cdns3-plat and core.c file")

Not a big issue, it is not necessary to backport.

Peter

Quoted 20 lines
---
 drivers/usb/cdns3/cdns3-plat.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/cdns3/cdns3-plat.c +1 -0
index e3f32c3e9535..b85d5d1c48fd 100644
@@ -219,6 +219,7 @@ static void cdns3_plat_remove(struct platform_device *pdev)
 	if (!(cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
 		pm_runtime_allow(dev);
 
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	cdns_remove(cdns);
Signature · 1 line
2.47.3
Signature · 2 lines
Thanks,
Peter Chen