These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / scripts / coccinelle / tests / odd_ptr_err.cocci
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 to
3 //# IS_ERR that is wrong.
4 ///
5 // Confidence: High
6 // Copyright: (C) 2012, 2015 Julia Lawall, INRIA.  GPLv2.
7 // Copyright: (C) 2012, 2015 Gilles Muller, INRIA.  GPLv2.
8 // URL: http://coccinelle.lip6.fr/
9 // Options: --no-includes --include-headers
10
11 virtual patch
12 virtual context
13 virtual org
14 virtual report
15
16 @ok1 exists@
17 expression x,e;
18 position p;
19 @@
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   <...
34 (
35    PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
36 |
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)
52 |
53   PTR_ERR@p(
54 -     y
55 +     x
56   )
57 )
58   ... when any
59 }
60
61 // ----------------------------------------------------------------------------
62
63 @r1_context depends on !patch && (context || org || report) exists@
64 position p != {ok1.p,ok2.p};
65 expression x, y;
66 position j0, j1;
67 @@
68
69 if (IS_ERR@j0(x) || ...) {
70   ... when any
71       when != IS_ERR(...)
72 (
73   PTR_ERR(x)
74 |
75   PTR_ERR@j1@p(
76      y
77   )
78 )
79   ... when any
80 }
81
82 @r1_disj depends on !patch && (context || org || report) exists@
83 position p != {ok1.p,ok2.p};
84 expression x, y;
85 position r1_context.j0, r1_context.j1;
86 @@
87
88 * if (IS_ERR@j0(x) || ...) {
89   ... when any
90       when != IS_ERR(...)
91 *   PTR_ERR@j1@p(
92      y
93   )
94   ... when any
95 }
96
97 // ----------------------------------------------------------------------------
98
99 @script:python r1_org depends on org@
100 j0 << r1_context.j0;
101 j1 << r1_context.j1;
102 @@
103
104 msg = "inconsistent IS_ERR and PTR_ERR"
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