diff options
author | Joe Perches <joe@perches.com> | 2013-07-03 18:05:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:45 -0400 |
commit | 179f8f40fc3ae7cd49e96b3a7d5182166c36bdab (patch) | |
tree | b2660986886bf926f82efd7960b40db57c0f350c /scripts/checkpatch.pl | |
parent | 77b9a53a627491df83a75361440485629c35aa91 (diff) |
checkpatch: add a --strict test for comparison to true/false
Comparing to true or false is error prone.
Add tests for the various forms of (foo == true) && (false != bar)
that are only reported with --strict.
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-x | scripts/checkpatch.pl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c43be815cc71..c2d223c406e8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -3588,6 +3588,33 @@ sub process { | |||
3588 | "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr); | 3588 | "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr); |
3589 | } | 3589 | } |
3590 | 3590 | ||
3591 | # check for comparisons against true and false | ||
3592 | if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) { | ||
3593 | my $lead = $1; | ||
3594 | my $arg = $2; | ||
3595 | my $test = $3; | ||
3596 | my $otype = $4; | ||
3597 | my $trail = $5; | ||
3598 | my $op = "!"; | ||
3599 | |||
3600 | ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i); | ||
3601 | |||
3602 | my $type = lc($otype); | ||
3603 | if ($type =~ /^(?:true|false)$/) { | ||
3604 | if (("$test" eq "==" && "$type" eq "true") || | ||
3605 | ("$test" eq "!=" && "$type" eq "false")) { | ||
3606 | $op = ""; | ||
3607 | } | ||
3608 | |||
3609 | CHK("BOOL_COMPARISON", | ||
3610 | "Using comparison to $otype is error prone\n" . $herecurr); | ||
3611 | |||
3612 | ## maybe suggesting a correct construct would better | ||
3613 | ## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr); | ||
3614 | |||
3615 | } | ||
3616 | } | ||
3617 | |||
3591 | # check for semaphores initialized locked | 3618 | # check for semaphores initialized locked |
3592 | if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { | 3619 | if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { |
3593 | WARN("CONSIDER_COMPLETION", | 3620 | WARN("CONSIDER_COMPLETION", |