cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH v1] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL
@ 2022-11-07 11:47 Uwe Kleine-König
  2022-11-07 12:45 ` Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2022-11-07 11:47 UTC (permalink / raw)
  To: Julia Lawall, Nicolas Palix; +Cc: linux-kernel, cocci, kernel

devm_platform_get_and_ioremap_resource(pdev, index, NULL) is equivalent to
the shorter devm_platform_ioremap_resource(pdev, index).

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

a potential improvement is to check for invocations of
devm_platform_get_and_ioremap_resource() where the res parameter isn't
used afterwards, but my coccinelle foo isn't strong enough for that.

Best regards
Uwe

 .../api/devm_platform_ioremap_resource.cocci  | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 scripts/coccinelle/api/devm_platform_ioremap_resource.cocci

diff --git a/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
new file mode 100644
index 000000000000..401610b9a17d
--- /dev/null
+++ b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Don't use devm_platform_get_and_ioremap_resource with NULL as third parameter
+// Confidence: High
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r1@
+position p;
+@@
+ devm_platform_ioremap_resource(...) {
+	...
+	devm_platform_get_and_ioremap_resource@p(...)
+	...
+ }
+
+@depends on patch@
+expression pdev,index;
+position p != r1.p;
+@@
+
+-  devm_platform_get_and_ioremap_resource@p(pdev, index, NULL)
++  devm_platform_ioremap_resource(pdev, index)
+
+@r2 depends on !patch exists@
+expression pdev,index;
+position p;
+@@
+
+*  devm_platform_get_and_ioremap_resource@p(pdev, index, NULL)
+
+@script:python depends on org@
+p << r2.p;
+@@
+
+cocci.print_main("WARNING opportunity for devm_platform_ioremap_resource", p)
+
+@script:python depends on report@
+p << r2.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for devm_platform_ioremap_resource")
-- 
2.38.1


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

end of thread, other threads:[~2022-11-11  1:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 11:47 [cocci] [PATCH v1] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL Uwe Kleine-König
2022-11-07 12:45 ` Julia Lawall
2022-11-07 18:11   ` [cocci] [PATCH v2] " Uwe Kleine-König
2022-11-10 15:07     ` Uwe Kleine-König
2022-11-07 19:00 ` [cocci] [PATCH] " Markus Elfring
2022-11-07 20:08   ` Uwe Kleine-König
2022-11-07 21:40     ` Markus Elfring
2022-11-08  5:51     ` Julia Lawall
2022-11-08  7:55       ` Nicolas Palix
2022-11-08  9:54         ` Uwe Kleine-König
2022-11-08 12:21           ` [cocci] " Markus Elfring
2022-11-08 19:40     ` [cocci] [PATCH] " Markus Elfring
2022-11-09 18:00     ` Markus Elfring
2022-11-09 18:50 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).