diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-03-25 14:12:59 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-03-26 16:51:24 -0400 |
commit | 468db96122152fad1a23fc9024523f35140e5675 (patch) | |
tree | 7d4d9ce0f8845cc2f8dae4fda30276221b82312b /scripts/coccinelle | |
parent | 66979224c0d288331edcadb1e6ebd978d920d476 (diff) |
scripts/coccinelle/api/ptr_ret.cocci: semantic patch for ptr_err
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/coccinelle')
-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") | ||