Re: [PATCH v3 2/2] iio: adc: Add TI ADS1100 and ADS1000

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

 



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@xxxxxxxx> 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





[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