Skip to content

Commit

Permalink
checkpatch: remove false unbalanced braces warning
Browse files Browse the repository at this point in the history
Lines containing "} else {" should not be detected as unbalanced braces.
But the second check can be reduced to ".+else\s*{" and it therefore
never checked if the beginning of a line contains any other character
(like the relevant "}").  This check would also return true for "} else
{" and create warnings like

    CHECK: Unbalanced braces around else statement
    torvalds#391: FILE: ./net/batman-adv/tvlv.c:391:
    +   } else {

The check can be changed to check the whole line for the missing "}" to
avoid this false positive.

Fixes: 0d15324 ("checkpatch: notice unbalanced else braces in a patch")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Sven Eckelmann <[email protected]>
Acked-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ecsv authored and torvalds committed Feb 25, 2017
1 parent e4c5bab commit 9533047
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5105,8 +5105,8 @@ sub process {
}

# check for single line unbalanced braces
if ($sline =~ /.\s*\}\s*else\s*$/ ||
$sline =~ /.\s*else\s*\{\s*$/) {
if ($sline =~ /^.\s*\}\s*else\s*$/ ||
$sline =~ /^.\s*else\s*\{\s*$/) {
CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
}

Expand Down

0 comments on commit 9533047

Please sign in to comment.