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
9virtual patch
10virtual report
11
12@ open depends on patch @
13identifier open_f != simple_open;
14identifier 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 @
28identifier fops;
29identifier open.open_f;
30@@
31struct file_operations fops = {
32...,
33-.open = open_f,
34+.open = simple_open,
35...
36};
37
38@ openr depends on report @
39identifier open_f != simple_open;
40identifier i, f;
41position p;
42@@
43int open_f@p(struct inode *i, struct file *f)
44{
45(
46if (i->i_private)
47f->private_data = i->i_private;
48|
49f->private_data = i->i_private;
50)
51return 0;
52}
53
54@ has_openr depends on openr @
55identifier fops;
56identifier openr.open_f;
57position p;
58@@
59struct file_operations fops = {
60...,
61.open = open_f@p,
62...
63};
64
65@script:python@
66pf << openr.p;
67ps << has_openr.p;
68@@
69
70coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))
71