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