^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /// Remove an open coded simple_open() function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /// and replace file operations references to the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /// with simple_open() instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Confidence: High
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Comments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Options: --no-includes --include-headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) virtual patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) @ open depends on patch @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) identifier open_f != simple_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) identifier i, f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) -int open_f(struct inode *i, struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) -{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) -if (i->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) -f->private_data = i->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) -f->private_data = i->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) -return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) -}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) @ has_open depends on open @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) identifier fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) identifier open.open_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ...,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) -.open = open_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) +.open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) @ openr depends on report @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) identifier open_f != simple_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) identifier i, f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) position p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int open_f@p(struct inode *i, struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (i->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) f->private_data = i->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) f->private_data = i->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) @ has_openr depends on openr @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) identifier fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) identifier openr.open_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) position p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct file_operations fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ...,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .open = open_f@p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) @script:python@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pf << openr.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ps << has_openr.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) coccilib.report.print_report(pf[0],"WARNING opportunity for simple_open, see also structure on line %s"%(ps[0].line))