[RFC PATCH 3/5] iio: triggered-buffer: add sysfs buffer attributes as args for setup

From: Alexandru Ardelean
Date: Fri Sep 25 2020 - 04:38:30 EST


This change adds a parameter to the {devm_}iio_triggered_buffer_setup()
functions to assign the extra sysfs buffer attributes that are typically
assigned via iio_buffer_set_attrs().

When adding multiple IIO buffers per IIO device, it can be pretty
cumbersome to first allocate a set of buffers, then to dig them out of IIO
to assign extra attributes.

Naturally, the best way would be to provide them at allocation time, which
is what this change does for {devm_}iio_triggered_buffer_setup() allocated
buffers.

At this moment, buffers allocated with {devm_}iio_triggered_buffer_setup()
are the only ones in mainline IIO to call iio_buffer_set_attrs(), and this
works well for the single-buffer-per-IIO-device case.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@xxxxxxxxxx>
---
drivers/iio/buffer/industrialio-triggered-buffer.c | 12 +++++++++---
include/linux/iio/triggered_buffer.h | 7 +++++--
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
index 6c20a83f887e..b79acdc623b7 100644
--- a/drivers/iio/buffer/industrialio-triggered-buffer.c
+++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
@@ -21,6 +21,7 @@
* @setup_ops: Buffer setup functions to use for this device.
* If NULL the default setup functions for triggered
* buffers will be used.
+ * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer
*
* This function combines some common tasks which will normally be performed
* when setting up a triggered buffer. It will allocate the buffer and the
@@ -36,7 +37,8 @@
int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
irqreturn_t (*h)(int irq, void *p),
irqreturn_t (*thread)(int irq, void *p),
- const struct iio_buffer_setup_ops *setup_ops)
+ const struct iio_buffer_setup_ops *setup_ops,
+ const struct attribute **buffer_attrs)
{
struct iio_buffer *buffer;
int ret;
@@ -67,6 +69,8 @@ int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
/* Flag that polled ring buffering is possible */
indio_dev->modes |= INDIO_BUFFER_TRIGGERED;

+ iio_buffer_set_attrs(buffer, buffer_attrs);
+
return 0;

error_kfifo_free:
@@ -96,7 +100,8 @@ int devm_iio_triggered_buffer_setup(struct device *dev,
struct iio_dev *indio_dev,
irqreturn_t (*h)(int irq, void *p),
irqreturn_t (*thread)(int irq, void *p),
- const struct iio_buffer_setup_ops *ops)
+ const struct iio_buffer_setup_ops *ops,
+ const struct attribute **buffer_attrs)
{
struct iio_dev **ptr;
int ret;
@@ -108,7 +113,8 @@ int devm_iio_triggered_buffer_setup(struct device *dev,

*ptr = indio_dev;

- ret = iio_triggered_buffer_setup(indio_dev, h, thread, ops);
+ ret = iio_triggered_buffer_setup(indio_dev, h, thread, ops,
+ buffer_attrs);
if (!ret)
devres_add(dev, ptr);
else
diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h
index e99c91799359..33c1f5bb1ee5 100644
--- a/include/linux/iio/triggered_buffer.h
+++ b/include/linux/iio/triggered_buffer.h
@@ -4,19 +4,22 @@

#include <linux/interrupt.h>

+struct attribute;
struct iio_dev;
struct iio_buffer_setup_ops;

int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
irqreturn_t (*h)(int irq, void *p),
irqreturn_t (*thread)(int irq, void *p),
- const struct iio_buffer_setup_ops *setup_ops);
+ const struct iio_buffer_setup_ops *setup_ops,
+ const struct attribute **buffer_attrs);
void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);

int devm_iio_triggered_buffer_setup(struct device *dev,
struct iio_dev *indio_dev,
irqreturn_t (*h)(int irq, void *p),
irqreturn_t (*thread)(int irq, void *p),
- const struct iio_buffer_setup_ops *ops);
+ const struct iio_buffer_setup_ops *ops,
+ const struct attribute **buffer_attrs);

#endif
--
2.17.1