From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] linux: bad logic in repetitive tests
Date: Tue, 31 Mar 2020 02:02:42 -0700 [thread overview]
Message-ID: <471262a54c6919efe62917ec2beb43e6bd45e0b1.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2003311048341.3188@hadrien>
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.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-03-31 10:22 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 [this message]
2020-03-31 9:12 ` Julia Lawall
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=471262a54c6919efe62917ec2beb43e6bd45e0b1.camel@perches.com \
--to=joe@perches.com \
--cc=cocci@systeme.lip6.fr \
--cc=julia.lawall@inria.fr \
/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).