checkpatch: whine about ACCESS_ONCE
[cascardo/linux.git] / scripts / checkpatch.pl
index d574d13..1048672 100755 (executable)
@@ -2755,6 +2755,19 @@ sub process {
                            "Logical continuations should be on the previous line\n" . $hereprev);
                }
 
+# check indentation starts on a tab stop
+               if ($^V && $^V ge 5.10.0 &&
+                   $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$))/) {
+                       my $indent = length($1);
+                       if ($indent % 8) {
+                               if (WARN("TABSTOP",
+                                        "Statements should start on a tabstop\n" . $herecurr) &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e;
+                               }
+                       }
+               }
+
 # check multi-line statement indentation matches previous line
                if ($^V && $^V ge 5.10.0 &&
                    $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|$Ident\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
@@ -4291,7 +4304,7 @@ sub process {
                        my $comp = $3;
                        my $to = $4;
                        my $newcomp = $comp;
-                       if ($lead !~ /$Operators\s*$/ &&
+                       if ($lead !~ /(?:$Operators|\.)\s*$/ &&
                            $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
                            WARN("CONSTANT_COMPARISON",
                                 "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
@@ -5637,6 +5650,16 @@ sub process {
                        }
                }
 
+# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
+               if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
+                       my $config = $1;
+                       if (WARN("PREFER_IS_ENABLED",
+                                "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) &&
+                           $fix) {
+                               $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
+                       }
+               }
+
 # check for case / default statements not preceded by break/fallthrough/switch
                if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
                        my $has_break = 0;
@@ -5827,6 +5850,28 @@ sub process {
                        }
                }
 
+# whine about ACCESS_ONCE
+               if ($^V && $^V ge 5.10.0 &&
+                   $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
+                       my $par = $1;
+                       my $eq = $2;
+                       my $fun = $3;
+                       $par =~ s/^\(\s*(.*)\s*\)$/$1/;
+                       if (defined($eq)) {
+                               if (WARN("PREFER_WRITE_ONCE",
+                                        "Prefer WRITE_ONCE(<FOO>, <BAR>) over ACCESS_ONCE(<FOO>) = <BAR>\n" . $herecurr) &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)\s*$eq\s*\Q$fun\E/WRITE_ONCE($par, $fun)/;
+                               }
+                       } else {
+                               if (WARN("PREFER_READ_ONCE",
+                                        "Prefer READ_ONCE(<FOO>) over ACCESS_ONCE(<FOO>)\n" . $herecurr) &&
+                                   $fix) {
+                                       $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)/READ_ONCE($par)/;
+                               }
+                       }
+               }
+
 # check for lockdep_set_novalidate_class
                if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
                    $line =~ /__lockdep_no_validate__\s*\)/ ) {