checkpatch: only warn for empty lines before closing braces by themselves
authorMatthijs Kooijman <matthijs@stdin.nl>
Mon, 29 Apr 2013 23:18:16 +0000 (16:18 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 30 Apr 2013 01:28:20 +0000 (18:28 -0700)
This check was intended to catch extra newlines at the end of a function
definition, but it would trigger on any closing brace, including those
of inline functions and macro definitions, triggering false positives.
Now, only closing braces on a line by themselves trigger this check.

Tested with:

$ cat test.h
/* test.h - Test file */

static inline int foo(void) { return 0; }

static inline int bar(void)
{
        return 1;

}

$ ./scripts/checkpatch.pl --strict -f test.h # Before this commit
CHECK: Blank lines aren't necessary before a close brace '}'
+
+static inline int foo(void) { return 0; }

CHECK: Blank lines aren't necessary before a close brace '}'
+
+}

total: 0 errors, 0 warnings, 2 checks, 9 lines checked

$ ./scripts/checkpatch.pl --strict -f test.h # After this commit
CHECK: Blank lines aren't necessary before a close brace '}'
+
+}

total: 0 errors, 0 warnings, 1 checks, 9 lines checked

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
Cc: Andy Whitcroft <apw@canonical.com>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index b20ca55cddd3aaa07488323e66161403a2f55423..3a7600d1278313c37d7bc0bdbe8a9d9e76b205a5 100755 (executable)
@@ -3229,7 +3229,7 @@ sub process {
                }
 
 # check for unnecessary blank lines around braces
-               if (($line =~ /^..*}\s*$/ && $prevline =~ /^.\s*$/)) {
+               if (($line =~ /^.\s*}\s*$/ && $prevline =~ /^.\s*$/)) {
                        CHK("BRACES",
                            "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
                }