1///
2/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
3///
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/
8// Options: --no-includes --include-headers
9//
10// Keywords: ERR_PTR, PTR_ERR, PTR_ERR_OR_ZERO
11// 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;
24+ return PTR_ERR_OR_ZERO(ptr);
25
26@depends on patch@
27expression ptr;
28@@
29
30- if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
31+ return PTR_ERR_OR_ZERO(ptr);
32
33@depends on patch@
34expression ptr;
35@@
36
37- (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
38+ PTR_ERR_OR_ZERO(ptr)
39
40@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
54@r3 depends on !patch@
55expression ptr;
56position p3;
57@@
58
59* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0
60
61@script:python depends on org@
62p << r1.p1;
63@@
64
65coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
66
67
68@script:python depends on org@
69p << r2.p2;
70@@
71
72coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
73
74@script:python depends on org@
75p << r3.p3;
76@@
77
78coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
79
80@script:python depends on report@
81p << r1.p1;
82@@
83
84coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
85
86@script:python depends on report@
87p << r2.p2;
88@@
89
90coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
91
92@script:python depends on report@
93p << r3.p3;
94@@
95
96coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
97