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
11virtual patch
12virtual context
13virtual org
14virtual report
15
16@ok1 exists@
17expression x,e;
18position p;
19@@
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  <...
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@
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)
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@
64position p != {ok1.p,ok2.p};
65expression x, y;
66position j0, j1;
67@@
68
69if (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@
83position p != {ok1.p,ok2.p};
84expression x, y;
85position 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@
100j0 << r1_context.j0;
101j1 << r1_context.j1;
102@@
103
104msg = "inconsistent IS_ERR and PTR_ERR"
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
118