diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2287a0bca863..143ab5ca2c41 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -4496,6 +4496,30 @@ sub process { | |||
| 4496 | } | 4496 | } |
| 4497 | } | 4497 | } |
| 4498 | 4498 | ||
| 4499 | # check for unnecessary parentheses around comparisons in if uses | ||
| 4500 | if ($^V && $^V ge 5.10.0 && defined($stat) && | ||
| 4501 | $stat =~ /(^.\s*if\s*($balanced_parens))/) { | ||
| 4502 | my $if_stat = $1; | ||
| 4503 | my $test = substr($2, 1, -1); | ||
| 4504 | my $herectx; | ||
| 4505 | while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) { | ||
| 4506 | my $match = $1; | ||
| 4507 | # avoid parentheses around potential macro args | ||
| 4508 | next if ($match =~ /^\s*\w+\s*$/); | ||
| 4509 | if (!defined($herectx)) { | ||
| 4510 | $herectx = $here . "\n"; | ||
| 4511 | my $cnt = statement_rawlines($if_stat); | ||
| 4512 | for (my $n = 0; $n < $cnt; $n++) { | ||
| 4513 | my $rl = raw_line($linenr, $n); | ||
| 4514 | $herectx .= $rl . "\n"; | ||
| 4515 | last if $rl =~ /^[ \+].*\{/; | ||
| 4516 | } | ||
| 4517 | } | ||
| 4518 | CHK("UNNECESSARY_PARENTHESES", | ||
| 4519 | "Unnecessary parentheses around '$match'\n" . $herectx); | ||
| 4520 | } | ||
| 4521 | } | ||
| 4522 | |||
| 4499 | #goto labels aren't indented, allow a single space however | 4523 | #goto labels aren't indented, allow a single space however |
| 4500 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and | 4524 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
| 4501 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { | 4525 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
