diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-04-05 17:25:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-05 18:25:50 -0400 |
commit | 9b3ae64be658a573b33d05a8dc73b08d3345fa44 (patch) | |
tree | 233faed7d0210858ac940385548665b4a8644be6 | |
parent | 20955e891d828b2027281fe3295dae6af8e0423b (diff) |
scripts/coccinelle/api/simple_open.cocci: semantic patch for simple_open()
Find instances of an open-coded simple_open() and replace them with
calls to simple_open().
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Reported-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | scripts/coccinelle/api/simple_open.cocci | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/simple_open.cocci b/scripts/coccinelle/api/simple_open.cocci new file mode 100644 index 000000000000..05962f7be155 --- /dev/null +++ b/scripts/coccinelle/api/simple_open.cocci | |||
@@ -0,0 +1,70 @@ | |||
1 | /// This removes an open coded simple_open() function | ||
2 | /// and replaces file operations references to the function | ||
3 | /// with simple_open() instead. | ||
4 | /// | ||
5 | // Confidence: High | ||
6 | // Comments: | ||
7 | // Options: -no_includes -include_headers | ||
8 | |||
9 | virtual patch | ||
10 | virtual report | ||
11 | |||
12 | @ open depends on patch @ | ||
13 | identifier open_f != simple_open; | ||
14 | identifier i, f; | ||
15 | @@ | ||
16 | -int open_f(struct inode *i, struct file *f) | ||
17 | -{ | ||
18 | ( | ||
19 | -if (i->i_private) | ||
20 | -f->private_data = i->i_private; | ||
21 | | | ||
22 | -f->private_data = i->i_private; | ||
23 | ) | ||
24 | -return 0; | ||
25 | -} | ||
26 | |||
27 | @ has_open depends on open @ | ||
28 | identifier fops; | ||
29 | identifier open.open_f; | ||
30 | @@ | ||
31 | struct file_operations fops = { | ||
32 | ..., | ||
33 | -.open = open_f, | ||
34 | +.open = simple_open, | ||
35 | ... | ||
36 | }; | ||
37 | |||
38 | @ openr depends on report @ | ||
39 | identifier open_f != simple_open; | ||
40 | identifier i, f; | ||
41 | position p; | ||
42 | @@ | ||
43 | int open_f@p(struct inode *i, struct file *f) | ||
44 | { | ||
45 | ( | ||
46 | if (i->i_private) | ||
47 | f->private_data = i->i_private; | ||
48 | | | ||
49 | f->private_data = i->i_private; | ||
50 | ) | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | @ has_openr depends on openr @ | ||
55 | identifier fops; | ||
56 | identifier openr.open_f; | ||
57 | position p; | ||
58 | @@ | ||
59 | struct file_operations fops = { | ||
60 | ..., | ||
61 | .open = open_f@p, | ||
62 | ... | ||
63 | }; | ||
64 | |||
65 | @script:python@ | ||
66 | pf << openr.p; | ||
67 | ps << has_openr.p; | ||
68 | @@ | ||
69 | |||
70 | coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line)) | ||