Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH] Coccinelle: api: Add SmPL script “use_platform_get_irq.cocci”
@ 2020-09-23 17:00 Markus Elfring
  0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2020-09-23 17:00 UTC (permalink / raw)
  To: Coccinelle, Gilles Muller, Julia Lawall, Masahiro Yamada,
	Michal Marek, Nicolas Palix, Stephen Boyd, kernel-janitors
  Cc: Rob Herring, Bartlomiej Zolnierkiewicz, Rafael J. Wysocki,
	Javier Martinez Canillas, LKML, Andrzej Hajda, Andy Shevchenko,
	Mark Brown, Russell King, Marek Szyprowski

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 17:00 [Cocci] [PATCH] Coccinelle: api: Add SmPL script “use_platform_get_irq.cocci” Markus Elfring

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