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.
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.
Best Regards
Michał Mirosław