Re: [PATCH v9 08/17] iio: core: add hierarchical channel relationships

Jonathan Cameron <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-doc,org.kernel.vger.linux-hardening,org.kernel.vger.linux-kernel
Message-ID <20260725232432.7a0d4292@jic23-huawei>
On Wed, 22 Jul 2026 16:50:17 +0100
Rodrigo Alencar via B4 Relay <[email protected]> wrote:

> From: Rodrigo Alencar <[email protected]>
> 
> Add parent-child relationship between iio channels by creating a parent
> pointer field in iio_chan_spec struct and exposing a sysfs attribute that
> returns the parent channel prefix.
> 
> Signed-off-by: Rodrigo Alencar <[email protected]>
Hi Rodrigo.

One small thing below

Jonathan

> ---
>  drivers/iio/industrialio-core.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  include/linux/iio/iio.h         |  5 +++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index aa9d6474edd9..f7e3048354b9 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -856,6 +856,22 @@ static ssize_t iio_read_channel_label(struct device *dev,
>  					 to_iio_dev_attr(attr)->c, buf);
>  }
>  
> +static ssize_t iio_read_channel_parent(struct device *dev,
> +				       struct device_attribute *attr,
> +				       char *buf)
> +{
> +	const struct iio_chan_spec *chan = to_iio_dev_attr(attr)->c->parent;
> +	ssize_t len;
> +
> +	len = __iio_chan_prefix_emit(dev, chan, IIO_SEPARATE, buf, PAGE_SIZE);
> +	if (len < 0)
> +		return len;
> +
> +	buf[len++] = '\n';

Use sysfs_emit_at() for this rather than a direct write. I'd rather not have
to think about what happens if __iio_chan_prefix_emit() returns exactly
PAGE_SIZE().

> +
> +	return len;
> +}
> +
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.