From: "Bjørn Mork" <bjorn@mork.no>
To: Dave Jones <davej@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Joe Perches <joe@perches.com>, Andy Whitcroft <apw@shadowen.org>,
LKML <linux-kernel@vger.kernel.org>,
Jacob Pan <jacob.jun.pan@linux.intel.com>
Subject: Re: [PATCH] checkpatch: Warn on comparisons to true and false
Date: Thu, 11 Apr 2013 13:56:54 +0200 [thread overview]
Message-ID: <878v4pwa9l.fsf@nemi.mork.no> (raw)
In-Reply-To: <20130411021415.GA16118@redhat.com> (Dave Jones's message of "Wed, 10 Apr 2013 22:14:15 -0400")
Dave Jones <davej@redhat.com> writes:
> On Wed, Apr 10, 2013 at 03:57:51PM -0700, Andrew Morton wrote:
> > On Tue, 09 Apr 2013 20:17:14 -0700 Joe Perches <joe@perches.com> wrote:
> >
> > > Comparisons of A to true and false are better written
> > > as A and !A.
> > >
> > > Bleat a message on use.
> >
> > hm. I'm counting around 1,100 instances of "== true" and "== false".
> >
> > That's a lot of people to shout at. Is it really worthwhile?
> > "foo==true" is a bit of a waste of space but I can't say that I find it
> > terribly offensive.
>
> It would be interesting to see how many people have historically screwed
> up and used (!a) when they mean (a) and vice versa, versus spelling
> it out longform. I'd be surprised if the results weren't skewed
> in favour of the more verbose form.
You have to consider that it is still possible to reverse the operator
even if spelling it out, so you don't really gain anything:
bjorn@nemi:/usr/local/src/git/linux$ git grep -E '!=\s*(true|false)'|wc -l
63
and since most of these compare to true, they are also at risk wrt
integers:
bjorn@nemi:/usr/local/src/git/linux$ git grep -E '!=\s*true'|wc -l
54
Based on a quick look at a few of these I guess they are mostly OK,
testing against bool values. But I felt I had to share this little gem
which showed up in drivers/gpu/drm/exynos/exynos_drm_vidi.c:
static int vidi_power_on(struct vidi_context *ctx, bool enable)
{
struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
struct device *dev = subdrv->dev;
DRM_DEBUG_KMS("%s\n", __FILE__);
if (enable != false && enable != true)
return -EINVAL;
..
That's taking failsafe to the next step :)
Bjørn
next prev parent reply other threads:[~2013-04-11 11:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-10 3:17 [PATCH] checkpatch: Warn on comparisons to true and false Joe Perches
2013-04-10 9:33 ` Andy Whitcroft
2013-04-10 11:27 ` Joe Perches
2013-04-10 12:41 ` Andy Whitcroft
2013-04-10 22:57 ` Andrew Morton
2013-04-11 1:07 ` Joe Perches
2013-04-11 2:14 ` Dave Jones
2013-04-11 3:47 ` Joe Perches
2013-04-11 8:19 ` Dan Carpenter
2013-04-11 8:29 ` Joe Perches
2013-04-11 11:56 ` Bjørn Mork [this message]
2013-04-11 14:25 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878v4pwa9l.fsf@nemi.mork.no \
--to=bjorn@mork.no \
--cc=akpm@linux-foundation.org \
--cc=apw@shadowen.org \
--cc=davej@redhat.com \
--cc=jacob.jun.pan@linux.intel.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).