Skip to content

Commit

Permalink
checkpatch: notice unbalanced else braces in a patch
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
JoePerches authored and sfrothwell committed Feb 19, 2017
1 parent 6235064 commit 0d15324
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0d15324

Please sign in to comment.