From: Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@kernel.org>
To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Subject: [PATCH v2 2/5] iio: buffer: add iio_attr_to_buffer() helper
Date: Fri, 27 Nov 2026 09:47:45 +0000 [thread overview]
Message-ID: <20261127-iio-core-attr-review-v2-2-e0aed1e8a81c@analog.com> (raw)
In-Reply-To: <20261127-iio-core-attr-review-v2-0-e0aed1e8a81c@analog.com>
From: Rodrigo Alencar <rodrigo.alencar@analog.com>
Buffer implementations providing their own attributes through
struct iio_buffer::attrs need to find the buffer an attribute belongs
to. The DMAengine buffer does that with to_iio_dev_attr(attr)->buffer,
which depends on the IIO buffer core wrapping those attributes into its
own copies and on the layout of struct iio_dev_attr.
Add iio_attr_to_buffer(), so buffer implementations no longer depend on
how the IIO core keeps track of the buffer, and use it in the DMAengine
buffer.
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +-
drivers/iio/industrialio-buffer.c | 15 +++++++++++++++
include/linux/iio/buffer_impl.h | 3 +++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
index 7ecb9d875b8e..2e04cd5e3411 100644
--- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
+++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -226,7 +226,7 @@ static const struct iio_dma_buffer_ops iio_dmaengine_default_ops = {
static ssize_t iio_dmaengine_buffer_get_length_align(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
+ struct iio_buffer *buffer = iio_attr_to_buffer(attr);
struct dmaengine_buffer *dmaengine_buffer =
iio_buffer_to_dmaengine_buffer(buffer);
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 4294101810fd..2d7759325eb3 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -69,6 +69,21 @@ static const char * const iio_endian_prefix[] = {
[IIO_LE] = "le",
};
+/**
+ * iio_attr_to_buffer() - Get the IIO buffer a buffer attribute belongs to
+ * @attr: Device attribute of the buffer, as passed to its show/store callbacks
+ *
+ * Only valid for attributes registered through &struct iio_buffer.attrs or
+ * created by the IIO buffer core.
+ *
+ * Returns: Pointer to the IIO buffer.
+ */
+struct iio_buffer *iio_attr_to_buffer(struct device_attribute *attr)
+{
+ return to_iio_dev_attr(attr)->buffer;
+}
+EXPORT_SYMBOL_GPL(iio_attr_to_buffer);
+
static bool iio_buffer_is_active(struct iio_buffer *buf)
{
return !list_empty(&buf->buffer_list);
diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h
index 9442c165561a..c259dfdf46a2 100644
--- a/include/linux/iio/buffer_impl.h
+++ b/include/linux/iio/buffer_impl.h
@@ -9,6 +9,7 @@
#include <uapi/linux/iio/buffer.h>
#include <linux/iio/buffer.h>
+struct device_attribute;
struct dma_buf_attachment;
struct dma_fence;
struct iio_dev;
@@ -197,6 +198,8 @@ void iio_buffer_put(struct iio_buffer *buffer);
void iio_buffer_signal_dmabuf_done(struct dma_fence *fence, int ret);
+struct iio_buffer *iio_attr_to_buffer(struct device_attribute *attr);
+
#else /* CONFIG_IIO_BUFFER */
static inline void iio_buffer_get(struct iio_buffer *buffer) {}
--
2.43.0
next prev parent reply other threads:[~2026-11-27 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 9:47 [PATCH v2 0/5] iio: split struct iio_dev_attr into typed core attributes Rodrigo Alencar via B4 Relay
2026-11-27 9:47 ` [PATCH v2 1/5] iio: core: emit channel prefixes into a struct seq_buf Rodrigo Alencar via B4 Relay
2026-11-27 9:47 ` Rodrigo Alencar via B4 Relay [this message]
2026-11-27 9:47 ` [PATCH v2 3/5] iio: core: add struct iio_chan_attr and split attribute creation Rodrigo Alencar via B4 Relay
2026-11-27 9:47 ` [PATCH v2 4/5] iio: event: add struct iio_event_attr Rodrigo Alencar via B4 Relay
2026-11-27 9:47 ` [PATCH v2 5/5] iio: buffer: add struct iio_buffer_attr Rodrigo Alencar via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-iio-core-attr-review-v2-2-e0aed1e8a81c@analog.com \
--to=devnull+rodrigo.alencar.analog.com@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=rodrigo.alencar@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®