summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2015-09-09 18:37:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-10 16:29:01 -0400
commit9f5af480f4554aac12e002b6f5c2b04895857700 (patch)
treea4c8826093272ba4bc1b28f84aa8b83024314129 /scripts
parent9d3e3c705eb395528fd8f17208c87581b134da48 (diff)
checkpatch: improve SUSPECT_CODE_INDENT test
Many lines exist like if (foo) bar; where the tabbed indentation of the branch is not one more than the "if" line above it. checkpatch should emit a warning on those lines. Miscellenea: o Remove comments from branch blocks o Skip blank lines in block 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')
-rwxr-xr-xscripts/checkpatch.pl21
1 files changed, 15 insertions, 6 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1629e3513f0d..ce305ff53aab 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3076,15 +3076,22 @@ sub process {
3076 3076
3077 substr($s, 0, length($c), ''); 3077 substr($s, 0, length($c), '');
3078 3078
3079 # Make sure we remove the line prefixes as we have 3079 # remove inline comments
3080 # none on the first line, and are going to readd them 3080 $s =~ s/$;/ /g;
3081 # where necessary. 3081 $c =~ s/$;/ /g;
3082 $s =~ s/\n./\n/gs;
3083 3082
3084 # Find out how long the conditional actually is. 3083 # Find out how long the conditional actually is.
3085 my @newlines = ($c =~ /\n/gs); 3084 my @newlines = ($c =~ /\n/gs);
3086 my $cond_lines = 1 + $#newlines; 3085 my $cond_lines = 1 + $#newlines;
3087 3086
3087 # Make sure we remove the line prefixes as we have
3088 # none on the first line, and are going to readd them
3089 # where necessary.
3090 $s =~ s/\n./\n/gs;
3091 while ($s =~ /\n\s+\\\n/) {
3092 $cond_lines += $s =~ s/\n\s+\\\n/\n/g;
3093 }
3094
3088 # We want to check the first line inside the block 3095 # We want to check the first line inside the block
3089 # starting at the end of the conditional, so remove: 3096 # starting at the end of the conditional, so remove:
3090 # 1) any blank line termination 3097 # 1) any blank line termination
@@ -3150,8 +3157,10 @@ sub process {
3150 3157
3151 #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; 3158 #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
3152 3159
3153 if ($check && (($sindent % 8) != 0 || 3160 if ($check && $s ne '' &&
3154 ($sindent <= $indent && $s ne ''))) { 3161 (($sindent % 8) != 0 ||
3162 ($sindent < $indent) ||
3163 ($sindent > $indent + 8))) {
3155 WARN("SUSPECT_CODE_INDENT", 3164 WARN("SUSPECT_CODE_INDENT",
3156 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); 3165 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
3157 } 3166 }