mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource
@ 2016-08-06  5:15 Amitoj Kaur Chawla
  2016-08-06  6:30 ` SF Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Amitoj Kaur Chawla @ 2016-08-06  5:15 UTC (permalink / raw)
  To: Julia.Lawall, Gilles.Muller, nicolas.palix, mmarek, cocci, linux-kernel

This script detects cases which have incorrect error handling for
devm_ioremap_resource function, employing a NULL test instead of an
IS_ERR() test.

Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
Changes in v2:
        -Changed script to correct error handling instead of just
         detecting cases of incorrect error handling
Changes in v3:
        -Reverted to original script in v1 to ensure no error in
         modifying inconsistent paths.

 .../null/devm_ioremap_resource_test.cocci          | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 scripts/coccinelle/null/devm_ioremap_resource_test.cocci

diff --git a/scripts/coccinelle/null/devm_ioremap_resource_test.cocci b/scripts/coccinelle/null/devm_ioremap_resource_test.cocci
new file mode 100644
index 0000000..734dbd3
--- /dev/null
+++ b/scripts/coccinelle/null/devm_ioremap_resource_test.cocci
@@ -0,0 +1,38 @@
+/// Correct error handling for devm_ioremap_resource
+///
+// Confidence: High
+// Copyright: (C) 2016 Amitoj Kaur Chawla
+// Keywords: devm,devm_ioremap_resource
+
+virtual context
+virtual org
+virtual report
+
+// ----------------------------------------------------------------------------
+
+@err depends on context || org || report@
+statement S;
+expression e;
+position j0;
+@@
+
+  e = devm_ioremap_resource(...);
+* if (!e@j0) S
+// ----------------------------------------------------------------------------
+
+@script:python err_org depends on org@
+j0 << err.j0;
+@@
+
+msg = "Incorrect error handling."
+coccilib.org.print_todo(j0[0], msg)
+
+// ----------------------------------------------------------------------------
+
+@script:python err_report depends on report@
+j0 << err.j0;
+@@
+
+msg = "Incorrect error handling."
+coccilib.report.print_report(j0[0], msg)
+
-- 
1.9.1

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

* Re: [PATCH v3] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource
  2016-08-06  5:15 [PATCH v3] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource Amitoj Kaur Chawla
@ 2016-08-06  6:30 ` SF Markus Elfring
  2016-08-06  6:40   ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2016-08-06  6:30 UTC (permalink / raw)
  To: Amitoj Kaur Chawla
  Cc: LKML, Coccinelle, Gilles Muller, Julia Lawall, Michal Marek,
	Nicolas Palix

> +@err depends on context || org || report@
> +statement S;
> +expression e;
> +position j0;

How do you think about to omit the number from this variable name?


> +@@
> +
> +  e = devm_ioremap_resource(...);
> +* if (!e@j0) S

Are there any more functions to consider for such a source code search pattern?
How do you think about to use a function name list here?


> +// ----------------------------------------------------------------------------

I suggest to omit such comment lines from this SmPL script.

Regards,
Markus

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

* Re: [PATCH v3] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource
  2016-08-06  6:30 ` SF Markus Elfring
@ 2016-08-06  6:40   ` Julia Lawall
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2016-08-06  6:40 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: Amitoj Kaur Chawla, LKML, Coccinelle, Gilles Muller,
	Michal Marek, Nicolas Palix



On Sat, 6 Aug 2016, SF Markus Elfring wrote:

> > +@err depends on context || org || report@
> > +statement S;
> > +expression e;
> > +position j0;
>
> How do you think about to omit the number from this variable name?
>
>
> > +@@
> > +
> > +  e = devm_ioremap_resource(...);
> > +* if (!e@j0) S
>
> Are there any more functions to consider for such a source code search pattern?
> How do you think about to use a function name list here?

How about getting this into the kernel, and then one can worry about
adding more functions later.

>
> > +// ----------------------------------------------------------------------------
>
> I suggest to omit such comment lines from this SmPL script.

These are introduced by spgen.  Likewise for the numbers on the j
variables.  The pattern j + number can even be useful, because it shows a
position variable that introduced to manage the different kinds of output,
rather than something that is intrinsic to the computation being
performed.

julia

>
> Regards,
> Markus
>

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

end of thread, other threads:[~2016-08-06 21:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-06  5:15 [PATCH v3] Coccinelle: Script to replace NULL test with IS_ERR test for devm_ioremap_resource Amitoj Kaur Chawla
2016-08-06  6:30 ` SF Markus Elfring
2016-08-06  6:40   ` Julia Lawall

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®