public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Nuno Sa <nuno.sa@analog.com>,
	David Lechner <dlechner@baylibre.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Quentin Schulz <quentin.schulz@free-electrons.com>
Subject: Re: [PATCH v2 2/5] iio: adc: add helpers for parsing ADC nodes
Date: Mon, 17 Feb 2025 16:24:36 +0200	[thread overview]
Message-ID: <14779fcc-bd10-45a5-afc1-4a5510e29cf1@gmail.com> (raw)
In-Reply-To: <20250211190714.4db240d2@jic23-huawei>

On 11/02/2025 21:07, Jonathan Cameron wrote:
> On Tue, 11 Feb 2025 10:52:51 +0200
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 

...

>>>> +int iio_adc_device_get_channels(struct device *dev, int *channels,
>>>> +				int max_channels)
>>>> +{
>>>> +	struct fwnode_handle *fwnode, *child;
>>>> +	int num_chan = 0, ret;
>>>> +
>>>> +	fwnode = dev_fwnode(dev);
>>>> +	if (!fwnode) {
>>>
>>> As before, I'd relax this until we need to do it. We may never do so.
>>
>> The BD79124 does not require this as I dropped the MFD, so this is
>> ultimately your call :) I, however, would like to humbly suggest adding
>> it now ;) I have changed some APIs in the regulator subsystem and in the
>> clk subsystem to support cases where the device-tree node is in the
>> parent (usual MFD device-case), and it has been somewhat scary... (What
>> if somewhere in some of the existing device-trees the parent happens to
>> have interesting properties - but it actually is not correct node? This
>> becomes a potential source of regression when adding support to an
>> existing API).
>>
>> Furthermore, when the node is unconditionally taken from the given
>> device-pointer, it is tempting for the caller to just pass the parent
>> device as argument...
>>
>>    - If you have done this - please raise your hand. /me raises.
>>    - If you have only later realized it can cause life-time issues when
>>      devm is used - please raise your hand. /me raises.
>>    - If you have tried to kick your own behind when fixing the issues -
>>      please, raise your hand. /me raises. (and if you succeeded - congraz,
>>      you aren't as old and clumsy as I am).
> 
> Maybe. I'd be happier if there was a single user included
> with a patch set doing this.  I'm not sure this applies to
> any of the SoC ADCs which are MFD hosted but maybe it does.
> 

I did a quick "grep powered audit" of the ADC drivers out of the 
curiosity. It seems to me that most of the platform drivers under ADC do 
have the of_match table populated. I suppose they have own node for the 
ADC stuff with ADC specific compatibles, so they're safe from this problem.

(I think we should still also consider cases where the ADC block does 
not have own compatible/node. This sure is just an opinion but I think 
it is kind of artificial to have own node for ADC block when it is just 
a part of a smallish device. Also, having multiple compatibles for one 
device feels "quirky" to me).

The exception to a rule seems to be the 'sun4i-gpadc-iio.c'

And, if I am not misreading the code, the thermal zone registration may 
be causing some problems. It seems to me the data of the thermal zone is 
allocated by the devm_iio_device_alloc() - and bound to the lifetime of 
the platform device.

The thermal zone in MFD branch is bound to the life time of the parent 
(MFD) device.

(in MFD case):
	info->sensor_device = pdev->dev.parent;
...

devm_thermal_of_zone_register(info->sensor_device, ...

I believe that releasing the IIO device will free the thermal zone data 
- but the thermal zone stays there until MFD is released. I haven't 
checked when the thermal zone uses the data though - but I'd be a bit 
wary of this design. Furthermore, removing and re-registering the IIO 
driver may cause some collision with the thermal zone which has stayed 
there. (Again, I didn't check the thermal zone implementation so I'm not 
sure this really is a problem).

In any case, it seems to me most of the current IIO ADC MFD devices have 
dt node "bound" to the platform device and don't use the parent node.

Yours,
   -- Matti


  parent reply	other threads:[~2025-02-17 14:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05 13:34 [PATCH v2 0/5] Support ROHM BD79124 ADC/GPO Matti Vaittinen
2025-02-05 13:34 ` [PATCH v2 1/5] dt-bindings: " Matti Vaittinen
2025-02-05 20:03   ` Conor Dooley
2025-02-06  8:39     ` Matti Vaittinen
2025-02-06 18:16       ` Conor Dooley
2025-02-05 13:34 ` [PATCH v2 2/5] iio: adc: add helpers for parsing ADC nodes Matti Vaittinen
2025-02-08 16:41   ` Jonathan Cameron
2025-02-11  8:52     ` Matti Vaittinen
2025-02-11 19:07       ` Jonathan Cameron
2025-02-16 17:50         ` David Lechner
2025-02-17  6:29           ` Matti Vaittinen
2025-02-17 16:05             ` David Lechner
2025-02-17  7:08         ` Matti Vaittinen
2025-02-17 14:24         ` Matti Vaittinen [this message]
2025-02-05 13:38 ` [PATCH v2 3/5] iio: adc: Support ROHM BD79124 ADC Matti Vaittinen
2025-02-06 22:42   ` kernel test robot
2025-02-08 16:52   ` Jonathan Cameron
2025-02-11  9:06     ` Matti Vaittinen
2025-02-11 19:19       ` Jonathan Cameron
2025-02-05 13:38 ` [PATCH v2 4/5] MAINTAINERS: Add IIO ADC helpers Matti Vaittinen
2025-02-05 13:38 ` [PATCH v2 5/5] MAINTAINERS: Add ROHM BD79124 ADC/GPO 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=14779fcc-bd10-45a5-afc1-4a5510e29cf1@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=nuno.sa@analog.com \
    --cc=quentin.schulz@free-electrons.com \
    --cc=robh@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