devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Andy Shevchenko" <andriy.shevchenko@intel.com>,
	"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
	"Tobias Sperling" <tobias.sperling@softing.com>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Trevor Gamblin" <tgamblin@baylibre.com>,
	"Esteban Blanc" <eblanc@baylibre.com>,
	"Ramona Alexandra Nechita" <ramona.nechita@analog.com>,
	"Thomas Bonnefille" <thomas.bonnefille@bootlin.com>,
	"Hans de Goede" <hansg@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: adc: Support ROHM BD79112 ADC/GPIO
Date: Thu, 4 Sep 2025 15:35:36 +0300	[thread overview]
Message-ID: <43141a95-2267-44de-bd7e-11eb8c80090e@gmail.com> (raw)
In-Reply-To: <CAHp75Ve4vgU5kK3z3bZyGqDOPVkMbW7RUd6_EA3jjZSeruWs=Q@mail.gmail.com>

On 03/09/2025 16:29, Andy Shevchenko wrote:
> On Wed, Sep 3, 2025 at 3:14 PM Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>> On 03/09/2025 14:23, Andy Shevchenko wrote:
>>> On Wed, Sep 03, 2025 at 09:52:02AM +0300, Matti Vaittinen wrote:
>>>> On 02/09/2025 17:15, Andy Shevchenko wrote:
>>>>> On Tue, Sep 02, 2025 at 03:24:31PM +0300, Matti Vaittinen wrote:
> 
> ...
> 
>>>>>> +  data->vref_mv = ret / 1000;
>>>>>
>>>>> (MICRO / MILLI)
>>>>
>>>> I find this much more confusing than plain 1000. (I know we had this type of
>>>> discussion before. See [1] again).
>>>
>>> Rings a bell, but that's what IIO reviewers suggest to do nowadays as a
>>> compromise between creating a new bunch of unit (V) related definitions.
>>
>> I am sorry, but this just seems stupid to me. I'd say that it is very
>> obvious for most of the readers dividing microvolts by 1000 results
>> millivolts. And if it is not, then having this MICRO / MILLI is likely
>> to just cause more confusion.
> 
> No, it tells that we have a value in microSOMETHING that is converted
> to MILLIsomething.

No. I disagree. This tells that 'ret' from the regulator API is divided 
by some unknown value, which is a result of division of two odd defines. 
Especially odd because one would intuitively think MICRO is smaller than 
MILLI. You need to look up the definitions to understand WTF is really 
going on. I think this is plain terrible.

The fact that we store value in vref_mv should be enough of hint that 
idea is to have value in millivolts. Dividing by 1000 before assigning 
makes it 100% clear the ret is in microvolts even if you didn't know the 
regulator API to return micro volts.

>> I _really_ dislike these defines. Why is MILLI 1000? Why it isn't 0.001?
> 
> You know exactly a few reasons why it's not.
> 
>> It makes no sense that KILO and MILLI are the same. Especially not when
>> we are dealing with physics.
> 
> Yes, this is the limitation of computers and particularly of _a_ kernel.

No. In my opinion, this is an example of, hopefully unintentional, 
obfuscation where blindly following some paradigm like 'avoid plain 
numbers and always use named defines' just results things getting worse. 
That combined with bad naming. If KILO is 1000, then MILLI can't be 
1000. That's 1 per milli.

And still, the original "mv = uv / 1000" is superior in clarity. Using 
(MICRO / MILLI) there to avoid plain number is just a sign of blindly 
and religiously following some 'golden rule', even when it results worse 
code.

>> This is just an obfuscation compared to using plain 1000. (I kind of
>> understand having a define for a value like 100000 - where counting the
>> zeros gets cumbersome, although 100 * 1000 would be equally clear. But
>> 1000 _is_ really 100% clear, whereas MICRO / MILLI is not).
> 
> See above why this way.

I see no real justification to degrade this - other than "because I say 
so". Sorry but that's not really a good reason to me.

> ...
> 
>>>>>> +  gpio_pins = bd79112_get_gpio_pins(iio_dev->channels,
>>>>>> +                                    iio_dev->num_channels);
>>>>>
>>>>>> +
>>>>>
>>>>> Instead of leaving this rather unneeded blank line I would move above...
>>>>>
>>>>>> +  /* We're done if all channels are reserved for ADC. */
>>>>>
>>>>> ...to be here
>>>>>
>>>>>      gpio_pins = bd79112_get_gpio_pins(iio_dev->channels,
>>>>>                                        iio_dev->num_channels);
>>>>
>>>> I suppose you mean something like:
>>>>
>>>> register_gpios:
>>>>       /* We're done if all channels are reserved for ADC. */
>>>>       gpio_pins = bd79112_get_gpio_pins(iio_dev->channels,
>>>>                                             iio_dev->num_channels);
>>>>       if (!gpio_pins)
>>>>               return 0;
>>>>
>>>> right?
>>>
>>> Yes.
>>>
>>>> I don't like this because now the comment suggests we do call
>>>> bd79112_get_gpio_pins() only to see if all channels were for ADCs. This,
>>>> however, is not THE reason for this call, only an optimization. I think:
>>>> having:
>>>>
>>>>           /* We're done if all channels are reserved for ADC. */
>>>
>>> Then you can amend the comment
>>>
>>>            /* If all channels are reserved for ADC, we are done. */
>>>
>>>>           if (!gpio_pins)
>>>>                   return 0;
>>>>
>>>> is clearer.
>>>
>>> Which makes my approach sustainable.
>>
>> I like your wording better, but placing this comment before the call to
>> bd79112_get_gpio_pins() is still more confusing that placing it before
>> the actual check:
>>          if (!gpio_pins)
>> is still misleading. Comment applies to the check, not the retrieval.
> 
> The variable assignment, or i.o.w. the source of the value we are
> testing is also part of the equation.

The comment explains why the check, not why the value is obtained.

Yours,
	-- Matti

  reply	other threads:[~2025-09-04 12:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 12:23 [PATCH 0/3] Support ROHM BD79112 ADC Matti Vaittinen
2025-09-02 12:23 ` [PATCH 1/3] dt-bindings: iio: adc: ROHM BD79112 ADC/GPIO Matti Vaittinen
2025-09-02 17:57   ` Rob Herring (Arm)
2025-09-02 12:24 ` [PATCH 2/3] iio: adc: Support " Matti Vaittinen
2025-09-02 14:15   ` Andy Shevchenko
2025-09-03  6:52     ` Matti Vaittinen
2025-09-03 11:23       ` Andy Shevchenko
2025-09-03 12:14         ` Matti Vaittinen
2025-09-03 13:29           ` Andy Shevchenko
2025-09-04 12:35             ` Matti Vaittinen [this message]
2025-09-04 13:04               ` Andy Shevchenko
2025-09-05  5:47     ` Matti Vaittinen
2025-09-02 15:14   ` David Lechner
2025-09-03  7:03     ` Matti Vaittinen
2025-09-02 22:34   ` Linus Walleij
2025-09-03  5:23     ` Matti Vaittinen
2025-09-03  6:47       ` Linus Walleij
2025-09-03  7:17         ` Matti Vaittinen
2025-09-03  7:17         ` Matti Vaittinen
2025-09-03  8:17           ` Matti Vaittinen
2025-09-03 11:02         ` Nuno Sá
2025-09-03 11:27           ` Andy Shevchenko
2025-09-04 14:02   ` kernel test robot
2025-09-02 12:30 ` [PATCH 3/3] MAINTAINERS: Support ROHM BD79112 ADC 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=43141a95-2267-44de-bd7e-11eb8c80090e@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=hansg@kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt@analog.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=nuno.sa@analog.com \
    --cc=ramona.nechita@analog.com \
    --cc=robh@kernel.org \
    --cc=tgamblin@baylibre.com \
    --cc=thomas.bonnefille@bootlin.com \
    --cc=tobias.sperling@softing.com \
    /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;
as well as URLs for NNTP newsgroup(s).