checkpatch: net and drivers/net: warn on missing blank line after variable declaration
authorJoe Perches <joe@perches.com>
Thu, 3 Apr 2014 21:49:28 +0000 (14:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 3 Apr 2014 23:21:15 +0000 (16:21 -0700)
Networking prefers this style, so warn when it's not used.

Networking uses:

    void foo(int bar)
    {
        int baz;

        code...
   }

not

    void foo(int bar)
    {
        int baz;
        code...
    }

There are a limited number of false positives when using macros to
declare variables like:

  WARNING: networking uses a blank line after declarations
  #330: FILE: net/ipv4/inet_hashtables.c:330:
  + int dif = sk->sk_bound_dev_if;
  + INET_ADDR_COOKIE(acookie, saddr, daddr)

Signed-off-by: Joe Perches <joe@perches.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index 921c037f19689cf187b6973a05f9a1c54de38a3f..33072d6c1b5a901bac5266e606b4030bf39aef47 100755 (executable)
@@ -2257,6 +2257,21 @@ sub process {
                             "networking block comments put the trailing */ on a separate line\n" . $herecurr);
                }
 
+# check for missing blank lines after declarations
+               if ($realfile =~ m@^(drivers/net/|net/)@ &&
+                   $prevline =~ /^\+\s+$Declare\s+$Ident/ &&
+                   !($prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
+                     $prevline =~ /(?:\{\s*|\\)$/) &&          #extended lines
+                   $sline =~ /^\+\s+/ &&                       #Not at char 1
+                   !($sline =~ /^\+\s+$Declare/ ||
+                     $sline =~ /^\+\s+$Ident\s+$Ident/ ||      #eg: typedef foo
+                     $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ ||
+                     $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(])/ ||
+                     $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
+                       WARN("SPACING",
+                            "networking uses a blank line after declarations\n" . $hereprev);
+               }
+
 # check for spaces at the beginning of a line.
 # Exceptions:
 #  1) within comments