From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>
Cc: "Joshua Crofts" <crofts@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: dac: rohm-bd79703: Fix full-scale voltages
Date: Mon, 30 Nov 2026 16:34:14 +0200 [thread overview]
Message-ID: <aw2JZnBKDH4tRLX6@ashevche-desk.local> (raw)
In-Reply-To: <bd689775-92b2-4d56-be01-9a00c061709f@gmail.com>
On Mon, Nov 30, 2026 at 09:01:07AM +0200, Matti Vaittinen wrote:
> On 27/11/2026 14:08, Andy Shevchenko wrote:
> > On Fri, Nov 27, 2026 at 01:46:12PM +0200, Matti Vaittinen wrote:
> > > On 27/11/2026 13:03, Andy Shevchenko wrote:
> > > > On Fri, Nov 27, 2026 at 08:34:22AM +0200, Matti Vaittinen wrote:
> > > > > On 26/11/2026 15:31, Joshua Crofts wrote:
> > > > > > On 26-Nov-26 14:23, Matti Vaittinen wrote:
...
> > > > > > > + int vcc_mv;
> > > > > >
> > > > > > _mV is the preferred style to denote SI unit variables.
> > > > >
> > > > > I have discussed this before, and I disagree. Regular variables have been
> > > > > lower case since forever. Capitals have been used to scream "Note me, here
> > > > > is something unusal you need to pay attention for" (like macros). In my,
> > > > > admittably not always humble enough, opinion, the whole "denote SI units" is
> > > > > stupid. I haven't yet seen an engineer who wouldn't understand the meaning
> > > > > of vcc_mv in this context. And, to be very blunt, if I saw such an engineer,
> > > > > I would rather him stay away from the driver code. On the other hand, I have
> > > > > seen engineers who have spent long time with kernel code, stop reading to
> > > > > wonder "Hey, we have capitals here, what's special with this
> > > > > variable/member". So for me a change from vcc_mv to vcc_mV makes this worse.
> > > >
> > > > And I disagree with your argumentation because the scope of discussion here is
> > > > more than just millivolts. We have (in practice!) already a problem with mHz
> > > > versus MHz. Yes, in real life.
> > >
> > > I see no mHz or MHz here.
> >
> > That's why I pointed that the issue is broader than just millivolts _here_.
> > FWIW, mHz is in drivers/iio/imu/st_lsm6dsx/.
>
> If the problem is with the mHz vs MHz - why adding weird variables
> elsewhere? In my opinion, we should avoid blindly following general "rules
> of thumb". And we definitely shouldn't invent such out of very specific
> cases.
Then we will end up with different SI units when we apply different style to
them.
> > > > So, that's why it's better to follow SI for all
> > > > SI registered units and stop messing with the multipliers.
> > >
> > > No. There is zero reason to use capitals in variable/member names when
> > > intent is clear. It only hurts reading with zero real benefits.
> >
> > It's clear for *you* or somebody else who is not the first day in IIO
> > development, always put yourself into the position of unprepared reader.
>
> If you consider someone coming outside of IIO (but someone who has spent
> time in-kernel) - it is likely seeing upper-case variable makes them rise
> their eyebrows. And no, VCC is not used only in IIO. VCC is pretty much used
> with a wide variety of electronics. Besides, I don't buy your claim that
> "vcc_mV" would make the meaning of variable any more known for someone who
> does not come from IIO than vcc_mv does. To me this claim sounds just plain
> silly. If you know vcc is a voltage, then mv -suffix is really obvious. If
> you don't know it is voltage, then mV - suffix won't help. I really have a
> feeling this is very made-up solution to a made-up problem.
Vcc can be in Volts, millivolts, microvolts, and so on. We add unit suffices
for readability to understand the order of the values and give more meaning
to the expressions like
vref_mV = 5;
Then we have different suffices based on SI + registered multipliers and how
they are represented in the physical world. Yes, it's not that much a problem
as we take it standalone (for isolated driver and isolated case), but in general
it's a deviation in style.
> To me, (I don't claim this is how things are, this is how it seems to me)
> comments like this are a symptom of: "I want to show I am a Very Capable
> Experienced Kernel Developer and I want to feel important" attitude, rather
> than "I genuinely believe this is an important improvement to the
> contribution, and I want to help the author to improve". Please note, this
> does not mean I didn't appreciate your reviews. I do value many of your
> findings, you tend to add also some very valuable comments.
I understand the frustration, but I'm for the common style, like a standard
at least in the borders of a single subsystem. What you are saying about
individual approach based on the SI in use I disagree with, because it would
lead to potential misinterpretations.
> > SI is known for much longer than computer even exist.
> >
> > > > > > > + int vfs_mv;
...
> > > > > > > + data->vcc_mv = ret / 1000;
> > > > > >
> > > > > > Better to do ret / (MICRO / MILLI).
> > > > >
> > > > > This is another thing I've discussed also in the past. If you genuinely stop
> > > > > to think this, why would MICRO / MILLI be better than 1000? Which one brings
> > > > > smaller cognitional load, huh? And assigning the result to variable vcc_mv
> > > > > makes units explicit in any case. And speaking of SI units and scientific
> > > > > accuracy, what actually is MICRO? What is MILLI?
> > > >
> > > > Then what prevents you from adding a new multiplier to units.h?
> >
> > No answer?
>
> I think I've said it also earlier. In my opinion, we should not obfuscate
> 1000 with a define. To me, 1000 is as clear as it gets. If we have a define,
> then there is always a chance it means something else - unless we go and see
> the define. Like in case of MILLI and KILO, MICRO and MEGA.
It requires an additional cognitive work to get the order of the value kept in
'ret'. With (MICRO / MILLI) it's easier to understand (as it's read as 'we got
value in microSOMETHING and we convert it to milliSOMETHING).
...
> > > > > Micro is 10^-6! Milli is 10^-3. So, this becomes "ret / (10^-6 / 10^-3)",
> > > > > which is plain incorrect. So, instead of making things better, this
> > > > > obfuscates stuff even further. So please, let's not spread this madness any
> > > > > further.
> > > >
> > > > Because kernel does not work in float, it works in integer space.
> > >
> > > This does not mean Milli is same as Kilo. You were the one who ask for
> > > accuracy above (even though it really just breaks the known convention), and
> > > here you demand obfuscation.
> >
> > Yeah, it would be nice to have the stricter rules about this, but I see the
> > problems it may lead to. For the given case we transform the value in MICRO
> > volts to a MILLI volts using a ratio MICRO / MILLI. I consider that much easier
> > to read in the code and _understand_ what's going on.
>
> I understand the intention of explaining the transformation from micro to
> milli, but I genuinely think this is a very failed attempt. We are reading
> code, not documentation, and if code says:
>
> ret / (MICRO / MILLI);
>
> it says we are dividing ret by a value, which is MICRO / MILLI. In order to
> understand what resulting ret is going to be, one must dig out what the
> MICRO and MILLI are.
Everybody understands what are they. The same argument as you used about 'mv'
versus 'mV' above.
> This is extra step for anyone who does not know what
> they are, and also an unnecessary (although simple) computation for anyone
> who know what they are. It really is not a documentation but obfuscation.
> For unit conversion, one would logically expect to see _multiplication_ by
> the ratio (which, of course, would not work here as MICRO and MILLI aren't
> what they are supposed to be). This is just obfuscation to ... Somebody
> else, who is the first day in IIO development. Please, always put yourself
> into the position of unprepared reader.
>
> In my opinion, if the transformation really requires documentation, use real
> values and add a comment.
>
> vcc_mv = ret / 1000; /* uV to mV */
>
> Do NOT add some strange inverse unit division with bad defines.
Yes, this is the main point of our disagreement. So, I think we can go thru
applying the multiplier in the units.h as MICROVOLT_PER_MILLIVOLT and then
it will follow the pattern that is used *a lot* in the kernel for other things.
> Now, when one considers if a comment would be needed in above code, seeing
> the 'ret' value comes from regulator API and goes into vcc_mv ... In my
> opinion, this really is not something that would need a comment.
>
> > > > We don't have fractions without keeping a multiplier in mind. I do not
> > > > consider this a madness.
> > >
> > > swapping 1000 to (MICRO / MILLI) - where micro and milli arent what they are
> > > supposed to be - is madeness to me.
> >
> > And opposite to me as we may admit.
>
> I admit :)
...
With all arguments being said, I do not think we can productively and effectively
continue this discussion. Let's just not waist our time on this anymore and do
something more useful. Do you agree?
Especially taking into account that Jonathan is okay with your style and AFAICS
he applied this already.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-30 14:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 13:23 Matti Vaittinen
2026-11-26 13:31 ` Joshua Crofts
2026-11-27 6:34 ` Matti Vaittinen
2026-11-27 11:03 ` Andy Shevchenko
2026-11-27 11:46 ` Matti Vaittinen
2026-11-27 12:08 ` Andy Shevchenko
2026-11-27 15:57 ` Andy Shevchenko
2026-11-30 7:06 ` Matti Vaittinen
2026-11-30 7:01 ` Matti Vaittinen
2026-11-30 14:34 ` Andy Shevchenko [this message]
2026-11-28 3:53 ` Jonathan Cameron
2026-11-30 8:28 ` 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=aw2JZnBKDH4tRLX6@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=crofts@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.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
all inboxes | Powered by JetHome®