blob: e18f8402e37c6df791f208d1f7f5ba244e432b8e [file] [log] [blame]
Julia Lawall468db962012-03-25 20:12:59 +02001///
Rusty Russell8c6ffba2013-07-15 11:20:32 +09302/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
Julia Lawall468db962012-03-25 20:12:59 +02003///
4// Confidence: High
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/
Nicolas Palix93f14462013-06-20 13:10:56 +02008// Options: --no-includes --include-headers
Julia Lawall468db962012-03-25 20:12:59 +02009//
Rusty Russell8c6ffba2013-07-15 11:20:32 +093010// Keywords: ERR_PTR, PTR_ERR, PTR_RET, PTR_ERR_OR_ZERO
Julia Lawall468db962012-03-25 20:12:59 +020011// Version min: 2.6.39
12//
13
14virtual context
15virtual patch
16virtual org
17virtual report
18
19@depends on patch@
20expression ptr;
21@@
22
23- if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
Rusty Russell8c6ffba2013-07-15 11:20:32 +093024+ return PTR_ERR_OR_ZERO(ptr);
Julia Lawall468db962012-03-25 20:12:59 +020025
26@depends on patch@
27expression ptr;
28@@
29
30- if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
Rusty Russell8c6ffba2013-07-15 11:20:32 +093031+ return PTR_ERR_OR_ZERO(ptr);
Julia Lawall468db962012-03-25 20:12:59 +020032
Lars-Peter Clausen30858972012-08-21 10:49:58 +020033@depends on patch@
34expression ptr;
35@@
36
37- (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
Rusty Russell8c6ffba2013-07-15 11:20:32 +093038+ PTR_ERR_OR_ZERO(ptr)
Lars-Peter Clausen30858972012-08-21 10:49:58 +020039
Julia Lawall468db962012-03-25 20:12:59 +020040@r1 depends on !patch@
41expression ptr;
42position p1;
43@@
44
45* if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
46
47@r2 depends on !patch@
48expression ptr;
49position p2;
50@@
51
52* if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
53
Lars-Peter Clausen30858972012-08-21 10:49:58 +020054@r3 depends on !patch@
55expression ptr;
56position p3;
57@@
58
59* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0
60
Julia Lawall468db962012-03-25 20:12:59 +020061@script:python depends on org@
62p << r1.p1;
63@@
64
65coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
66
67
68@script:python depends on org@
69p << r2.p2;
70@@
71
72coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
73
Lars-Peter Clausen30858972012-08-21 10:49:58 +020074@script:python depends on org@
75p << r3.p3;
76@@
77
78coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used")
79
Julia Lawall468db962012-03-25 20:12:59 +020080@script:python depends on report@
81p << r1.p1;
82@@
83
84coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")
85
86@script:python depends on report@
87p << r2.p2;
88@@
89
90coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")
Lars-Peter Clausen30858972012-08-21 10:49:58 +020091
92@script:python depends on report@
93p << r3.p3;
94@@
95
96coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used")