Re: [PATCH v3 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer

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

 



On Fri, Oct 21, 2022 at 10:10:08AM +0300, Matti Vaittinen wrote:
> On 10/20/22 17:34, Andy Shevchenko wrote:
> > On Thu, Oct 20, 2022 at 02:37:15PM +0300, Matti Vaittinen wrote:

...

> > > +	ret = regmap_bulk_read(data->regmap, chan->address, &data->buffer,
> > > +			       sizeof(__le16));
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	*val = le16_to_cpu(data->buffer[0]);
> > 
> > 'p'-variant of the above would look better
> > 
> > 	*val = le16_to_cpup(data->buffer);
> > 
> > since it will be the same as above address without any additional arithmetics.
> > 
> 
> I guess there is no significant performance difference? To my eye the
> le16_to_cpu(data->buffer[0]) is much more clear. I see right from the call
> that we have an array here and use the first member. If there is no obvious
> technical merit for using le16_to_cpup(data->buffer) over
> le16_to_cpu(data->buffer[0]), then I do really prefer the latter for
> clarity.

Then you probably wanted to have &data->buffer[0] as a parameter to
regmap_bulk_read()?

...

> > > +	if (data->trigger_enabled) {
> > > +		iio_trigger_poll_chained(data->trig);
> > > +		ret = IRQ_HANDLED;
> > > +	}
> > > +
> > > +	if (data->state & KX022A_STATE_FIFO) {
> > 
> > > +		ret = __kx022a_fifo_flush(idev, KX022A_FIFO_LENGTH, true);
> > > +		if (ret > 0)
> > > +			ret = IRQ_HANDLED;
> > 
> > I don't like it. Perhaps
> > 
> > 	bool handled = false;
> > 	int ret;
> > 
> > 	...
> > 		ret = ...
> > 		if (ret > 0)
> > 			handled = true;
> > 	...
> > 
> > 	return IRQ_RETVAL(handled);
> 
> I don't see the benefit of adding another variable 'handled'.
> If I understand correctly, it just introduces one extra 'if' in IRQ thread
> handling while hiding the return value in IRQ_RETVAL() - macro.
> 
> I do like seeing the IRQ_NONE being returned by default and IRQ_HANDLED only
> when "handlers" are successfully executed. Adding extra variable just
> obfuscates this (from my eyes) while adding also the additional 'if'.

You assigning semantically different values to the same variable inside the
function.

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