Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /// Remove an open coded simple_open() function
0003 /// and replace file operations references to the function
0004 /// with simple_open() instead.
0005 ///
0006 // Confidence: High
0007 // Comments:
0008 // Options: --no-includes --include-headers
0009 
0010 virtual patch
0011 virtual report
0012 
0013 @ open depends on patch @
0014 identifier open_f != simple_open;
0015 identifier i, f;
0016 @@
0017 -int open_f(struct inode *i, struct file *f)
0018 -{
0019 (
0020 -if (i->i_private)
0021 -f->private_data = i->i_private;
0022 |
0023 -f->private_data = i->i_private;
0024 )
0025 -return 0;
0026 -}
0027 
0028 @ has_open depends on open @
0029 identifier fops;
0030 identifier open.open_f;
0031 @@
0032 struct file_operations fops = {
0033 ...,
0034 -.open = open_f,
0035 +.open = simple_open,
0036 ...
0037 };
0038 
0039 @ openr depends on report @
0040 identifier open_f != simple_open;
0041 identifier i, f;
0042 position p;
0043 @@
0044 int open_f@p(struct inode *i, struct file *f)
0045 {
0046 (
0047 if (i->i_private)
0048 f->private_data = i->i_private;
0049 |
0050 f->private_data = i->i_private;
0051 )
0052 return 0;
0053 }
0054 
0055 @ has_openr depends on openr @
0056 identifier fops;
0057 identifier openr.open_f;
0058 position p;
0059 @@
0060 struct file_operations fops = {
0061 ...,
0062 .open = open_f@p,
0063 ...
0064 };
0065 
0066 @script:python@
0067 pf << openr.p;
0068 ps << has_openr.p;
0069 @@
0070 
0071 coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))