From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [bug report] Input: elants_i2c - add support for eKTF3624
Date: Fri, 29 Jan 2021 00:21:08 +0100 [thread overview]
Message-ID: <20210128232108.GA11394@qmqm.qmqm.pl> (raw)
In-Reply-To: <20210128143726.GT20820@kadam>
On Thu, Jan 28, 2021 at 05:37:26PM +0300, Dan Carpenter wrote:
> On Thu, Jan 28, 2021 at 02:07:05PM +0100, Michał Mirosław wrote:
> > On Thu, Jan 28, 2021 at 12:57:12PM +0300, Dan Carpenter wrote:
> > > Hello Michał Mirosław,
> > >
> > > The patch 9517b95bdc46: "Input: elants_i2c - add support for
> > > eKTF3624" from Jan 24, 2021, leads to the following static checker
> > > warning:
> > >
> > > drivers/input/touchscreen/elants_i2c.c:966 elants_i2c_mt_event()
> > > warn: should this be a bitwise negate mask?
> > >
> > > drivers/input/touchscreen/elants_i2c.c
> > [...]
> > > 963 w = buf[FW_POS_WIDTH + i / 2];
> > > 964 w >>= 4 * (~i & 1);
> > > 965 w |= w << 4;
> > > 966 w |= !w;
> > > ^^^^^^^^
> > >
> > > This code is just very puzzling. I think it may actually be correct?
> > > The boring and conventional way to write this would be to do it like so:
> > >
> > > if (!w)
> > > w = 1;
> >
> > It could also be written as:
> >
> > w += !w;
> >
> > or:
> > w += w == 0;`
> >
> > while avoiding conditional.
>
> Is there some kind of prize for avoiding if statements??
Less LOC and an occassional puzzle, of course. :-) Considering your
examples below I can see where the check came from. I wouldn't object
to a patch changing the code or adding a comment on what it does (it
maps a selected nibble value (0..15) to a byte (1..255) spreading the
values evenly).
> > But, in this case, the warning is bogus. Because w | ~w == all-ones (always),
> > it might as well suggested to write:
> >
> > w = -1;
> >
> > or:
> > w = ~0;
> >
> > making the code broken.
>
> Yeah. The rule is just a simple heuristic of a logical negate used
> with a bitwise operation.
[...]
Maybe it could differentiate between "|= !x" and "&= !x", the second one
being more suspicious? I must say that 'x | !x' idiom looks obvious
as other sigle-operator-letter misspellings ('x | ~x' and 'x || !x')
beg the question of why the constant wasn't used directly?
Best Regards
Michał Mirosław
prev parent reply other threads:[~2021-01-28 23:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-28 9:57 [bug report] Input: elants_i2c - add support for eKTF3624 Dan Carpenter
2021-01-28 13:07 ` Michał Mirosław
2021-01-28 14:37 ` Dan Carpenter
2021-01-28 23:21 ` Michał Mirosław [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=20210128232108.GA11394@qmqm.qmqm.pl \
--to=mirq-linux@rere.qmqm.pl \
--cc=dan.carpenter@oracle.com \
--cc=linux-input@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.