On Tue, Jul 07, 2026 at 03:04:27PM +0100, Rodrigo Alencar via B4 Relay wrote:

> Move logic to create a channel prefix for naming attribute files into a
> separate __iio_chan_prefix_emit() function for reuse. The dev pointer is
> passed to __iio_device_attr_init() so that WARN() replaced by dev_err().
> The new helper is going to be used to expose channel relationships as
> sysfs attributes.

...

> +static ssize_t __iio_chan_prefix_emit(struct device *dev,
> +                                   const struct iio_chan_spec *chan,
> +                                   enum iio_shared_by shared_by,
> +                                   char *buf, size_t len)
> +{
> +     const char *type = iio_chan_type_name_spec[chan->type];
> +     const char *dir = iio_direction[chan->output];
> +     struct seq_buf s;
> +
> +     seq_buf_init(&s, buf, len);
> +
> +     switch (shared_by) {
> +     case IIO_SHARED_BY_ALL:
> +             break;
> +     case IIO_SHARED_BY_DIR:
> +             seq_buf_printf(&s, "%s", dir);
> +             break;
> +     case IIO_SHARED_BY_TYPE:
> +             seq_buf_printf(&s, "%s_%s", dir, type);
> +             if (chan->differential)
> +                     seq_buf_printf(&s, "-%s", type);


> +             break;
> +     case IIO_SEPARATE:

> +             if (chan->indexed) {
> +                     seq_buf_printf(&s, "%s_%s%d", dir, type, chan->channel);
> +                     if (chan->differential)
> +                             seq_buf_printf(&s, "-%s%d", type, 
> chan->channel2);
> +             } else {
> +                     if (chan->differential) {
> +                             dev_err(dev, "Differential channels must be 
> indexed\n");
> +                             return -EINVAL;
> +                     }
> +                     seq_buf_printf(&s, "%s_%s", dir, type);
> +             }

So, in analogue with _BY_TYPE

                seq_buf_printf(&s, "%s_%s", dir, type);
                if (chan->indexed) {
                        seq_buf_printf(&s, "%d", chan->channel);
                        if (chan->differential)
                                seq_buf_printf(&s, "-%s%d", type, 
chan->channel2);
                } else if (chan->differential) {
                        dev_err(dev, "Differential channels must be indexed\n");
                        return -EINVAL;
                }

> +             if (chan->modified) {
> +                     if (chan->differential) {
> +                             dev_err(dev, "Differential channels can not 
> have modifier\n");
> +                             return -EINVAL;
> +                     }
> +                     seq_buf_printf(&s, "_%s", 
> iio_modifier_names[chan->channel2]);
> +             }
> +
> +             if (chan->extend_name)
> +                     seq_buf_printf(&s, "_%s", chan->extend_name);
> +             break;
> +     }
> +
> +     return seq_buf_has_overflowed(&s) ? -EOVERFLOW : s.len;
> +}

-- 
With Best Regards,
Andy Shevchenko



Reply via email to