diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-08-25 16:42:45 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-10-11 08:50:51 -0400 |
commit | e8fa600e066f137ef5810a2a5021530d68f34ac9 (patch) | |
tree | 818980fffa7a0b3d8b65e48f4552cafaf6f4c669 /scripts | |
parent | 22beb565d42bcf762585c477a34dcc00618e371e (diff) |
scripts/coccinelle/tests/odd_ptr_err.cocci: semantic patch for IS_ERR/PTR_ERR inconsistency
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/tests/odd_ptr_err.cocci | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts/coccinelle/tests/odd_ptr_err.cocci b/scripts/coccinelle/tests/odd_ptr_err.cocci new file mode 100644 index 000000000000..e8dd8a6b28a2 --- /dev/null +++ b/scripts/coccinelle/tests/odd_ptr_err.cocci | |||
@@ -0,0 +1,65 @@ | |||
1 | /// PTR_ERR should access the value just tested by IS_ERR | ||
2 | //# There can be false positives in the patch case, where it is the call | ||
3 | //# IS_ERR that is wrong. | ||
4 | /// | ||
5 | // Confidence: High | ||
6 | // Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2. | ||
7 | // Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2. | ||
8 | // URL: http://coccinelle.lip6.fr/ | ||
9 | // Comments: | ||
10 | // Options: -no_includes -include_headers | ||
11 | |||
12 | virtual patch | ||
13 | virtual context | ||
14 | virtual org | ||
15 | virtual report | ||
16 | |||
17 | @depends on patch@ | ||
18 | expression e,e1; | ||
19 | @@ | ||
20 | |||
21 | ( | ||
22 | if (IS_ERR(e)) { ... PTR_ERR(e) ... } | ||
23 | | | ||
24 | if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } | ||
25 | | | ||
26 | if (IS_ERR(e)) | ||
27 | { ... | ||
28 | PTR_ERR( | ||
29 | - e1 | ||
30 | + e | ||
31 | ) | ||
32 | ... } | ||
33 | ) | ||
34 | |||
35 | @r depends on !patch@ | ||
36 | expression e,e1; | ||
37 | position p1,p2; | ||
38 | @@ | ||
39 | |||
40 | ( | ||
41 | if (IS_ERR(e)) { ... PTR_ERR(e) ... } | ||
42 | | | ||
43 | if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... } | ||
44 | | | ||
45 | *if (IS_ERR@p1(e)) | ||
46 | { ... | ||
47 | * PTR_ERR@p2(e1) | ||
48 | ... } | ||
49 | ) | ||
50 | |||
51 | @script:python depends on org@ | ||
52 | p1 << r.p1; | ||
53 | p2 << r.p2; | ||
54 | @@ | ||
55 | |||
56 | cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1) | ||
57 | cocci.print_secs("PTR_ERR",p2) | ||
58 | |||
59 | @script:python depends on report@ | ||
60 | p1 << r.p1; | ||
61 | p2 << r.p2; | ||
62 | @@ | ||
63 | |||
64 | msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line) | ||
65 | coccilib.report.print_report(p1[0],msg) | ||