summaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2017-05-08 18:56:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-08 20:15:11 -0400
commitf6950a735f29e782bc219ece22bb91d6e1ab7bbc (patch)
treeaeb8aacfa0c31e53997c33ee0939ff996fcfd4f7 /scripts/checkpatch.pl
parent74fd4f347bfc10c1b19a18d0760f220eed1b2023 (diff)
checkpatch: improve the SUSPECT_CODE_INDENT test
The current SUSPECT_CODE_INDENT test does not recognize several defective code style defects where code following a logical test is inappropriately indented. Before this patch, for code like: if (foo) bar(); checkpatch would not emit a warning. Improve the test to warn when code after a logical test has the same indentation as the logical test. Perform the same indentation test for "else" blocks too. Link: http://lkml.kernel.org/r/df2374b68c4a68af2b7ef08afe486584811f610a.1493683942.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>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl4
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 33740404cd9e..4b9569fa931b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3354,7 +3354,7 @@ sub process {
3354 } 3354 }
3355 3355
3356# Check relative indent for conditionals and blocks. 3356# Check relative indent for conditionals and blocks.
3357 if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { 3357 if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
3358 ($stat, $cond, $line_nr_next, $remain_next, $off_next) = 3358 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
3359 ctx_statement_block($linenr, $realcnt, 0) 3359 ctx_statement_block($linenr, $realcnt, 0)
3360 if (!defined $stat); 3360 if (!defined $stat);
@@ -3446,6 +3446,8 @@ sub process {
3446 if ($check && $s ne '' && 3446 if ($check && $s ne '' &&
3447 (($sindent % 8) != 0 || 3447 (($sindent % 8) != 0 ||
3448 ($sindent < $indent) || 3448 ($sindent < $indent) ||
3449 ($sindent == $indent &&
3450 ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
3449 ($sindent > $indent + 8))) { 3451 ($sindent > $indent + 8))) {
3450 WARN("SUSPECT_CODE_INDENT", 3452 WARN("SUSPECT_CODE_INDENT",
3451 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); 3453 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");