checkpatch: don't warn on some function pointer return styles
[firefly-linux-kernel-4.4.55.git] / scripts / checkpatch.pl
index 464dcef79b353be5426115fb3fb8ba1f746546df..19591af206c59d1225c69b864f77e453524d2d4e 100755 (executable)
@@ -2848,10 +2848,7 @@ sub process {
 # Function pointer declarations
 # check spacing between type, funcptr, and args
 # canonical declaration is "type (*funcptr)(args...)"
-#
-# the $Declare variable will capture all spaces after the type
-# so check it for trailing missing spaces or multiple spaces
-               if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) {
+               if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
                        my $declare = $1;
                        my $pre_pointer_space = $2;
                        my $post_pointer_space = $3;
@@ -2859,16 +2856,30 @@ sub process {
                        my $post_funcname_space = $5;
                        my $pre_args_space = $6;
 
-                       if ($declare !~ /\s$/) {
+# the $Declare variable will capture all spaces after the type
+# so check it for a missing trailing missing space but pointer return types
+# don't need a space so don't warn for those.
+                       my $post_declare_space = "";
+                       if ($declare =~ /(\s+)$/) {
+                               $post_declare_space = $1;
+                               $declare = rtrim($declare);
+                       }
+                       if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
                                WARN("SPACING",
                                     "missing space after return type\n" . $herecurr);
+                               $post_declare_space = " ";
                        }
 
 # unnecessary space "type  (*funcptr)(args...)"
-                       elsif ($declare =~ /\s{2,}$/) {
-                               WARN("SPACING",
-                                    "Multiple spaces after return type\n" . $herecurr);
-                       }
+# This test is not currently implemented because these declarations are
+# equivalent to
+#      int  foo(int bar, ...)
+# and this is form shouldn't/doesn't generate a checkpatch warning.
+#
+#                      elsif ($declare =~ /\s{2,}$/) {
+#                              WARN("SPACING",
+#                                   "Multiple spaces after return type\n" . $herecurr);
+#                      }
 
 # unnecessary space "type ( *funcptr)(args...)"
                        if (defined $pre_pointer_space &&
@@ -2900,7 +2911,7 @@ sub process {
 
                        if (show_type("SPACING") && $fix) {
                                $fixed[$linenr - 1] =~
-                                   s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex;
+                                   s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
                        }
                }
 
@@ -3912,10 +3923,15 @@ sub process {
 
 # prefer usleep_range over udelay
                if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
+                       my $delay = $1;
                        # ignore udelay's < 10, however
-                       if (! ($1 < 10) ) {
+                       if (! ($delay < 10) ) {
                                CHK("USLEEP_RANGE",
-                                   "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
+                                   "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr);
+                       }
+                       if ($delay > 2000) {
+                               WARN("LONG_UDELAY",
+                                    "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
                        }
                }
 
@@ -3923,7 +3939,7 @@ sub process {
                if ($line =~ /\bmsleep\s*\((\d+)\);/) {
                        if ($1 < 20) {
                                WARN("MSLEEP",
-                                    "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
+                                    "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr);
                        }
                }