mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage
@ 2026-09-15  6:43 Joshua Crofts
  2026-09-16  9:21 ` Johan Hovold
  0 siblings, 1 reply; 4+ messages in thread
From: Joshua Crofts @ 2026-09-15  6:43 UTC (permalink / raw)
  To: Julia Lawall, Nicolas Palix; +Cc: linux-kernel, cocci

Add a checker for ensuring that pm_runtime_dont_use_autosuspend() is
called in a file if pm_runtime_use_autosuspend() is called and its
devm_* counterpart isn't present.

Without _dont_use_autosuspend(), removing devices causes resource leaks.

Assisted-by: LLM
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 scripts/coccinelle/api/pm_autosuspend.cocci | 64 +++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 scripts/coccinelle/api/pm_autosuspend.cocci

diff --git a/scripts/coccinelle/api/pm_autosuspend.cocci b/scripts/coccinelle/api/pm_autosuspend.cocci
new file mode 100644
index 000000000000..581e874cd10b
--- /dev/null
+++ b/scripts/coccinelle/api/pm_autosuspend.cocci
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Find drivers that enable autosuspend via pm_runtime_use_autosuspend()
+/// but never call pm_runtime_dont_use_autosuspend() anywhere in the file,
+/// while not using devm_pm_runtime_enable().
+//
+// Confidence: High
+// Copyright: (C) 2026 Joshua Crofts
+// URL: https://coccinelle.gitlabpages.inria.fr/website
+// Options: --no-includes
+
+virtual context
+virtual org
+virtual report
+
+//----------------------------------------------------------
+// Detection
+//----------------------------------------------------------
+
+@has_use@
+expression dev;
+position p;
+@@
+
+pm_runtime_use_autosuspend@p(dev)
+
+@has_dont@
+expression dev;
+@@
+
+pm_runtime_dont_use_autosuspend(dev)
+
+@has_devm@
+expression dev;
+@@
+
+devm_pm_runtime_enable(dev)
+
+//----------------------------------------------------------
+// Context mode
+//----------------------------------------------------------
+
+@depends on context && has_use && !has_dont && !has_devm@
+expression dev;
+@@
+
+* pm_runtime_use_autosuspend(dev)
+
+//----------------------------------------------------------
+// Org and report mode
+//----------------------------------------------------------
+
+@script:python depends on org && !has_dont && !has_devm@
+p << has_use.p;
+@@
+
+msg = "WARNING: pm_runtime_use_autosuspend() called without matching pm_runtime_dont_use_autosuspend() or devm_pm_runtime_enable()"
+cocci.print_main(msg, p)
+
+@script:python depends on report && !has_dont && !has_devm@
+p << has_use.p;
+@@
+
+msg = "WARNING: pm_runtime_use_autosuspend() called without matching pm_runtime_dont_use_autosuspend() or devm_pm_runtime_enable()"
+coccilib.report.print_report(p[0], msg)
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage
  2026-09-15  6:43 [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage Joshua Crofts
@ 2026-09-16  9:21 ` Johan Hovold
  2026-09-16  9:24   ` Joshua Crofts
  2026-09-16  9:25   ` Julia Lawall
  0 siblings, 2 replies; 4+ messages in thread
From: Johan Hovold @ 2026-09-16  9:21 UTC (permalink / raw)
  To: Joshua Crofts; +Cc: Julia Lawall, Nicolas Palix, linux-kernel, cocci

On Tue, Sep 15, 2026 at 06:43:27AM +0000, Joshua Crofts wrote:
> Add a checker for ensuring that pm_runtime_dont_use_autosuspend() is
> called in a file if pm_runtime_use_autosuspend() is called and its
> devm_* counterpart isn't present.
> 
> Without _dont_use_autosuspend(), removing devices causes resource leaks.

No, as I've explained repeatedly elsewhere, it does not cause any
resource leaks. [1][2]

The autosuspend setting leaks if you will, but that only matters in the
theoretical corner case of someone rebinding a different driver (which
will soon also taint the kernel).

So don't exaggerate the impact, this is essentially just a cleanup,
which is fine in itself.

> Assisted-by: LLM
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>

Johan

[1] https://lore.kernel.org/all/aqpd3viN1UoZBkgL@hovoldconsulting.com/
[2] https://lore.kernel.org/linux-iio/aow51Nk-cet9qaUQ@hovoldconsulting.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage
  2026-09-16  9:21 ` Johan Hovold
@ 2026-09-16  9:24   ` Joshua Crofts
  2026-09-16  9:25   ` Julia Lawall
  1 sibling, 0 replies; 4+ messages in thread
From: Joshua Crofts @ 2026-09-16  9:24 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Julia Lawall, Nicolas Palix, linux-kernel, cocci

On Wed, 16 Sep 2026 11:21:24 +0200
Johan Hovold <johan@kernel.org> wrote:

> On Tue, Sep 15, 2026 at 06:43:27AM +0000, Joshua Crofts wrote:
> > Add a checker for ensuring that pm_runtime_dont_use_autosuspend() is
> > called in a file if pm_runtime_use_autosuspend() is called and its
> > devm_* counterpart isn't present.
> > 
> > Without _dont_use_autosuspend(), removing devices causes resource leaks.  
> 
> No, as I've explained repeatedly elsewhere, it does not cause any
> resource leaks. [1][2]
> 
> The autosuspend setting leaks if you will, but that only matters in the
> theoretical corner case of someone rebinding a different driver (which
> will soon also taint the kernel).
> 
> So don't exaggerate the impact, this is essentially just a cleanup,
> which is fine in itself.

Yes, I got your point the first time. I'll edit the commit message for
this patch and all subsequent patches based on this script.

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage
  2026-09-16  9:21 ` Johan Hovold
  2026-09-16  9:24   ` Joshua Crofts
@ 2026-09-16  9:25   ` Julia Lawall
  1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2026-09-16  9:25 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Joshua Crofts, Nicolas Palix, linux-kernel, cocci



On Wed, 16 Sep 2026, Johan Hovold wrote:

> On Tue, Sep 15, 2026 at 06:43:27AM +0000, Joshua Crofts wrote:
> > Add a checker for ensuring that pm_runtime_dont_use_autosuspend() is
> > called in a file if pm_runtime_use_autosuspend() is called and its
> > devm_* counterpart isn't present.
> >
> > Without _dont_use_autosuspend(), removing devices causes resource leaks.
>
> No, as I've explained repeatedly elsewhere, it does not cause any
> resource leaks. [1][2]
>
> The autosuspend setting leaks if you will, but that only matters in the
> theoretical corner case of someone rebinding a different driver (which
> will soon also taint the kernel).
>
> So don't exaggerate the impact, this is essentially just a cleanup,
> which is fine in itself.

Thanks for the feedback.  Joshua, please update the patch accordingly.

julia

>
> > Assisted-by: LLM
> > Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
>
> Johan
>
> [1] https://lore.kernel.org/all/aqpd3viN1UoZBkgL@hovoldconsulting.com/
> [2] https://lore.kernel.org/linux-iio/aow51Nk-cet9qaUQ@hovoldconsulting.com/
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-16  9:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15  6:43 [PATCH v2] coccinelle: api: add a checker for pm_runtime_use_autosuspend() usage Joshua Crofts
2026-09-16  9:21 ` Johan Hovold
2026-09-16  9:24   ` Joshua Crofts
2026-09-16  9:25   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®