checkpatch: add --strict test for spaces around arithmetic
[cascardo/linux.git] / scripts / checkpatch.pl
index 6705576..32bd31c 100755 (executable)
@@ -2541,7 +2541,7 @@ sub process {
                        }
                }
 
-               if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;\({\[\<\>])/ &&
+               if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ &&
                    (!defined($1) || $1 !~ /sizeof\s*/)) {
                        if (CHK("SPACING",
                                "No space is necessary after a cast\n" . $herecurr) &&
@@ -3243,7 +3243,7 @@ sub process {
 # check for uses of printk_ratelimit
                if ($line =~ /\bprintk_ratelimit\s*\(/) {
                        WARN("PRINTK_RATELIMITED",
-"Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
+                            "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
                }
 
 # printk should use KERN_* levels.  Note that follow on printk's on the
@@ -3689,7 +3689,22 @@ sub process {
                                         $op eq '*' or $op eq '/' or
                                         $op eq '%')
                                {
-                                       if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
+                                       if ($check) {
+                                               if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
+                                                       if (CHK("SPACING",
+                                                               "spaces preferred around that '$op' $at\n" . $hereptr)) {
+                                                               $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+                                                               $fix_elements[$n + 2] =~ s/^\s+//;
+                                                               $line_fixed = 1;
+                                                       }
+                                               } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
+                                                       if (CHK("SPACING",
+                                                               "space preferred before that '$op' $at\n" . $hereptr)) {
+                                                               $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
+                                                               $line_fixed = 1;
+                                                       }
+                                               }
+                                       } elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
                                                if (ERROR("SPACING",
                                                          "need consistent spacing around '$op' $at\n" . $hereptr)) {
                                                        $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
@@ -4461,12 +4476,18 @@ sub process {
 
 # check for unnecessary blank lines around braces
                if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
-                       CHK("BRACES",
-                           "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
+                       if (CHK("BRACES",
+                               "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
+                           $fix && $prevrawline =~ /^\+/) {
+                               fix_delete_line($fixlinenr - 1, $prevrawline);
+                       }
                }
                if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
-                       CHK("BRACES",
-                           "Blank lines aren't necessary after an open brace '{'\n" . $hereprev);
+                       if (CHK("BRACES",
+                               "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
+                           $fix) {
+                               fix_delete_line($fixlinenr, $rawline);
+                       }
                }
 
 # no volatiles please
@@ -4848,7 +4869,8 @@ sub process {
 # check for seq_printf uses that could be seq_puts
                if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
                        my $fmt = get_quoted_string($line, $rawline);
-                       if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
+                       $fmt =~ s/%%//g;
+                       if ($fmt !~ /%/) {
                                if (WARN("PREFER_SEQ_PUTS",
                                         "Prefer seq_puts to seq_printf\n" . $herecurr) &&
                                    $fix) {