Re: [PATCH 6/6] iio: adc: ad7173: Add support for AD411x devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> >  
> > >> +               case IIO_CURRENT:
> > >> +                       *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel);
> > >> +                       *val /= AD4111_SHUNT_RESISTOR_OHM;
> > >> +                       *val2 = chan->scan_type.realbits - !!(ch->cfg.bipolar);  
> > >
> > > Static analysis tools like to complain about using bool as int.
> > > Probably more clear to write it as (ch->cfg.bipolar ? 1 : 0) anyway.
> > >  
> > Maybe it does not apply here, but i followed this advice:
> >
> > Andy Shevchenko V1 of AD7173 (named initially ad717x)
> > "  
> > > +     return (bool)(value & mask);  
> >
> > This is weird. You have int which you get from bool, wouldn't be better
> > to use
> > !!(...) as other GPIO drivers do?  
> 
> As long as the build bots don't complain, there isn't a reason to
> change it. It is just a matter of personal preference at that point.
> 
> I got a sparse warning for something like this recently [1], but maybe
> that case was just because it was inside of a FIELD_PREP() using it as
> bit logic instead of addition and we won't get any warnings here.
> 
> [1]: https://lore.kernel.org/linux-iio/20240129195611.701611-3-dlechner@xxxxxxxxxxxx/

It was common to use !! for a number of years, but then it got a
comment from Linus Torvalds making reasonable point that it isn't
easy to read, so slight preference these days is for a ternary.








[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux