aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2015-08-30 16:18:14 -0400
committerMichal Marek <mmarek@suse.cz>2015-10-26 15:54:28 -0400
commit02da7b42777c159c6897e233e6c53d5581c07dab (patch)
tree98b1f5efbc65442f5c517cb022e5abd9f2478cdb
parent74a8478f9ea2b3e70640a64db8acd54d4225a2c4 (diff)
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: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Michal Marek <mmarek@suse.cz>
-rw-r--r--scripts/coccinelle/tests/odd_ptr_err.cocci120
1 files changed, 86 insertions, 34 deletions
diff --git a/scripts/coccinelle/tests/odd_ptr_err.cocci b/scripts/coccinelle/tests/odd_ptr_err.cocci
index cfe0a35cf2dd..dfc6b40c2969 100644
--- a/scripts/coccinelle/tests/odd_ptr_err.cocci
+++ b/scripts/coccinelle/tests/odd_ptr_err.cocci
@@ -1,12 +1,11 @@
1/// PTR_ERR should access the value just tested by IS_ERR 1/// PTR_ERR should access the value just tested by IS_ERR
2//# There can be false positives in the patch case, where it is the call 2//# There can be false positives in the patch case, where it is the call to
3//# IS_ERR that is wrong. 3//# IS_ERR that is wrong.
4/// 4///
5// Confidence: High 5// Confidence: High
6// Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2. 6// Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2. 7// Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments:
10// Options: --no-includes --include-headers 9// Options: --no-includes --include-headers
11 10
12virtual patch 11virtual patch
@@ -14,52 +13,105 @@ virtual context
14virtual org 13virtual org
15virtual report 14virtual report
16 15
17@depends on patch@ 16@ok1 exists@
18expression e,e1; 17expression x,e;
18position p;
19@@ 19@@
20 20
21if (IS_ERR(x=e) || ...) {
22 <...
23 PTR_ERR@p(x)
24 ...>
25}
26
27@ok2 exists@
28expression x,e1,e2;
29position p;
30@@
31
32if (IS_ERR(x) || ...) {
33 <...
21( 34(
22if (IS_ERR(e)) { ... PTR_ERR(e) ... } 35 PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
23| 36|
24if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } 37 PTR_ERR@p(x)
38)
39 ...>
40}
41
42@r1 depends on patch && !context && !org && !report exists@
43expression x,y;
44position p != {ok1.p,ok2.p};
45@@
46
47if (IS_ERR(x) || ...) {
48 ... when any
49 when != IS_ERR(...)
50(
51 PTR_ERR(x)
25| 52|
26if (IS_ERR(e)) 53 PTR_ERR@p(
27 { ... 54- y
28 PTR_ERR( 55+ x
29- e1
30+ e
31 ) 56 )
32 ... }
33) 57)
58 ... when any
59}
60
61// ----------------------------------------------------------------------------
34 62
35@r depends on !patch@ 63@r1_context depends on !patch && (context || org || report) exists@
36expression e,e1; 64position p != {ok1.p,ok2.p};
37position p1,p2; 65expression x, y;
66position j0, j1;
38@@ 67@@
39 68
69if (IS_ERR@j0(x) || ...) {
70 ... when any
71 when != IS_ERR(...)
40( 72(
41if (IS_ERR(e)) { ... PTR_ERR(e) ... } 73 PTR_ERR(x)
42| 74|
43if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } 75 PTR_ERR@j1@p(
44| 76 y
45*if (IS_ERR@p1(e)) 77 )
46 { ...
47* PTR_ERR@p2(e1)
48 ... }
49) 78)
79 ... when any
80}
50 81
51@script:python depends on org@ 82@r1_disj depends on !patch && (context || org || report) exists@
52p1 << r.p1; 83position p != {ok1.p,ok2.p};
53p2 << r.p2; 84expression x, y;
85position r1_context.j0, r1_context.j1;
54@@ 86@@
55 87
56cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1) 88* if (IS_ERR@j0(x) || ...) {
57cocci.print_secs("PTR_ERR",p2) 89 ... when any
90 when != IS_ERR(...)
91* PTR_ERR@j1@p(
92 y
93 )
94 ... when any
95}
58 96
59@script:python depends on report@ 97// ----------------------------------------------------------------------------
60p1 << r.p1; 98
61p2 << r.p2; 99@script:python r1_org depends on org@
100j0 << r1_context.j0;
101j1 << r1_context.j1;
62@@ 102@@
63 103
64msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line) 104msg = "inconsistent IS_ERR and PTR_ERR"
65coccilib.report.print_report(p1[0],msg) 105coccilib.org.print_todo(j0[0], msg)
106coccilib.org.print_link(j1[0], "")
107
108// ----------------------------------------------------------------------------
109
110@script:python r1_report depends on report@
111j0 << r1_context.j0;
112j1 << r1_context.j1;
113@@
114
115msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line)
116coccilib.report.print_report(j0[0], msg)
117