checkpatch: notice unbalanced else braces in a patch
authorJoe Perches <joe@perches.com>
Fri, 24 Feb 2017 23:01:41 +0000 (15:01 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Feb 2017 01:46:57 +0000 (17:46 -0800)
Patches that add or modify code like

} else
<foo>
or
else {
<bar>

where one branch appears to have a brace and the other branch does not
have a brace should emit a --strict style message.

Link: http://lkml.kernel.org/r/c6be32747fc725cbc235802991746700a0f54fdc.1486754390.git.joe@perches.com
Signed-off-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 12db1483e6c250b399139bc1482af121a9c77967..7fb73d92801cd80ff726f622b014ef8ec1d715e0 100755 (executable)
@@ -5104,6 +5104,12 @@ sub process {
                        }
                }
 
+# check for single line unbalanced braces
+               if ($sline =~ /.\s*\}\s*else\s*$/ ||
+                   $sline =~ /.\s*else\s*\{\s*$/) {
+                       CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
+               }
+
 # check for unnecessary blank lines around braces
                if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
                        if (CHK("BRACES",