On Mon, 27 Jul 2026 10:40:55 +0100
Rodrigo Alencar <[email protected]> wrote:

> On 25/07/26 23:24, Jonathan Cameron wrote:
> > 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().  
> 
> We can have __iio_chan_prefix_emit() called with PAGE_SIZE - 1?

That seems sensible anyway.

> 
> Filenames should be capped at 255.. so that NAME_MAX << PAGE_SIZE 

Agreed it isn't a real issue but nice to tidy up anyway.

> 
> As you suggest, we need a local buffer. Not sure we need to do an extra 
> copy...

I'm lost. I'm only suggesting sysfs_emit_at() for the buf[len++] = '\n';
not eh more complex __iio_chan_prefix_emit() as that takes the size so
anyone reading just this snippet will assume it doesn't overflow.

Jonathan


>  
> > > +
> > > + return len;
> > > +}
> > > +  
> 


Reply via email to