checkpatch: struct file_operations should normally be const
authorAndy Whitcroft <[email protected]>
Tue, 6 Jan 2009 22:41:29 +0000 (14:41 -0800)
committerLinus Torvalds <[email protected]>
Tue, 6 Jan 2009 23:59:17 +0000 (15:59 -0800)
In the general use case struct file_operations should be a const object.
Check for and warn where it is not.  As suggested by Steven and Ingo.

Acked-by: Steven Rostedt <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Andy Whitcroft <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
scripts/checkpatch.pl

index c39ce0b663b4310f3131cdc3795e98df590afc48..94371f69122c7b4eba5dfa63d07e0642cdb459a9 100755 (executable)
@@ -2509,6 +2509,11 @@ sub process {
                if ($line =~ /^.\s*__initcall\s*\(/) {
                        WARN("please use device_initcall() instead of __initcall()\n" . $herecurr);
                }
+# check for struct file_operations, ensure they are const.
+               if ($line =~ /\bstruct\s+file_operations\b/ &&
+                   $line !~ /\bconst\b/) {
+                       WARN("struct file_operations should normally be const\n" . $herecurr);
+               }
 
 # use of NR_CPUS is usually wrong
 # ignore definitions of NR_CPUS and usage to define arrays as likely right