GNU Linux-libre 4.14.290-gnu1
[releases.git] / scripts / coccinelle / api / simple_open.cocci
1 // SPDX-License-Identifier: GPL-2.0
2 /// Remove an open coded simple_open() function
3 /// and replace file operations references to the function
4 /// with simple_open() instead.
5 ///
6 // Confidence: High
7 // Comments:
8 // Options: --no-includes --include-headers
9
10 virtual patch
11 virtual report
12
13 @ open depends on patch @
14 identifier open_f != simple_open;
15 identifier i, f;
16 @@
17 -int open_f(struct inode *i, struct file *f)
18 -{
19 (
20 -if (i->i_private)
21 -f->private_data = i->i_private;
22 |
23 -f->private_data = i->i_private;
24 )
25 -return 0;
26 -}
27
28 @ has_open depends on open @
29 identifier fops;
30 identifier open.open_f;
31 @@
32 struct file_operations fops = {
33 ...,
34 -.open = open_f,
35 +.open = simple_open,
36 ...
37 };
38
39 @ openr depends on report @
40 identifier open_f != simple_open;
41 identifier i, f;
42 position p;
43 @@
44 int open_f@p(struct inode *i, struct file *f)
45 {
46 (
47 if (i->i_private)
48 f->private_data = i->i_private;
49 |
50 f->private_data = i->i_private;
51 )
52 return 0;
53 }
54
55 @ has_openr depends on openr @
56 identifier fops;
57 identifier openr.open_f;
58 position p;
59 @@
60 struct file_operations fops = {
61 ...,
62 .open = open_f@p,
63 ...
64 };
65
66 @script:python@
67 pf << openr.p;
68 ps << has_openr.p;
69 @@
70
71 coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))