Commit 02da7b42 authored by Julia Lawall's avatar Julia Lawall Committed by Michal Marek

coccinelle: tests: improve odd_ptr_err.cocci

The original version only considered the case where the then branch
contains only one call to PTR_ERR.  Reimplement the whole thing to allow
multiple calls, with potentially different arguments.
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
parent 74a8478f
/// PTR_ERR should access the value just tested by IS_ERR /// PTR_ERR should access the value just tested by IS_ERR
//# There can be false positives in the patch case, where it is the call //# There can be false positives in the patch case, where it is the call to
//# IS_ERR that is wrong. //# IS_ERR that is wrong.
/// ///
// Confidence: High // Confidence: High
// Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2. // Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2.
// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2. // Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2.
// URL: http://coccinelle.lip6.fr/ // URL: http://coccinelle.lip6.fr/
// Comments:
// Options: --no-includes --include-headers // Options: --no-includes --include-headers
virtual patch virtual patch
...@@ -14,52 +13,105 @@ virtual context ...@@ -14,52 +13,105 @@ virtual context
virtual org virtual org
virtual report virtual report
@depends on patch@ @ok1 exists@
expression e,e1; expression x,e;
position p;
@@ @@
if (IS_ERR(x=e) || ...) {
<...
PTR_ERR@p(x)
...>
}
@ok2 exists@
expression x,e1,e2;
position p;
@@
if (IS_ERR(x) || ...) {
<...
( (
if (IS_ERR(e)) { ... PTR_ERR(e) ... } PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
| |
if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } PTR_ERR@p(x)
)
...>
}
@r1 depends on patch && !context && !org && !report exists@
expression x,y;
position p != {ok1.p,ok2.p};
@@
if (IS_ERR(x) || ...) {
... when any
when != IS_ERR(...)
(
PTR_ERR(x)
| |
if (IS_ERR(e)) PTR_ERR@p(
{ ... - y
PTR_ERR( + x
- e1
+ e
) )
... }
) )
... when any
}
// ----------------------------------------------------------------------------
@r depends on !patch@ @r1_context depends on !patch && (context || org || report) exists@
expression e,e1; position p != {ok1.p,ok2.p};
position p1,p2; expression x, y;
position j0, j1;
@@ @@
if (IS_ERR@j0(x) || ...) {
... when any
when != IS_ERR(...)
( (
if (IS_ERR(e)) { ... PTR_ERR(e) ... } PTR_ERR(x)
| |
if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } PTR_ERR@j1@p(
| y
*if (IS_ERR@p1(e)) )
{ ...
* PTR_ERR@p2(e1)
... }
) )
... when any
}
@script:python depends on org@ @r1_disj depends on !patch && (context || org || report) exists@
p1 << r.p1; position p != {ok1.p,ok2.p};
p2 << r.p2; expression x, y;
position r1_context.j0, r1_context.j1;
@@ @@
cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1) * if (IS_ERR@j0(x) || ...) {
cocci.print_secs("PTR_ERR",p2) ... when any
when != IS_ERR(...)
* PTR_ERR@j1@p(
y
)
... when any
}
@script:python depends on report@ // ----------------------------------------------------------------------------
p1 << r.p1;
p2 << r.p2; @script:python r1_org depends on org@
j0 << r1_context.j0;
j1 << r1_context.j1;
@@ @@
msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line) msg = "inconsistent IS_ERR and PTR_ERR"
coccilib.report.print_report(p1[0],msg) coccilib.org.print_todo(j0[0], msg)
coccilib.org.print_link(j1[0], "")
// ----------------------------------------------------------------------------
@script:python r1_report depends on report@
j0 << r1_context.j0;
j1 << r1_context.j1;
@@
msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line)
coccilib.report.print_report(j0[0], msg)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment