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