lkml.org 
[lkml]   [2023]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 2/2] iio: adc: Add TI ADS1100 and ADS1000
On Sat, Mar 04, 2023 at 05:57:51PM +0000, Jonathan Cameron wrote:
> On Tue, 28 Feb 2023 07:31:51 +0100
> Mike Looijmans <mike.looijmans@topic.nl> wrote:

...

> > + for (i = 0; i < 4; i++) {
> > + if (BIT(i) == gain) {
> > + ads1100_set_config_bits(data, ADS1100_PGA_MASK, i);
> > + return 0;
> > + }
> > + }
> Andy's suggestion of something like..
> if (!gain)
> return -EINVAL;
> i = ffs(gain);
> if (i >= 4 || BIT(i) != gain)
> return -EINVAL;
>
> ads...
>
> Is perhaps nicer than the loop.

Even better:

if (!gain || !is_power_of_2(gain))
return -EINVAL;

i = ffs(gain);
if (i >= 4)
return -EINVAL;

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2023-03-27 00:45    [W:0.189 / U:0.436 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site