If we have sufficient context detect and handle do without braces ({). Else these incorrectly trigger a trailing statements error for the associated while.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -1051,6 +1051,7 @@ sub process { · 1050 unmodified lines | |||
| 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 { · 99 unmodified lines | |||
| 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 { · 139 unmodified lines | |||
| 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 { · 642 unmodified lines | |||
| 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*\(.*[^<>!=]=[^=].*/) { |