Re: [PATCH RFC 4/5] iio: buffer: add struct iio_buffer_attr
From: Jonathan Cameron
Date: Fri Nov 20 2026 - 20:53:09 EST
On Fri, 20 Nov 2026 18:04:00 +0000
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:
> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> Buffer attributes find their buffer through the buffer field of
> struct iio_dev_attr, which is unused by every other attribute.
>
> Add struct iio_buffer_attr, extending struct iio_chan_attr with the
> buffer the attribute belongs to, and use it both for the scan element
> attributes and for the buffer attributes wrapped by the buffer core.
> iio_attr_to_buffer() now resolves the buffer through it.
>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
> ---
> drivers/iio/industrialio-buffer.c | 63 +++++++++++++++++++++++++--------------
> 1 file changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 48fdaed6d703..af5c9ecd1b3f 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -69,6 +69,22 @@ static const char * const iio_endian_prefix[] = {
> [IIO_LE] = "le",
> };
>
> +/**
> + * struct iio_buffer_attr - IIO buffer attribute
> + * @chan_attr: underlying IIO channel attribute (channel is NULL for buffer
> + * wide attributes)
> + * @buffer: the IIO buffer to which this attribute belongs to
> + */
> +struct iio_buffer_attr {
> + struct iio_chan_attr chan_attr;
> + struct iio_buffer *buffer;
> +};
> @@ -1526,25 +1543,25 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
> struct attribute *attr)
> {
> struct device_attribute *dattr = to_dev_attr(attr);
> - struct iio_chan_attr *chan_attr;
> + struct iio_buffer_attr *buf_attr;
> struct iio_dev_attr *iio_attr;
>
> - chan_attr = kzalloc_obj(*chan_attr);
> - if (!chan_attr)
> + buf_attr = kzalloc_obj(*buf_attr);
Maybe some free magic is appropriate here.
> + if (!buf_attr)
> return NULL;
>
> - iio_attr = &chan_attr->iio_attr;
> - iio_attr->buffer = buffer;
> + buf_attr->buffer = buffer;
> + iio_attr = &buf_attr->chan_attr.iio_attr;
> memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
> iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
> if (!iio_attr->dev_attr.attr.name) {
> - kfree(chan_attr);
> + kfree(buf_attr);
> return NULL;
> }
>
> sysfs_attr_init(&iio_attr->dev_attr.attr);
>
> - list_add(&chan_attr->l, &buffer->buffer_attr_list);
> + list_add(&buf_attr->chan_attr.l, &buffer->buffer_attr_list);
>
> return &iio_attr->dev_attr.attr;
> }
>