Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Coccinelle <cocci@systeme.lip6.fr>,
	Gilles Muller <Gilles.Muller@lip6.fr>,
	Julia Lawall <Julia.Lawall@lip6.fr>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Stephen Boyd <swboyd@chromium.org>,
	kernel-janitors@vger.kernel.org
Cc: Rob Herring <robh@kernel.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Javier Martinez Canillas <javierm@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: [Cocci] [PATCH] Coccinelle: api: Add SmPL script “use_platform_get_irq.cocci”
Date: Wed, 23 Sep 2020 19:00:16 +0200
Message-ID: <dbb7be9c-788e-c5bd-b4b2-d709e3bd5e8b@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 23 Sep 2020 18:30:25 +0200

A wrapper function is available since the commit 7723f4c5ecdb8d832f049f8483beb0d1081cedf6
("driver core: platform: Add an error message to platform_get_irq*()").
Provide design options for the adjustment of affected source code
by the means of the semantic patch language (Coccinelle software).

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 .../coccinelle/api/use_platform_get_irq.cocci | 107 ++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 scripts/coccinelle/api/use_platform_get_irq.cocci

diff --git a/scripts/coccinelle/api/use_platform_get_irq.cocci b/scripts/coccinelle/api/use_platform_get_irq.cocci
new file mode 100644
index 000000000000..0a0b27a3cd1a
--- /dev/null
+++ b/scripts/coccinelle/api/use_platform_get_irq.cocci
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Simplify a function call combination by using a known wrapper function.
+//
+// Keywords: wrapper function conversion IRQ resources
+// Confidence: High
+// Options: --no-includes --include-headers
+
+virtual context, patch, report, org
+
+@depends on context@
+expression device, error_code, index, irq, resource, x;
+identifier ri;
+type t;
+@@
+(
+*resource = platform_get_resource(device, IORESOURCE_IRQ, index);
+*if (resource == NULL)
+*{
+*   dev_err(&device->dev, ...);
+*   return error_code;
+*}
+ irq =
+*      resource->start
+ ;
+|
+*t ri = platform_get_resource(device, IORESOURCE_IRQ, index);
+ ... when != ri
+     when != device = x
+*if (ri == NULL)
+*{
+*   dev_err(&device->dev, ...);
+*   return error_code;
+*}
+ irq =
+*      ri->start
+ ;
+)
+
+@depends on patch@
+expression device, error_code, index, irq, resource, x;
+identifier ri;
+type t;
+@@
+(
+-resource = platform_get_resource(device, IORESOURCE_IRQ, index);
+-if (resource == NULL)
+-{
+-   dev_err(&device->dev, ...);
+-   return error_code;
+-}
+ irq =
+-      resource->start
++      platform_get_irq(device, index)
+ ;
++if (irq < 0)
++   return irq;
+|
+-t ri = platform_get_resource(device, IORESOURCE_IRQ, index);
+ ... when != ri
+     when != device = x
+-if (ri == NULL)
+-{
+-   dev_err(&device->dev, ...);
+-   return error_code;
+-}
+ irq =
+-      ri->start
++      platform_get_irq(device, index)
+ ;
++if (irq < 0)
++   return irq;
+)
+
+@or depends on org || report@
+expression device, error_code, index, irq, resource, x;
+identifier ri;
+position p;
+type t;
+@@
+(resource = platform_get_resource(device, IORESOURCE_IRQ, index);
+ if (resource == NULL)
+ {
+    dev_err(&device->dev, ...);
+    return error_code;
+ }
+ irq = resource->start@p;
+|
+ t ri = platform_get_resource(device, IORESOURCE_IRQ, index);
+ ... when != ri
+     when != device = x
+ if (ri == NULL)
+ {
+    dev_err(&device->dev, ...);
+    return error_code;
+ }
+ irq = ri->start@p;
+)
+
+@script:python depends on org@
+p << or.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: opportunity for platform_get_irq()")
+
+@script:python depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0], "WARNING: opportunity for platform_get_irq()")
--
2.28.0

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=dbb7be9c-788e-c5bd-b4b2-d709e3bd5e8b@web.de \
    --to=markus.elfring@web.de \
    --cc=Gilles.Muller@lip6.fr \
    --cc=Julia.Lawall@lip6.fr \
    --cc=a.hajda@samsung.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=broonie@kernel.org \
    --cc=cocci@systeme.lip6.fr \
    --cc=javierm@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=masahiroy@kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=nicolas.palix@imag.fr \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robh@kernel.org \
    --cc=swboyd@chromium.org \
    /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

Coccinelle Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git