[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130410093346.GO7511@dm>
Date: Wed, 10 Apr 2013 10:33:46 +0100
From: Andy Whitcroft <apw@...dowen.org>
To: Joe Perches <joe@...ches.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>,
Jacob Pan <jacob.jun.pan@...ux.intel.com>
Subject: Re: [PATCH] checkpatch: Warn on comparisons to true and false
On Tue, Apr 09, 2013 at 08:17:14PM -0700, Joe Perches wrote:
> Comparisons of A to true and false are better written
> as A and !A.
>
> Bleat a message on use.
>
> Signed-off-by: Joe Perches <joe@...ches.com>
> ---
> scripts/checkpatch.pl | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 3fb6d86..080e7f6 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3538,6 +3538,23 @@ sub process {
> "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
> }
>
> +# check for comparisons against true and false
> + if ($line =~ /\+\s*(.*?)($Lval)\s*(==|\!=)\s*(true|false)\b(.*)$/i) {
> + my $lead = $1;
> + my $arg = $2;
> + my $test = $3;
> + my $otype = $4;
> + my $trail = $5;
> + my $type = lc($otype);
> + my $op = "!";
> + if (("$test" eq "==" && "$type" eq "true") ||
> + ("$test" eq "!=" && "$type" eq "false")) {
> + $op = "";
> + }
> + WARN("BOOL_COMPARISON",
> + "Using comparison to $otype is poor style. Use '${lead}${op}${arg}${trail}'\n" . $herecurr);
In a complex case such as a + b == false will this do the right thing?
Not that I am sure that adding bools makes sense but assuming there is
some valid complex lval.
-apw
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists