19b3ae64bSJulia Lawall/// This removes an open coded simple_open() function 29b3ae64bSJulia Lawall/// and replaces file operations references to the function 39b3ae64bSJulia Lawall/// with simple_open() instead. 49b3ae64bSJulia Lawall/// 59b3ae64bSJulia Lawall// Confidence: High 69b3ae64bSJulia Lawall// Comments: 7*93f14468SNicolas Palix// Options: --no-includes --include-headers 89b3ae64bSJulia Lawall 99b3ae64bSJulia Lawallvirtual patch 109b3ae64bSJulia Lawallvirtual report 119b3ae64bSJulia Lawall 129b3ae64bSJulia Lawall@ open depends on patch @ 139b3ae64bSJulia Lawallidentifier open_f != simple_open; 149b3ae64bSJulia Lawallidentifier i, f; 159b3ae64bSJulia Lawall@@ 169b3ae64bSJulia Lawall-int open_f(struct inode *i, struct file *f) 179b3ae64bSJulia Lawall-{ 189b3ae64bSJulia Lawall( 199b3ae64bSJulia Lawall-if (i->i_private) 209b3ae64bSJulia Lawall-f->private_data = i->i_private; 219b3ae64bSJulia Lawall| 229b3ae64bSJulia Lawall-f->private_data = i->i_private; 239b3ae64bSJulia Lawall) 249b3ae64bSJulia Lawall-return 0; 259b3ae64bSJulia Lawall-} 269b3ae64bSJulia Lawall 279b3ae64bSJulia Lawall@ has_open depends on open @ 289b3ae64bSJulia Lawallidentifier fops; 299b3ae64bSJulia Lawallidentifier open.open_f; 309b3ae64bSJulia Lawall@@ 319b3ae64bSJulia Lawallstruct file_operations fops = { 329b3ae64bSJulia Lawall..., 339b3ae64bSJulia Lawall-.open = open_f, 349b3ae64bSJulia Lawall+.open = simple_open, 359b3ae64bSJulia Lawall... 369b3ae64bSJulia Lawall}; 379b3ae64bSJulia Lawall 389b3ae64bSJulia Lawall@ openr depends on report @ 399b3ae64bSJulia Lawallidentifier open_f != simple_open; 409b3ae64bSJulia Lawallidentifier i, f; 419b3ae64bSJulia Lawallposition p; 429b3ae64bSJulia Lawall@@ 439b3ae64bSJulia Lawallint open_f@p(struct inode *i, struct file *f) 449b3ae64bSJulia Lawall{ 459b3ae64bSJulia Lawall( 469b3ae64bSJulia Lawallif (i->i_private) 479b3ae64bSJulia Lawallf->private_data = i->i_private; 489b3ae64bSJulia Lawall| 499b3ae64bSJulia Lawallf->private_data = i->i_private; 509b3ae64bSJulia Lawall) 519b3ae64bSJulia Lawallreturn 0; 529b3ae64bSJulia Lawall} 539b3ae64bSJulia Lawall 549b3ae64bSJulia Lawall@ has_openr depends on openr @ 559b3ae64bSJulia Lawallidentifier fops; 569b3ae64bSJulia Lawallidentifier openr.open_f; 579b3ae64bSJulia Lawallposition p; 589b3ae64bSJulia Lawall@@ 599b3ae64bSJulia Lawallstruct file_operations fops = { 609b3ae64bSJulia Lawall..., 619b3ae64bSJulia Lawall.open = open_f@p, 629b3ae64bSJulia Lawall... 639b3ae64bSJulia Lawall}; 649b3ae64bSJulia Lawall 659b3ae64bSJulia Lawall@script:python@ 669b3ae64bSJulia Lawallpf << openr.p; 679b3ae64bSJulia Lawallps << has_openr.p; 689b3ae64bSJulia Lawall@@ 699b3ae64bSJulia Lawall 709b3ae64bSJulia Lawallcoccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line)) 71