Skip to content

Commit

Permalink
coccinelle: Add script to check for platform_get_irq() excessive prints
Browse files Browse the repository at this point in the history
Add a coccinelle script to check for the usage of dev_err() after a call
to platform_get_irq{,_byname}() as it's redundant now that the function
already prints an error when it fails.

Cc: Greg Kroah-Hartman <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Javier Martinez Canillas <[email protected]>
Cc: Andrzej Hajda <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Russell King - ARM Linux <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Markus Elfring <[email protected]>
Signed-off-by: Stephen Boyd <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
bebarino authored and gregkh committed Jul 30, 2019
1 parent 7723f4c commit 98051ba
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions scripts/coccinelle/api/platform_get_irq.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: GPL-2.0
/// Remove dev_err() messages after platform_get_irq*() failures
//
// Confidence: Medium
// Options: --include-headers

virtual patch
virtual context
virtual org
virtual report

@depends on context@
expression ret;
struct platform_device *E;
@@

ret =
(
platform_get_irq
|
platform_get_irq_byname
)(E, ...);

if ( ret \( < \| <= \) 0 )
{
(
if (ret != -EPROBE_DEFER)
{ ...
*dev_err(...);
... }
|
...
*dev_err(...);
)
...
}

@depends on patch@
expression ret;
struct platform_device *E;
@@

ret =
(
platform_get_irq
|
platform_get_irq_byname
)(E, ...);

if ( ret \( < \| <= \) 0 )
{
(
-if (ret != -EPROBE_DEFER)
-{ ...
-dev_err(...);
-... }
|
...
-dev_err(...);
)
...
}

@r depends on org || report@
position p1;
expression ret;
struct platform_device *E;
@@

ret =
(
platform_get_irq
|
platform_get_irq_byname
)(E, ...);

if ( ret \( < \| <= \) 0 )
{
(
if (ret != -EPROBE_DEFER)
{ ...
dev_err@p1(...);
... }
|
...
dev_err@p1(...);
)
...
}

@script:python depends on org@
p1 << r.p1;
@@
cocci.print_main(p1)
@script:python depends on report@
p1 << r.p1;
@@
msg = "line %s is redundant because platform_get_irq() already prints an error" % (p1[0].line)
coccilib.report.print_report(p1[0],msg)

0 comments on commit 98051ba

Please sign in to comment.