aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-08-06 19:11:14 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 21:01:28 -0400
commit8b8856f4b102ce148611322465f2ff8932664411 (patch)
tree77d03918dadddfdcf920acd3553745f0631093c3 /scripts
parent8d1824780f2f1786db5e0e7a54bbae75340c655c (diff)
checkpatch: fix brace style misuses of else and while
Add --fix corrections for ELSE_AFTER_BRACE and WHILE_AFTER_BRACE misuses. if (x) { ... } else { ... } is corrected to if (x) { ... } else { ... } and do { ... } while (x); is corrected to do { ... } while (x); 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.pl38
1 files changed, 30 insertions, 8 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1e95953b488f..404e3d6906aa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3885,14 +3885,26 @@ sub process {
3885 3885
3886 # Check for }<nl>else {, these must be at the same 3886 # Check for }<nl>else {, these must be at the same
3887 # indent level to be relevant to each other. 3887 # indent level to be relevant to each other.
3888 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and 3888 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
3889 $previndent == $indent) { 3889 $previndent == $indent) {
3890 ERROR("ELSE_AFTER_BRACE", 3890 if (ERROR("ELSE_AFTER_BRACE",
3891 "else should follow close brace '}'\n" . $hereprev); 3891 "else should follow close brace '}'\n" . $hereprev) &&
3892 $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
3893 fix_delete_line($fixlinenr - 1, $prevrawline);
3894 fix_delete_line($fixlinenr, $rawline);
3895 my $fixedline = $prevrawline;
3896 $fixedline =~ s/}\s*$//;
3897 if ($fixedline !~ /^\+\s*$/) {
3898 fix_insert_line($fixlinenr, $fixedline);
3899 }
3900 $fixedline = $rawline;
3901 $fixedline =~ s/^(.\s*)else/$1} else/;
3902 fix_insert_line($fixlinenr, $fixedline);
3903 }
3892 } 3904 }
3893 3905
3894 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and 3906 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
3895 $previndent == $indent) { 3907 $previndent == $indent) {
3896 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); 3908 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
3897 3909
3898 # Find out what is on the end of the line after the 3910 # Find out what is on the end of the line after the
@@ -3901,8 +3913,18 @@ sub process {
3901 $s =~ s/\n.*//g; 3913 $s =~ s/\n.*//g;
3902 3914
3903 if ($s =~ /^\s*;/) { 3915 if ($s =~ /^\s*;/) {
3904 ERROR("WHILE_AFTER_BRACE", 3916 if (ERROR("WHILE_AFTER_BRACE",
3905 "while should follow close brace '}'\n" . $hereprev); 3917 "while should follow close brace '}'\n" . $hereprev) &&
3918 $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
3919 fix_delete_line($fixlinenr - 1, $prevrawline);
3920 fix_delete_line($fixlinenr, $rawline);
3921 my $fixedline = $prevrawline;
3922 my $trailing = $rawline;
3923 $trailing =~ s/^\+//;
3924 $trailing = trim($trailing);
3925 $fixedline =~ s/}\s*$/} $trailing/;
3926 fix_insert_line($fixlinenr, $fixedline);
3927 }
3906 } 3928 }
3907 } 3929 }
3908 3930