blob: dfc6b40c29698417c32c9c50eb22ad1b5c81044d [file] [log] [blame]
Julia Lawalle8fa6002012-08-25 22:42:45 +02001/// PTR_ERR should access the value just tested by IS_ERR
Julia Lawall02da7b42015-08-30 22:18:14 +02002//# There can be false positives in the patch case, where it is the call to
Julia Lawalle8fa6002012-08-25 22:42:45 +02003//# IS_ERR that is wrong.
4///
5// Confidence: High
Julia Lawall02da7b42015-08-30 22:18:14 +02006// Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2.
7// Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2.
Julia Lawalle8fa6002012-08-25 22:42:45 +02008// URL: http://coccinelle.lip6.fr/
Nicolas Palix93f14462013-06-20 13:10:56 +02009// Options: --no-includes --include-headers
Julia Lawalle8fa6002012-08-25 22:42:45 +020010
11virtual patch
12virtual context
13virtual org
14virtual report
15
Julia Lawall02da7b42015-08-30 22:18:14 +020016@ok1 exists@
17expression x,e;
18position p;
Julia Lawalle8fa6002012-08-25 22:42:45 +020019@@
20
Julia Lawall02da7b42015-08-30 22:18:14 +020021if (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 <...
Julia Lawalle8fa6002012-08-25 22:42:45 +020034(
Julia Lawall02da7b42015-08-30 22:18:14 +020035 PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
Julia Lawalle8fa6002012-08-25 22:42:45 +020036|
Julia Lawall02da7b42015-08-30 22:18:14 +020037 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)
Julia Lawalle8fa6002012-08-25 22:42:45 +020052|
Julia Lawall02da7b42015-08-30 22:18:14 +020053 PTR_ERR@p(
54- y
55+ x
Julia Lawalle8fa6002012-08-25 22:42:45 +020056 )
Julia Lawalle8fa6002012-08-25 22:42:45 +020057)
Julia Lawall02da7b42015-08-30 22:18:14 +020058 ... when any
59}
Julia Lawalle8fa6002012-08-25 22:42:45 +020060
Julia Lawall02da7b42015-08-30 22:18:14 +020061// ----------------------------------------------------------------------------
62
63@r1_context depends on !patch && (context || org || report) exists@
64position p != {ok1.p,ok2.p};
65expression x, y;
66position j0, j1;
Julia Lawalle8fa6002012-08-25 22:42:45 +020067@@
68
Julia Lawall02da7b42015-08-30 22:18:14 +020069if (IS_ERR@j0(x) || ...) {
70 ... when any
71 when != IS_ERR(...)
Julia Lawalle8fa6002012-08-25 22:42:45 +020072(
Julia Lawall02da7b42015-08-30 22:18:14 +020073 PTR_ERR(x)
Julia Lawalle8fa6002012-08-25 22:42:45 +020074|
Julia Lawall02da7b42015-08-30 22:18:14 +020075 PTR_ERR@j1@p(
76 y
77 )
Julia Lawalle8fa6002012-08-25 22:42:45 +020078)
Julia Lawall02da7b42015-08-30 22:18:14 +020079 ... when any
80}
Julia Lawalle8fa6002012-08-25 22:42:45 +020081
Julia Lawall02da7b42015-08-30 22:18:14 +020082@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;
Julia Lawalle8fa6002012-08-25 22:42:45 +020086@@
87
Julia Lawall02da7b42015-08-30 22:18:14 +020088* if (IS_ERR@j0(x) || ...) {
89 ... when any
90 when != IS_ERR(...)
91* PTR_ERR@j1@p(
92 y
93 )
94 ... when any
95}
Julia Lawalle8fa6002012-08-25 22:42:45 +020096
Julia Lawall02da7b42015-08-30 22:18:14 +020097// ----------------------------------------------------------------------------
98
99@script:python r1_org depends on org@
100j0 << r1_context.j0;
101j1 << r1_context.j1;
Julia Lawalle8fa6002012-08-25 22:42:45 +0200102@@
103
Julia Lawall02da7b42015-08-30 22:18:14 +0200104msg = "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