checkpatch: prefer usleep_range over udelay
[sfrench/cifs-2.6.git] / scripts / checkpatch.pl
index bd88f11b0953d161b259e80b27d6f423b12e8b1c..8b69af8a76f90acfe2cc2bdf556950c468b97ef3 100755 (executable)
@@ -195,7 +195,7 @@ our $typeTypedefs = qr{(?x:
 our $logFunctions = qr{(?x:
        printk|
        pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)|
-       dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
+       (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
        WARN|
        panic
 )};
@@ -224,6 +224,12 @@ our @modifierList = (
        qr{fastcall},
 );
 
+our $allowed_asm_includes = qr{(?x:
+       irq|
+       memory
+)};
+# memory.h: ARM has a custom one
+
 sub build_types {
        my $mods = "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
        my $all = "(?x:  \n" . join("|\n  ", @typeList) . "\n)";
@@ -1403,7 +1409,8 @@ sub process {
 #80 column limit
                if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
                    $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
-                   $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ &&
+                   !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ ||
+                   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
                    $length > 80)
                {
                        WARN("line over 80 characters\n" . $herecurr);
@@ -1448,6 +1455,13 @@ sub process {
                        WARN("please, no space before tabs\n" . $herevet);
                }
 
+# check for spaces at the beginning of a line.
+               if ($rawline =~ /^\+ / && $rawline !~ /\+ +\*/)  {
+                       my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+                       WARN("please, no space for starting a line, \
+                               excluding comments\n" . $herevet);
+               }
+
 # check we are in a valid C source file if not then ignore this hunk
                next if ($realfile !~ /\.(h|c)$/);
 
@@ -1778,9 +1792,9 @@ sub process {
                        WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
                }
 
-# check for external initialisers.
+# check for global initialisers.
                if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
-                       ERROR("do not initialise externals to 0 or NULL\n" .
+                       ERROR("do not initialise globals to 0 or NULL\n" .
                                $herecurr);
                }
 # check for static initialisers.
@@ -2308,7 +2322,7 @@ sub process {
                        my $checkfile = "include/linux/$file";
                        if (-f "$root/$checkfile" &&
                            $realfile ne $checkfile &&
-                           $1 ne 'irq')
+                           $1 !~ /$allowed_asm_includes/)
                        {
                                if ($realfile =~ m{^arch/}) {
                                        CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
@@ -2570,6 +2584,14 @@ sub process {
                        }
                }
 
+# prefer usleep_range over udelay
+               if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
+                       # ignore udelay's < 10, however
+                       if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
+                               CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
+                       }
+               }
+
 # warn about #ifdefs in C files
 #              if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
 #                      print "#ifdef in C files should be avoided\n";