checkpatch: prefer ftrace over function entry/exit printks
[linux-2.6-microblaze.git] / scripts / checkpatch.pl
index ca42017..736129c 100755 (executable)
@@ -382,6 +382,7 @@ our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeIni
 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
 our $Attribute = qr{
                        const|
+                       volatile|
                        __percpu|
                        __nocast|
                        __safe|
@@ -506,6 +507,30 @@ our $signature_tags = qr{(?xi:
        Cc:
 )};
 
+our $tracing_logging_tags = qr{(?xi:
+       [=-]*> |
+       <[=-]* |
+       \[ |
+       \] |
+       start |
+       called |
+       entered |
+       entry |
+       enter |
+       in |
+       inside |
+       here |
+       begin |
+       exit |
+       end |
+       done |
+       leave |
+       completed |
+       out |
+       return |
+       [\.\!:\s]*
+)};
+
 sub edit_distance_min {
        my (@arr) = @_;
        my $len = scalar @arr;
@@ -2973,7 +2998,7 @@ sub process {
                                }
                                if (!defined $lines[$linenr]) {
                                        WARN("BAD_SIGN_OFF",
-                                             "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
+                                            "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
                                } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
                                        WARN("BAD_SIGN_OFF",
                                             "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
@@ -2996,8 +3021,8 @@ sub process {
                        if (ERROR("GERRIT_CHANGE_ID",
                                  "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
                            $fix) {
-                                fix_delete_line($fixlinenr, $rawline);
-                        }
+                               fix_delete_line($fixlinenr, $rawline);
+                       }
                }
 
 # Check if the commit log is in a possible stack dump
@@ -3239,10 +3264,10 @@ sub process {
                                next if ($start_char =~ /^\S$/);
                                next if (index(" \t.,;?!", $end_char) == -1);
 
-                                # avoid repeating hex occurrences like 'ff ff fe 09 ...'
-                                if ($first =~ /\b[0-9a-f]{2,}\b/i) {
-                                        next if (!exists($allow_repeated_words{lc($first)}));
-                                }
+                               # avoid repeating hex occurrences like 'ff ff fe 09 ...'
+                               if ($first =~ /\b[0-9a-f]{2,}\b/i) {
+                                       next if (!exists($allow_repeated_words{lc($first)}));
+                               }
 
                                if (WARN("REPEATED_WORD",
                                         "Possible repeated word: '$first'\n" . $herecurr) &&
@@ -3776,43 +3801,48 @@ sub process {
                }
 
 # check for missing blank lines after declarations
-               if ($sline =~ /^\+\s+\S/ &&                     #Not at char 1
-                       # actual declarations
-                   ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+# (declarations must have the same indentation and not be at the start of line)
+               if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
+                       # use temporaries
+                       my $sl = $sline;
+                       my $pl = $prevline;
+                       # remove $Attribute/$Sparse uses to simplify comparisons
+                       $sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
+                       $pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
+                       if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
                        # function pointer declarations
-                    $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+                            $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
                        # foo bar; where foo is some local typedef or #define
-                    $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+                            $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
                        # known declaration macros
-                    $prevline =~ /^\+\s+$declaration_macros/) &&
+                            $pl =~ /^\+\s+$declaration_macros/) &&
                        # for "else if" which can look like "$Ident $Ident"
-                   !($prevline =~ /^\+\s+$c90_Keywords\b/ ||
+                           !($pl =~ /^\+\s+$c90_Keywords\b/ ||
                        # other possible extensions of declaration lines
-                     $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
+                             $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
                        # not starting a section or a macro "\" extended line
-                     $prevline =~ /(?:\{\s*|\\)$/) &&
+                             $pl =~ /(?:\{\s*|\\)$/) &&
                        # looks like a declaration
-                   !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+                           !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
                        # function pointer declarations
-                     $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+                             $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
                        # foo bar; where foo is some local typedef or #define
-                     $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+                             $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
                        # known declaration macros
-                     $sline =~ /^\+\s+$declaration_macros/ ||
+                             $sl =~ /^\+\s+$declaration_macros/ ||
                        # start of struct or union or enum
-                     $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
+                             $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
                        # start or end of block or continuation of declaration
-                     $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
+                             $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
                        # bitfield continuation
-                     $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
+                             $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
                        # other possible extensions of declaration lines
-                     $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
-                       # indentation of previous and current line are the same
-                   (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
-                       if (WARN("LINE_SPACING",
-                                "Missing a blank line after declarations\n" . $hereprev) &&
-                           $fix) {
-                               fix_insert_line($fixlinenr, "\+");
+                             $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
+                               if (WARN("LINE_SPACING",
+                                        "Missing a blank line after declarations\n" . $hereprev) &&
+                                   $fix) {
+                                       fix_insert_line($fixlinenr, "\+");
+                               }
                        }
                }
 
@@ -4417,7 +4447,7 @@ sub process {
                        WARN("STATIC_CONST_CHAR_ARRAY",
                             "char * array declaration might be better as static const\n" .
                                $herecurr);
-               }
+               }
 
 # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
                if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
@@ -5270,7 +5300,7 @@ sub process {
                    $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
                        WARN("RETURN_VOID",
                             "void function return statements are not generally useful\n" . $hereprev);
-               }
+               }
 
 # if statements using unnecessary parentheses - ie: if ((foo == bar))
                if ($perl_version_ok &&
@@ -5966,6 +5996,17 @@ sub process {
                             "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
                }
 
+# check for unnecessary function tracing like uses
+# This does not use $logFunctions because there are many instances like
+# 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
+               if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) {
+                       if (WARN("TRACING_LOGGING",
+                                "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
+                           $fix) {
+                                fix_delete_line($fixlinenr, $rawline);
+                       }
+               }
+
 # check for spaces before a quoted newline
                if ($rawline =~ /^.*\".*\s\\n/) {
                        if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
@@ -7019,12 +7060,14 @@ sub process {
 
 # use of NR_CPUS is usually wrong
 # ignore definitions of NR_CPUS and usage to define arrays as likely right
+# ignore designated initializers using NR_CPUS
                if ($line =~ /\bNR_CPUS\b/ &&
                    $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
                    $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
                    $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
                    $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
-                   $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
+                   $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/ &&
+                   $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/)
                {
                        WARN("NR_CPUS",
                             "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);