From: Julia Lawall <julia.lawall@inria.fr>
To: Joe Perches <joe@perches.com>
Cc: cocci <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] linux: bad logic in repetitive tests
Date: Tue, 31 Mar 2020 11:12:11 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.21.2003311111050.3188@hadrien> (raw)
In-Reply-To: <471262a54c6919efe62917ec2beb43e6bd45e0b1.camel@perches.com>
On Tue, 31 Mar 2020, Joe Perches wrote:
> On Tue, 2020-03-31 at 10:50 +0200, Julia Lawall wrote:
> > On Mon, 30 Mar 2020, Joe Perches wrote:
> >
> > > There is a block of if tests against the same variable
> > > in include/linux/mtd/pfow.h that likely is defective
> > >
> > > if (prog_status & 0x3)
> > > ...
> > > else if (prog_status & 0x2)
> > > ...
> > > else (prog_status & 0x1)
> > > ...
> > >
> > > If the first test is true the subsequent 2 tests aren't
> > > possible.
> > >
> > > Likely the first test should be something like
> > >
> > > if ((prog_status & 0x03) == 0x03)
> > >
> > > Is there a way for cocci to find this style of bitwise
> > > logic defect?
> >
> > I guess this occurs rarely enough that just looking for a succession of
> > bit and tests on the same variable would be good enough to narrow it down
> > to something manageable to check by hand.
>
> I suppose, but I think misuse of the and'ed bits
> by #define is the most likely defect as it's
> very difficult to verify visually.
>
> Hard to otherwise quantify.
OK, I see that the pattern of a sequence of bit ands is actually quite
common. It should be possible to make something more automatic.
julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
prev parent reply other threads:[~2020-03-31 9:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 0:52 [Cocci] linux: bad logic in repetitive tests Joe Perches
2020-03-31 8:50 ` Julia Lawall
2020-03-31 9:02 ` Joe Perches
2020-03-31 9:12 ` Julia Lawall [this message]
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=alpine.DEB.2.21.2003311111050.3188@hadrien \
--to=julia.lawall@inria.fr \
--cc=cocci@systeme.lip6.fr \
--cc=joe@perches.com \
/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).