mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: kernel@pengutronix.de, Nicolas Palix <nicolas.palix@imag.fr>,
	linux-kernel@vger.kernel.org, cocci@inria.fr
Subject: [PATCH v2] coccinelle: api: Don't use devm_platform_get_and_ioremap_resource with res==NULL
Date: Mon, 7 Nov 2022 19:11:35 +0100	[thread overview]
Message-ID: <20221107181135.tm2wmwiulepsyrmk@pengutronix.de> (raw)
In-Reply-To: <28e17fb9-cec1-4a89-1492-cd3ece7a9487@inria.fr>

[-- Attachment #1: Type: text/plain, Size: 3637 bytes --]

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>
---
On Mon, Nov 07, 2022 at 08:45:38PM +0800, Julia Lawall wrote:
> On Mon, 7 Nov 2022, Uwe Kleine-König wrote:
> 
> > 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.
> 
> ... when != res
> 
> I'm not sure where you wanted to put it though.

I tinkered a bit further and even succeeded to remove the declaration if
it's otherwise unused.

I failed to test the report mode, my spatch tells me some error about
python2?!

Best regards
Uwe

 .../api/devm_platform_ioremap_resource.cocci  | 85 +++++++++++++++++++
 1 file changed, 85 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..485dfa6ea0aa
--- /dev/null
+++ b/scripts/coccinelle/api/devm_platform_ioremap_resource.cocci
@@ -0,0 +1,85 @@
+// 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)
+
+@depends on patch@
+expression pdev,index;
+identifier res;
+type T;
+@@
+-  T res;
+   ... when != res
+-  devm_platform_get_and_ioremap_resource(pdev, index, &res)
++  devm_platform_ioremap_resource(pdev, index)
+   ... when != res
+
+@depends on patch@
+expression pdev,index;
+identifier res;
+@@
+
+-  devm_platform_get_and_ioremap_resource(pdev, index, &res)
++  devm_platform_ioremap_resource(pdev, index)
+   ... when != res
+
+@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")
+
+@r3 depends on !patch exists@
+expression pdev,index;
+identifier res;
+position p;
+@@
+
+*  devm_platform_get_and_ioremap_resource@p(pdev, index, &res)
+   ... when != res
+
+@script:python depends on org@
+p << r3.p;
+@@
+
+cocci.print_main("WARNING opportunity for devm_platform_ioremap_resource", p)
+
+@script:python depends on report@
+p << r3.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for devm_platform_ioremap_resource")
-- 
2.38.1


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-11-07 18:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 11:47 [PATCH v1] " Uwe Kleine-König
2022-11-07 12:45 ` Julia Lawall
2022-11-07 18:11   ` Uwe Kleine-König [this message]
2022-11-10 15:07     ` [PATCH v2] " Uwe Kleine-König
     [not found] ` <bd13da2d-6d18-4f33-0987-a193e3c9b761@web.de>
2022-11-07 20:08   ` [cocci] [PATCH] " Uwe Kleine-König
2022-11-08  5:51     ` Julia Lawall
2022-11-08  7:55       ` Nicolas Palix
2022-11-08  9:54         ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107181135.tm2wmwiulepsyrmk@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.fr \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.palix@imag.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®