public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
	Dmitry Rokosov <DDRokosov@sberdevices.ru>,
	Jagath Jog J <jagathjog1996@gmail.com>,
	Cosmin Tanislav <demonsingur@gmail.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer
Date: Fri, 21 Oct 2022 14:02:08 +0300	[thread overview]
Message-ID: <eb6ce47a-ab87-8a98-7ffe-b8cc50f8a549@gmail.com> (raw)
In-Reply-To: <Y1J5KiH6IJLmrWH4@smile.fi.intel.com>

On 10/21/22 13:49, Andy Shevchenko wrote:
> 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()?

Yes! Thanks.

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

Ah, yes! This was really a bug making it way in. I guess you may just 
have saved me from some not-that-funny debugging session... Well spotted!

I still don't like hiding the IRQ_HANDLED / IRQ_NONE. I'll just go for

         if (data->state & KX022A_STATE_FIFO) { 

                 int ok; 

 

                 ok = __kx022a_fifo_flush(idev, KX022A_FIFO_LENGTH, 
true);
                 if (ok > 0) 

                         ret = IRQ_HANDLED; 

         }

for v4. (Which I try to send still today before my memory is flushed by 
the weekend :])

Thanks a lot!

Yours
	-- Matti

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


  reply	other threads:[~2022-10-21 11:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 11:35 [PATCH v3 0/3] iio: Support ROHM/Kionix kx022a Matti Vaittinen
2022-10-20 11:36 ` [PATCH v3 1/3] dt-bindings: iio: Add KX022A accelerometer Matti Vaittinen
2022-10-20 13:44   ` Krzysztof Kozlowski
2022-10-20 11:37 ` [PATCH v3 2/3] iio: accel: Support Kionix/ROHM " Matti Vaittinen
2022-10-20 14:34   ` Andy Shevchenko
2022-10-21  7:10     ` Matti Vaittinen
2022-10-21 10:49       ` Andy Shevchenko
2022-10-21 11:02         ` Matti Vaittinen [this message]
2022-10-20 11:37 ` [PATCH v3 3/3] MAINTAINERS: Add KX022A maintainer entry Matti Vaittinen
2022-10-20 11:54 ` [PATCH v3 0/3] iio: Support ROHM/Kionix kx022a Matti Vaittinen
2022-10-20 12:04   ` Matti Vaittinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb6ce47a-ab87-8a98-7ffe-b8cc50f8a549@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=DDRokosov@sberdevices.ru \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=demonsingur@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jagathjog1996@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=nikita.yoush@cogentembedded.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox