diff options
author | Andy Whitcroft <apw@shadowen.org> | 2008-10-16 01:02:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 14:21:37 -0400 |
commit | 170d3a22688f06fda42e353bbccd0f3df89f3d94 (patch) | |
tree | 77dda2b9e7890d95452cfe3255d8d83187be579a /scripts | |
parent | a6a84062821738426ed4f58f4d584ecb7feb3dee (diff) |
checkpatch: handle do without braces if we have enough context
If we have sufficient context detect and handle do without braces ({).
Else these incorrectly trigger a trailing statements error for the
associated while.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 17e1d94fa1fa..19690a2ddb74 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -1051,6 +1051,7 @@ sub process { | |||
1051 | 1051 | ||
1052 | # suppression flags | 1052 | # suppression flags |
1053 | my %suppress_ifbraces; | 1053 | my %suppress_ifbraces; |
1054 | my %suppress_whiletrailers; | ||
1054 | 1055 | ||
1055 | # Pre-scan the patch sanitizing the lines. | 1056 | # Pre-scan the patch sanitizing the lines. |
1056 | # Pre-scan the patch looking for any __setup documentation. | 1057 | # Pre-scan the patch looking for any __setup documentation. |
@@ -1156,6 +1157,7 @@ sub process { | |||
1156 | $prev_values = 'E'; | 1157 | $prev_values = 'E'; |
1157 | 1158 | ||
1158 | %suppress_ifbraces = (); | 1159 | %suppress_ifbraces = (); |
1160 | %suppress_whiletrailers = (); | ||
1159 | next; | 1161 | next; |
1160 | 1162 | ||
1161 | # track the line number as we move through the hunk, note that | 1163 | # track the line number as we move through the hunk, note that |
@@ -1301,9 +1303,9 @@ sub process { | |||
1301 | } | 1303 | } |
1302 | 1304 | ||
1303 | # Check for potential 'bare' types | 1305 | # Check for potential 'bare' types |
1304 | my ($stat, $cond, $line_nr_next, $remain_next); | 1306 | my ($stat, $cond, $line_nr_next, $remain_next, $off_next); |
1305 | if ($realcnt && $line =~ /.\s*\S/) { | 1307 | if ($realcnt && $line =~ /.\s*\S/) { |
1306 | ($stat, $cond, $line_nr_next, $remain_next) = | 1308 | ($stat, $cond, $line_nr_next, $remain_next, $off_next) = |
1307 | ctx_statement_block($linenr, $realcnt, 0); | 1309 | ctx_statement_block($linenr, $realcnt, 0); |
1308 | $stat =~ s/\n./\n /g; | 1310 | $stat =~ s/\n./\n /g; |
1309 | $cond =~ s/\n./\n /g; | 1311 | $cond =~ s/\n./\n /g; |
@@ -1952,7 +1954,26 @@ sub process { | |||
1952 | 1954 | ||
1953 | # Check for illegal assignment in if conditional -- and check for trailing | 1955 | # Check for illegal assignment in if conditional -- and check for trailing |
1954 | # statements after the conditional. | 1956 | # statements after the conditional. |
1955 | if ($line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { | 1957 | if ($line =~ /do\s*(?!{)/) { |
1958 | my ($stat_next) = ctx_statement_block($line_nr_next, | ||
1959 | $remain_next, $off_next); | ||
1960 | $stat_next =~ s/\n./\n /g; | ||
1961 | ##print "stat<$stat> stat_next<$stat_next>\n"; | ||
1962 | |||
1963 | if ($stat_next =~ /^\s*while\b/) { | ||
1964 | # If the statement carries leading newlines, | ||
1965 | # then count those as offsets. | ||
1966 | my ($whitespace) = | ||
1967 | ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s); | ||
1968 | my $offset = | ||
1969 | statement_rawlines($whitespace) - 1; | ||
1970 | |||
1971 | $suppress_whiletrailers{$line_nr_next + | ||
1972 | $offset} = 1; | ||
1973 | } | ||
1974 | } | ||
1975 | if (!defined $suppress_whiletrailers{$linenr} && | ||
1976 | $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { | ||
1956 | my ($s, $c) = ($stat, $cond); | 1977 | my ($s, $c) = ($stat, $cond); |
1957 | 1978 | ||
1958 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { | 1979 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { |