aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-08-06 19:11:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 21:01:28 -0400
commit8d1824780f2f1786db5e0e7a54bbae75340c655c (patch)
tree802aa6870a881f28a4851a79b8240892ca2ef301 /scripts/checkpatch.pl
parentbd474ca076af8ac6fa8c5f4167f6024b446a08c8 (diff)
checkpatch: add --fix option for a couple OPEN_BRACE misuses
Style misuses of these types are corrected: typedef struct foo { int bar; }; int foo(int bar) { return bar+1; } int foo(int bar) { return bar+1; } 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.pl33
1 files changed, 28 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 569ba315823e..1e95953b488f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3164,17 +3164,40 @@ sub process {
3164 3164
3165# function brace can't be on same line, except for #defines of do while, 3165# function brace can't be on same line, except for #defines of do while,
3166# or if closed on same line 3166# or if closed on same line
3167 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and 3167 if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and
3168 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { 3168 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
3169 ERROR("OPEN_BRACE", 3169 if (ERROR("OPEN_BRACE",
3170 "open brace '{' following function declarations go on the next line\n" . $herecurr); 3170 "open brace '{' following function declarations go on the next line\n" . $herecurr) &&
3171 $fix) {
3172 fix_delete_line($fixlinenr, $rawline);
3173 my $fixed_line = $rawline;
3174 $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*){(.*)$/;
3175 my $line1 = $1;
3176 my $line2 = $2;
3177 fix_insert_line($fixlinenr, ltrim($line1));
3178 fix_insert_line($fixlinenr, "\+{");
3179 if ($line2 !~ /^\s*$/) {
3180 fix_insert_line($fixlinenr, "\+\t" . trim($line2));
3181 }
3182 }
3171 } 3183 }
3172 3184
3173# open braces for enum, union and struct go on the same line. 3185# open braces for enum, union and struct go on the same line.
3174 if ($line =~ /^.\s*{/ && 3186 if ($line =~ /^.\s*{/ &&
3175 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { 3187 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
3176 ERROR("OPEN_BRACE", 3188 if (ERROR("OPEN_BRACE",
3177 "open brace '{' following $1 go on the same line\n" . $hereprev); 3189 "open brace '{' following $1 go on the same line\n" . $hereprev) &&
3190 $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
3191 fix_delete_line($fixlinenr - 1, $prevrawline);
3192 fix_delete_line($fixlinenr, $rawline);
3193 my $fixedline = rtrim($prevrawline) . " {";
3194 fix_insert_line($fixlinenr, $fixedline);
3195 $fixedline = $rawline;
3196 $fixedline =~ s/^(.\s*){\s*/$1\t/;
3197 if ($fixedline !~ /^\+\s*$/) {
3198 fix_insert_line($fixlinenr, $fixedline);
3199 }
3200 }
3178 } 3201 }
3179 3202
3180# missing space after union, struct or enum definition 3203# missing space after union, struct or enum definition