diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2015-08-30 16:18:14 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2015-10-26 15:54:28 -0400 |
commit | 02da7b42777c159c6897e233e6c53d5581c07dab (patch) | |
tree | 98b1f5efbc65442f5c517cb022e5abd9f2478cdb | |
parent | 74a8478f9ea2b3e70640a64db8acd54d4225a2c4 (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.cocci | 120 |
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 | ||
12 | virtual patch | 11 | virtual patch |
@@ -14,52 +13,105 @@ virtual context | |||
14 | virtual org | 13 | virtual org |
15 | virtual report | 14 | virtual report |
16 | 15 | ||
17 | @depends on patch@ | 16 | @ok1 exists@ |
18 | expression e,e1; | 17 | expression x,e; |
18 | position p; | ||
19 | @@ | 19 | @@ |
20 | 20 | ||
21 | if (IS_ERR(x=e) || ...) { | ||
22 | <... | ||
23 | PTR_ERR@p(x) | ||
24 | ...> | ||
25 | } | ||
26 | |||
27 | @ok2 exists@ | ||
28 | expression x,e1,e2; | ||
29 | position p; | ||
30 | @@ | ||
31 | |||
32 | if (IS_ERR(x) || ...) { | ||
33 | <... | ||
21 | ( | 34 | ( |
22 | if (IS_ERR(e)) { ... PTR_ERR(e) ... } | 35 | PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\)) |
23 | | | 36 | | |
24 | if (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@ | ||
43 | expression x,y; | ||
44 | position p != {ok1.p,ok2.p}; | ||
45 | @@ | ||
46 | |||
47 | if (IS_ERR(x) || ...) { | ||
48 | ... when any | ||
49 | when != IS_ERR(...) | ||
50 | ( | ||
51 | PTR_ERR(x) | ||
25 | | | 52 | | |
26 | if (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@ |
36 | expression e,e1; | 64 | position p != {ok1.p,ok2.p}; |
37 | position p1,p2; | 65 | expression x, y; |
66 | position j0, j1; | ||
38 | @@ | 67 | @@ |
39 | 68 | ||
69 | if (IS_ERR@j0(x) || ...) { | ||
70 | ... when any | ||
71 | when != IS_ERR(...) | ||
40 | ( | 72 | ( |
41 | if (IS_ERR(e)) { ... PTR_ERR(e) ... } | 73 | PTR_ERR(x) |
42 | | | 74 | | |
43 | if (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@ |
52 | p1 << r.p1; | 83 | position p != {ok1.p,ok2.p}; |
53 | p2 << r.p2; | 84 | expression x, y; |
85 | position r1_context.j0, r1_context.j1; | ||
54 | @@ | 86 | @@ |
55 | 87 | ||
56 | cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1) | 88 | * if (IS_ERR@j0(x) || ...) { |
57 | cocci.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 | // ---------------------------------------------------------------------------- |
60 | p1 << r.p1; | 98 | |
61 | p2 << r.p2; | 99 | @script:python r1_org depends on org@ |
100 | j0 << r1_context.j0; | ||
101 | j1 << r1_context.j1; | ||
62 | @@ | 102 | @@ |
63 | 103 | ||
64 | msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line) | 104 | msg = "inconsistent IS_ERR and PTR_ERR" |
65 | coccilib.report.print_report(p1[0],msg) | 105 | coccilib.org.print_todo(j0[0], msg) |
106 | coccilib.org.print_link(j1[0], "") | ||
107 | |||
108 | // ---------------------------------------------------------------------------- | ||
109 | |||
110 | @script:python r1_report depends on report@ | ||
111 | j0 << r1_context.j0; | ||
112 | j1 << r1_context.j1; | ||
113 | @@ | ||
114 | |||
115 | msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line) | ||
116 | coccilib.report.print_report(j0[0], msg) | ||
117 | |||