diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ea6d0f3fc057..8be5297d18b6 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -1656,6 +1656,17 @@ sub get_stat_real { | |||
| 1656 | return $stat_real; | 1656 | return $stat_real; |
| 1657 | } | 1657 | } |
| 1658 | 1658 | ||
| 1659 | sub get_stat_here { | ||
| 1660 | my ($linenr, $cnt, $here) = @_; | ||
| 1661 | |||
| 1662 | my $herectx = $here . "\n"; | ||
| 1663 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 1664 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | return $herectx; | ||
| 1668 | } | ||
| 1669 | |||
| 1659 | sub cat_vet { | 1670 | sub cat_vet { |
| 1660 | my ($vet) = @_; | 1671 | my ($vet) = @_; |
| 1661 | my ($res, $coded); | 1672 | my ($res, $coded); |
| @@ -4967,12 +4978,8 @@ sub process { | |||
| 4967 | #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; | 4978 | #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; |
| 4968 | 4979 | ||
| 4969 | $ctx =~ s/\n*$//; | 4980 | $ctx =~ s/\n*$//; |
| 4970 | my $herectx = $here . "\n"; | ||
| 4971 | my $stmt_cnt = statement_rawlines($ctx); | 4981 | my $stmt_cnt = statement_rawlines($ctx); |
| 4972 | 4982 | my $herectx = get_stat_here($linenr, $stmt_cnt, $here); | |
| 4973 | for (my $n = 0; $n < $stmt_cnt; $n++) { | ||
| 4974 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 4975 | } | ||
| 4976 | 4983 | ||
| 4977 | if ($dstat ne '' && | 4984 | if ($dstat ne '' && |
| 4978 | $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), | 4985 | $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), |
| @@ -5044,12 +5051,9 @@ sub process { | |||
| 5044 | # check for macros with flow control, but without ## concatenation | 5051 | # check for macros with flow control, but without ## concatenation |
| 5045 | # ## concatenation is commonly a macro that defines a function so ignore those | 5052 | # ## concatenation is commonly a macro that defines a function so ignore those |
| 5046 | if ($has_flow_statement && !$has_arg_concat) { | 5053 | if ($has_flow_statement && !$has_arg_concat) { |
| 5047 | my $herectx = $here . "\n"; | ||
| 5048 | my $cnt = statement_rawlines($ctx); | 5054 | my $cnt = statement_rawlines($ctx); |
| 5055 | my $herectx = get_stat_here($linenr, $cnt, $here); | ||
| 5049 | 5056 | ||
| 5050 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 5051 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 5052 | } | ||
| 5053 | WARN("MACRO_WITH_FLOW_CONTROL", | 5057 | WARN("MACRO_WITH_FLOW_CONTROL", |
| 5054 | "Macros with flow control statements should be avoided\n" . "$herectx"); | 5058 | "Macros with flow control statements should be avoided\n" . "$herectx"); |
| 5055 | } | 5059 | } |
| @@ -5089,11 +5093,7 @@ sub process { | |||
| 5089 | 5093 | ||
| 5090 | $ctx =~ s/\n*$//; | 5094 | $ctx =~ s/\n*$//; |
| 5091 | my $cnt = statement_rawlines($ctx); | 5095 | my $cnt = statement_rawlines($ctx); |
| 5092 | my $herectx = $here . "\n"; | 5096 | my $herectx = get_stat_here($linenr, $cnt, $here); |
| 5093 | |||
| 5094 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 5095 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 5096 | } | ||
| 5097 | 5097 | ||
| 5098 | if (($stmts =~ tr/;/;/) == 1 && | 5098 | if (($stmts =~ tr/;/;/) == 1 && |
| 5099 | $stmts !~ /^\s*(if|while|for|switch)\b/) { | 5099 | $stmts !~ /^\s*(if|while|for|switch)\b/) { |
| @@ -5107,11 +5107,7 @@ sub process { | |||
| 5107 | } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) { | 5107 | } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) { |
| 5108 | $ctx =~ s/\n*$//; | 5108 | $ctx =~ s/\n*$//; |
| 5109 | my $cnt = statement_rawlines($ctx); | 5109 | my $cnt = statement_rawlines($ctx); |
| 5110 | my $herectx = $here . "\n"; | 5110 | my $herectx = get_stat_here($linenr, $cnt, $here); |
| 5111 | |||
| 5112 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 5113 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 5114 | } | ||
| 5115 | 5111 | ||
| 5116 | WARN("TRAILING_SEMICOLON", | 5112 | WARN("TRAILING_SEMICOLON", |
| 5117 | "macros should not use a trailing semicolon\n" . "$herectx"); | 5113 | "macros should not use a trailing semicolon\n" . "$herectx"); |
| @@ -5234,12 +5230,8 @@ sub process { | |||
| 5234 | } | 5230 | } |
| 5235 | } | 5231 | } |
| 5236 | if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { | 5232 | if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { |
| 5237 | my $herectx = $here . "\n"; | ||
| 5238 | my $cnt = statement_rawlines($block); | 5233 | my $cnt = statement_rawlines($block); |
| 5239 | 5234 | my $herectx = get_stat_here($linenr, $cnt, $here); | |
| 5240 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 5241 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
| 5242 | } | ||
| 5243 | 5235 | ||
| 5244 | WARN("BRACES", | 5236 | WARN("BRACES", |
| 5245 | "braces {} are not necessary for single statement blocks\n" . $herectx); | 5237 | "braces {} are not necessary for single statement blocks\n" . $herectx); |
| @@ -6096,11 +6088,9 @@ sub process { | |||
| 6096 | } | 6088 | } |
| 6097 | if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && | 6089 | if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && |
| 6098 | !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { | 6090 | !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { |
| 6099 | my $herectx = $here . "\n"; | ||
| 6100 | my $cnt = statement_rawlines($stat); | 6091 | my $cnt = statement_rawlines($stat); |
| 6101 | for (my $n = 0; $n < $cnt; $n++) { | 6092 | my $herectx = get_stat_here($linenr, $cnt, $here); |
| 6102 | $herectx .= raw_line($linenr, $n) . "\n"; | 6093 | |
| 6103 | } | ||
| 6104 | if (WARN("ALLOC_WITH_MULTIPLY", | 6094 | if (WARN("ALLOC_WITH_MULTIPLY", |
| 6105 | "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && | 6095 | "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && |
| 6106 | $cnt == 1 && | 6096 | $cnt == 1 && |
| @@ -6183,11 +6173,9 @@ sub process { | |||
| 6183 | if ($^V && $^V ge 5.10.0 && | 6173 | if ($^V && $^V ge 5.10.0 && |
| 6184 | defined $stat && | 6174 | defined $stat && |
| 6185 | $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) { | 6175 | $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) { |
| 6186 | my $herectx = $here . "\n"; | ||
| 6187 | my $cnt = statement_rawlines($stat); | 6176 | my $cnt = statement_rawlines($stat); |
| 6188 | for (my $n = 0; $n < $cnt; $n++) { | 6177 | my $herectx = get_stat_here($linenr, $cnt, $here); |
| 6189 | $herectx .= raw_line($linenr, $n) . "\n"; | 6178 | |
| 6190 | } | ||
| 6191 | WARN("DEFAULT_NO_BREAK", | 6179 | WARN("DEFAULT_NO_BREAK", |
| 6192 | "switch default: should use break\n" . $herectx); | 6180 | "switch default: should use break\n" . $herectx); |
| 6193 | } | 6181 | } |
