diff options
-rw-r--r-- | scripts/coccinelle/api/ptr_ret.cocci | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci new file mode 100644 index 000000000000..cbfd08c7d8c7 --- /dev/null +++ b/scripts/coccinelle/api/ptr_ret.cocci | |||
@@ -0,0 +1,70 @@ | |||
1 | /// | ||
2 | /// Use PTR_RET 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_RET | ||
11 | // Version min: 2.6.39 | ||
12 | // | ||
13 | |||
14 | virtual context | ||
15 | virtual patch | ||
16 | virtual org | ||
17 | virtual report | ||
18 | |||
19 | @depends on patch@ | ||
20 | expression ptr; | ||
21 | @@ | ||
22 | |||
23 | - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; | ||
24 | + return PTR_RET(ptr); | ||
25 | |||
26 | @depends on patch@ | ||
27 | expression ptr; | ||
28 | @@ | ||
29 | |||
30 | - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; | ||
31 | + return PTR_RET(ptr); | ||
32 | |||
33 | @r1 depends on !patch@ | ||
34 | expression ptr; | ||
35 | position p1; | ||
36 | @@ | ||
37 | |||
38 | * if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; | ||
39 | |||
40 | @r2 depends on !patch@ | ||
41 | expression ptr; | ||
42 | position p2; | ||
43 | @@ | ||
44 | |||
45 | * if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; | ||
46 | |||
47 | @script:python depends on org@ | ||
48 | p << r1.p1; | ||
49 | @@ | ||
50 | |||
51 | coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used") | ||
52 | |||
53 | |||
54 | @script:python depends on org@ | ||
55 | p << r2.p2; | ||
56 | @@ | ||
57 | |||
58 | coccilib.org.print_todo(p[0], "WARNING: PTR_RET can be used") | ||
59 | |||
60 | @script:python depends on report@ | ||
61 | p << r1.p1; | ||
62 | @@ | ||
63 | |||
64 | coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used") | ||
65 | |||
66 | @script:python depends on report@ | ||
67 | p << r2.p2; | ||
68 | @@ | ||
69 | |||
70 | coccilib.report.print_report(p[0], "WARNING: PTR_RET can be used") | ||