usb: add missing pm_runtime_dont_use_autosuspend() calls
Subsystems (7)
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
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.
--- drivers/usb/core/hub.c | 1 + 1 file changed, 1 insertion(+)
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; }
Signature · 1 line
2.47.3
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()disablespm_runtimeon failure, but doesn't callpm_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")Cc <[email protected]>Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/core/hub.c | 1 + 1 file changed, 1 insertion(+)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; }Signature · 1 line
2.47.3
Re: [PATCH 1/6] usb: core: add missing pm_runtime_dont_use_autosuspend() call
In reply to Joshua CroftsQuoted 2 lines · Joshua Crofts
The fail label in
usb_new_device()disablespm_runtimeon failure, but doesn't callpm_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")Cc <[email protected]>
But this one should not have a Fixes tag and does not need to be backported.
Quoted 10 lines
Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/core/hub.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/core/hub.c +0
-0
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
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()disablespm_runtimeon failure, but doesn't callpm_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
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()disablespm_runtimeon failure, but doesn't callpm_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
PATCH 2/6 usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call
In reply to Joshua CroftsThe 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.
--- drivers/usb/host/xhci-mtk.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-mtk.c +2 -0
@@ -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
Re: [PATCH 2/6] usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call
Quoted 4 lines · Joshua Crofts
The
disable_pmlabel inxhci_mtk_probe()andxhci_mtk_remove()both callpm_runtime_disable()on error or device teardown, but don't callpm_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")Cc <[email protected]>Signed-off-by Joshua Crofts <[email protected]>
Re: [PATCH 2/6] usb: xhci-mtk: add missing pm_runtime_dont_use_autosuspend() call
In reply to Joshua CroftsQuoted 3 lines · Joshua Crofts
The
disable_pmlabel inxhci_mtk_probe()andxhci_mtk_remove()both callpm_runtime_disable()on error or device teardown, but don't callpm_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")Cc <[email protected]>
So, without having looked at the rest: none of these should be backported.
Johan
PATCH 3/6 usb: xhci: add missing pm_runtime_dont_use_autosuspend() calls
In reply to Joshua CroftsThe 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.
--- drivers/usb/host/xhci-plat.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-plat.c +2 -0
@@ -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
PATCH 4/6 usb: typec: ucsi: ccg: add missing pm_runtime_dont_use_autosuspend() call
In reply to Joshua Croftsucsi_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.
--- drivers/usb/typec/ucsi/ucsi_ccg.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi_ccg.c +1 -0
@@ -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
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 callpm_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")Cc <[email protected]>Signed-off-by Joshua Crofts <[email protected]>
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@@ -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
PATCH 5/6 usb: mtu3: add missing pm_runtime_dont_use_autosuspend() calls
In reply to Joshua CroftsThe 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.
--- drivers/usb/mtu3/mtu3_plat.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/mtu3/mtu3_plat.c +2 -0
@@ -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
Re: [PATCH 5/6] usb: mtu3: add missing pm_runtime_dont_use_autosuspend() calls
Quoted 4 lines · Joshua Crofts
The
comm_init_errlabel inmtu3_probe()andmtu3_remove()both callpm_runtime_disable()on error or device teardown, but don't callpm_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")Cc <[email protected]>Signed-off-by Joshua Crofts <[email protected]>
PATCH 6/6 usb: cdns3: add missing pm_runtime_dont_use_autosuspend() call
In reply to Joshua Croftscdns3_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.
--- drivers/usb/cdns3/cdns3-plat.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/cdns3/cdns3-plat.c +1 -0
@@ -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
Peter Chen
maintainerRe: [PATCH 6/6] usb: cdns3: add missing pm_runtime_dont_use_autosuspend() call
Quoted 2 lines · Joshua Crofts
cdns3_plat_remove()callspm_runtime_disable()on device teardown, but doesn't callpm_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")Cc <[email protected]>
Not a big issue, it is not necessary to backport.
Peter
Quoted 20 lines
Signed-off-by Joshua Crofts <[email protected]>--- drivers/usb/cdns3/cdns3-plat.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/cdns3/cdns3-plat.c +1
-0@@ -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