Whamcloud - gitweb
LU-16829 gss: quiet noisy warnings
[fs/lustre-release.git] / contrib / scripts / checkpatch.pl
index 1e9bf50..b9d5a34 100755 (executable)
@@ -457,7 +457,7 @@ our $logFunctions = qr{(?x:
        printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
        (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
        WARN(?:_RATELIMIT|_ONCE|)|
-       CDEBUG|CERROR|CL_LOCK_DEBUG|CWARN|DEBUG_REQ|LCONSOLE_[A-Z]*|
+       CDEBUG|CERROR|CNETERR|CEMERG|CL_LOCK_DEBUG|CWARN|DEBUG_REQ|LCONSOLE_[A-Z]*|
        panic|
        MODULE_[A-Z_]+|
        seq_vprintf|seq_printf|seq_puts
@@ -2894,6 +2894,10 @@ sub process {
                        if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
                            length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
                                $msg_type = "";
+                       # a Lustre message that contains embedded formatting
+                       } elsif ($line =~ /^\+\s*(?:$logFunctions\s*\()?($String(?:DFID|DOSTID)$String\s*(?:|,|\)\s*;)?\s*)$/ &&
+                                length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+                               $msg_type = ""
 
                        # lines with only strings (w/ possible termination)
                        # #defines with only strings
@@ -3042,7 +3046,7 @@ sub process {
 
 # Block comment styles
 # Networking with an initial /*
-               if ($realfile =~ m@^(drivers/net/|net/)@ &&
+               if ($realfile =~ m@^(drivers/net/|net/|lnet)@ &&
                    $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
                    $rawline =~ /^\+[ \t]*\*/ &&
                    $realline > 2) {
@@ -4556,6 +4560,8 @@ sub process {
 #      avoid cases like "foo + BAR < baz"
 #      only fix matches surrounded by parentheses to avoid incorrect
 #      conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
+# Exceptions:
+# 01.  LUSTRE_VERSION_CODE upper-case constant on left side.
                if ($^V && $^V ge 5.10.0 &&
                    $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
                        my $lead = $1;
@@ -4565,6 +4571,7 @@ sub process {
                        my $newcomp = $comp;
                        if ($lead !~ /(?:$Operators|\.)\s*$/ &&
                            $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
+                           $const !~ /LUSTRE_VERSION_CODE/ &&
                            WARN("CONSTANT_COMPARISON",
                                 "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
                            $fix) {
@@ -5165,31 +5172,42 @@ sub process {
                        }
                }
 
-# try to replace assertions with error handling
+# Lustre try to replace assertions with error handling
                if ($line =~ /\bLASSERTF?\s*\(/) {
                    WARN("LASSERT",
-                        "try to replace assertions with error handling\n" .
+                        "Try to replace assertions with error handling\n" .
                         $herecurr);
                }
 
-# avoid new console messages
-               if ($line =~ /\bLCONSOLE[A-Z_]*\s*\(/) {
-                   WARN("LCONSOLE",
-                        "avoid adding new console messages\n" .
-                        $herecurr);
-               }
+# Lustre minimize new CERROR messages
+               if ($line =~ /\b(CEMERG|CERROR|CNETERR|CWARN|LCONSOLE)\s*\(/) {
+                       if ($rawline !~ /\(\"\%s: /) {
+                               WARN("CERROR_DEV",
+                                    "Console messages should start with '%s:' to print device name\n" . $herecurr)
+                       }
 
-# minimize new CERROR messages
-               if ($line =~ /\bC(EMERG|ERROR|NETERR|WARN)\s*\(/) {
-                   WARN("CERROR",
-                        "think hard when adding new CERROR messages\n" .
-                        $herecurr);
+                       # Check for "rc = %d" or "rc = %ld" at the end of errors
+                       if ($line !~ /LCONSOLE/ && $rawline !~ /: rc = \%l?d\\n\",/) {
+                               WARN("CERROR_RET",
+                                    "Console messages should end with ': rc = %d' or 'rc = %ld'\n" . $herecurr);
+                       }
+
+                       # This is fine as we are only matching the first part.
+                       if ($line =~ /(CEMERG|CERROR|CNETERR)/) {
+                               WARN("CERROR",
+                                    "Errors should be useful to fix failure conditions, not status/debug\n" . $herecurr);
+                       }
+               }
+# Lustre avoid unlimited message printing to the console
+               if ($line =~ /CDEBUG\((D_ERROR|D_WARNING|D_CONSOLE|[a-z])/) {
+                       WARN("CDEBUG_LIMIT",
+                            "CDEBUG does not rate-limit console messages, use CDEBUG_LIMIT\n". $herecurr);
                }
 
-# don't allow GPLv3 license files
+# Lustre don't allow GPLv3 license files
                if ($rawline =~ /version 3/) {
                        WARN("GPLV3",
-                            "using GPLv3 is usually wrong\n" . $herecurr);
+                            "Using GPLv3 is usually wrong\n" . $herecurr);
                }
 
 # check for single line unbalanced braces
@@ -5638,16 +5656,16 @@ sub process {
                        }
                }
 
-# Check for __attribute__ packed, prefer __packed
+# Check for __packed, prefer __attribute__ packed
                if ($realfile !~ m@\binclude/uapi/@ &&
-                   $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
+                   $line =~ /\b__packed\b/) {
                        WARN("PREFER_PACKED",
                             "__packed is preferred over __attribute__((packed))\n" . $herecurr);
                }
 
-# Check for __attribute__ aligned, prefer __aligned
+# Check for __aligned, prefer __attribute__ aligned
                if ($realfile !~ m@\binclude/uapi/@ &&
-                   $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
+                   $line =~ /\b__aligned\b/) {
                        WARN("PREFER_ALIGNED",
                             "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
                }
@@ -5766,7 +5784,7 @@ sub process {
                        for (my $count = $linenr; $count <= $lc; $count++) {
                                my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
                                $fmt =~ s/%%//g;
-                               if ($fmt =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGNO]).)/) {
+                               if ($fmt =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGNOx]).)/) {
                                        $bad_extension = $1;
                                        last;
                                }
@@ -6113,7 +6131,7 @@ sub process {
                                next if ($fline =~ /^.[\s$;]*$/);
                                $has_statement = 1;
                                $count++;
-                               $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
+                               $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/i);
                        }
                        if (!$has_break && $has_statement) {
                                WARN("MISSING_BREAK",