Re: drivers/iio/adc/axp20x_adc.c:572:26: sparse: sparse: dubious: x & !y

From: Andy Shevchenko
Date: Sun Jan 07 2024 - 14:47:10 EST


On Sun, Jan 7, 2024 at 7:37 AM Chen-Yu Tsai <wens@xxxxxxxx> wrote:
> On Sun, Jan 7, 2024 at 9:30 AM kernel test robot <lkp@xxxxxxxxx> wrote:

...

> > sparse warnings: (new ones prefixed by >>)
> > >> drivers/iio/adc/axp20x_adc.c:572:26: sparse: sparse: dubious: x & !y
> > drivers/iio/adc/axp20x_adc.c:577:26: sparse: sparse: dubious: x & !y
>
> This looks like a false positive. The code is doing exactly what we want:
> val = val ? 1 : 0, but in a shorter format.

Yes, but the problem is that FIELD_PREP() is a macro.
You can replace these by ternary (here and in other cases) to satisfy
sparse. Compiler will optimize that anyway, so no branch is expected
in the generated code.

--
With Best Regards,
Andy Shevchenko