Re: [PATCH v7 06/10] iio: adc: Support ROHM BD79124 ADC

From: Matti Vaittinen
Date: Mon Mar 31 2025 - 03:53:11 EST


On 31/03/2025 10:37, Andy Shevchenko wrote:
On Sun, Mar 30, 2025 at 05:04:36PM +0100, Jonathan Cameron wrote:
On Mon, 17 Mar 2025 13:24:07 +0200
Matti Vaittinen <mazziesaccount@xxxxxxxxx> wrote:
On 16/03/2025 13:02, Jonathan Cameron wrote:
On Thu, 13 Mar 2025 09:19:03 +0200
Matti Vaittinen <mazziesaccount@xxxxxxxxx> wrote:

...

+ return (data->alarm_monitored[chan->channel] & BIT(dir));

Drop the outer brackets as not adding anything.

I just noticed that the integer returned from here is directly provided
to the user-space. I don't know the history, but it feels a bit off to
me. I mean, I would expect the read from sysfs file "*_en" to return '1'
or '0' - not 0x04.

Oh well, I suppose it's too late to change this in the IIO core - but
I'll do:
return !!(data->alarm_monitored[chan->channel] & BIT(dir));

Agreed it should be returning 1 or 0.

This stuff is a little bit messy. I'd not be against that ABI
cleanup if we squashed the values to 0,1 in the core as a follow up.

I doubt anyone relies on getting 0x4 as that would be very driver
specific userspace code!

FWIW, the time this discussion was held, I looked at the code and it seems
we have such drivers. I doubt we can change it without potential breakage of
(some) user space tools.

Thanks for the check, and for sharing the results Andy.

I was considering this for a while but eventually I didn't want to take a chance of breaking things. I have a feeling that majority of application writers, who happen to be writing something using a specific sensor, would just make their code to match what-ever they see kernel retuning via sysfs.

I know younger me would in the early 2000s. If I got a board where I was able to read values from sysfs, I would have just written the code which matches whatever I saw in sysfs when testing out things. I would have tried reading the file and then making my application to expect exactly the value "0x4" - assuming other values may have some other, unknown to me, meaning. I wouldn't have gone after a documentation, much less to send a question or a patch upstream :)

So, I wouldn't be surprized if someone else had done just this same, and they might be upset if we break their app(s).

Yours,
-- Matti