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

From: Jonathan Cameron

Date: Sat Jul 25 2026 - 18:25:48 EST


On Wed, 22 Jul 2026 16:50:17 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> 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 <rodrigo.alencar@xxxxxxxxxx>
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;
> +}
> +