diff options
author | Cyril Roelandt <tipecaml@gmail.com> | 2012-12-18 17:21:28 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-18 18:02:11 -0500 |
commit | af56e3f017bae54b9c3b5f7877d5eff990a2eed9 (patch) | |
tree | aefe2e189094966dd1522b99dc57f08ab23017d1 /scripts/coccinelle/api | |
parent | 19af395d7c0daaafdebd441a162128aaac575912 (diff) |
Coccinelle: add api/d_find_alias.cocci
Ensure that calls to d_find_alias() have a corresponding dput().
Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>
Cc: Nicolas Palix <nicolas.palix@imag.fr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/coccinelle/api')
-rw-r--r-- | scripts/coccinelle/api/d_find_alias.cocci | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/d_find_alias.cocci b/scripts/coccinelle/api/d_find_alias.cocci new file mode 100644 index 000000000000..a9694a8d3e5a --- /dev/null +++ b/scripts/coccinelle/api/d_find_alias.cocci | |||
@@ -0,0 +1,80 @@ | |||
1 | /// Make sure calls to d_find_alias() have a corresponding call to dput(). | ||
2 | // | ||
3 | // Keywords: d_find_alias, dput | ||
4 | // | ||
5 | // Confidence: Moderate | ||
6 | // URL: http://coccinelle.lip6.fr/ | ||
7 | // Options: -include_headers | ||
8 | |||
9 | virtual context | ||
10 | virtual org | ||
11 | virtual patch | ||
12 | virtual report | ||
13 | |||
14 | @r exists@ | ||
15 | local idexpression struct dentry *dent; | ||
16 | expression E, E1; | ||
17 | statement S1, S2; | ||
18 | position p1, p2; | ||
19 | @@ | ||
20 | ( | ||
21 | if (!(dent@p1 = d_find_alias(...))) S1 | ||
22 | | | ||
23 | dent@p1 = d_find_alias(...) | ||
24 | ) | ||
25 | |||
26 | <...when != dput(dent) | ||
27 | when != if (...) { <+... dput(dent) ...+> } | ||
28 | when != true !dent || ... | ||
29 | when != dent = E | ||
30 | when != E = dent | ||
31 | if (!dent || ...) S2 | ||
32 | ...> | ||
33 | ( | ||
34 | return <+...dent...+>; | ||
35 | | | ||
36 | return @p2 ...; | ||
37 | | | ||
38 | dent@p2 = E1; | ||
39 | | | ||
40 | E1 = dent; | ||
41 | ) | ||
42 | |||
43 | @depends on context@ | ||
44 | local idexpression struct dentry *r.dent; | ||
45 | position r.p1,r.p2; | ||
46 | @@ | ||
47 | * dent@p1 = ... | ||
48 | ... | ||
49 | ( | ||
50 | * return@p2 ...; | ||
51 | | | ||
52 | * dent@p2 | ||
53 | ) | ||
54 | |||
55 | |||
56 | @script:python depends on org@ | ||
57 | p1 << r.p1; | ||
58 | p2 << r.p2; | ||
59 | @@ | ||
60 | cocci.print_main("Missing call to dput()",p1) | ||
61 | cocci.print_secs("",p2) | ||
62 | |||
63 | @depends on patch@ | ||
64 | local idexpression struct dentry *r.dent; | ||
65 | position r.p2; | ||
66 | @@ | ||
67 | ( | ||
68 | + dput(dent); | ||
69 | return @p2 ...; | ||
70 | | | ||
71 | + dput(dent); | ||
72 | dent@p2 = ...; | ||
73 | ) | ||
74 | |||
75 | @script:python depends on report@ | ||
76 | p1 << r.p1; | ||
77 | p2 << r.p2; | ||
78 | @@ | ||
79 | msg = "Missing call to dput() at line %s." | ||
80 | coccilib.report.print_report(p1[0], msg % (p2[0].line)) | ||