checkpatch: make in_atomic ok in the core
[sfrench/cifs-2.6.git] / scripts / checkpatch.pl
index 7bed4ed2c5197c5d360533665dcea69bc6446109..c71a0fae84df5a646d3bfb124937204c747035af 100755 (executable)
@@ -10,7 +10,7 @@ use strict;
 my $P = $0;
 $P =~ s@.*/@@g;
 
-my $V = '0.26';
+my $V = '0.27';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
@@ -411,13 +411,15 @@ sub ctx_statement_block {
 
        my $type = '';
        my $level = 0;
-       my @stack = ([$type, $level]);
+       my @stack = ();
        my $p;
        my $c;
        my $len = 0;
 
        my $remainder;
        while (1) {
+               @stack = (['', 0]) if ($#stack == -1);
+
                #warn "CSB: blk<$blk> remain<$remain>\n";
                # If we are about to drop off the end, pull in more
                # context.
@@ -1663,7 +1665,7 @@ sub process {
                        # Should not end with a space.
                        $to =~ s/\s+$//;
                        # '*'s should not have spaces between.
-                       while ($to =~ s/(.)\s\*/$1\*/) {
+                       while ($to =~ s/\*\s+\*/\*\*/) {
                        }
 
                        #print "from<$from> to<$to>\n";
@@ -1678,7 +1680,7 @@ sub process {
                        # Should not end with a space.
                        $to =~ s/\s+$//;
                        # '*'s should not have spaces between.
-                       while ($to =~ s/(.)\s\*/$1\*/) {
+                       while ($to =~ s/\*\s+\*/\*\*/) {
                        }
                        # Modifiers should have spaces.
                        $to =~ s/(\b$Modifier$)/$1 /;
@@ -2014,7 +2016,11 @@ sub process {
 
                        # Flatten any parentheses
                        $value =~ s/\)\(/\) \(/g;
-                       while ($value !~ /(?:$Ident|-?$Constant)\s*$Compare\s*(?:$Ident|-?$Constant)/ && $value =~ s/\([^\(\)]*\)/1/) {
+                       while ($value =~ s/\[[^\{\}]*\]/1/ ||
+                              $value !~ /(?:$Ident|-?$Constant)\s*
+                                            $Compare\s*
+                                            (?:$Ident|-?$Constant)/x &&
+                              $value =~ s/\([^\(\)]*\)/1/) {
                        }
 
                        if ($value =~ /^(?:$Ident|-?$Constant)$/) {
@@ -2102,6 +2108,11 @@ sub process {
                                ERROR("trailing statements should be on next line\n" . $herecurr);
                        }
                }
+# if should not continue a brace
+               if ($line =~ /}\s*if\b/) {
+                       ERROR("trailing statements should be on next line\n" .
+                               $herecurr);
+               }
 # case and default should not have general statements after them
                if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
                    $line !~ /\G(?:
@@ -2516,9 +2527,10 @@ sub process {
                        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);
+               if ($line !~ /\bconst\b/ &&
+                   $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) {
+                       WARN("struct $1 should normally be const\n" .
+                               $herecurr);
                }
 
 # use of NR_CPUS is usually wrong
@@ -2548,7 +2560,7 @@ sub process {
                if ($line =~ /\bin_atomic\s*\(/) {
                        if ($realfile =~ m@^drivers/@) {
                                ERROR("do not use in_atomic in drivers\n" . $herecurr);
-                       } else {
+                       } elsif ($realfile !~ m@^kernel/@) {
                                WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
                        }
                }