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 1/5] iio: core: emit channel prefixes into a struct seq_buf
Date: Fri, 27 Nov 2026 09:47:44 +0000 [thread overview]
Message-ID: <20261127-iio-core-attr-review-v2-1-e0aed1e8a81c@analog.com> (raw)
In-Reply-To: <20261127-iio-core-attr-review-v2-0-e0aed1e8a81c@analog.com>
From: Rodrigo Alencar <rodrigo.alencar@analog.com>
__iio_chan_prefix_emit() builds the channel prefix of an attribute name
through a struct seq_buf that is local to the function, so a caller that
wants to append to the prefix has to deal with the buffer offset itself.
Move the prefix logic into iio_chan_prefix_seq_buf(), which takes the
struct seq_buf directly and returns the length of the prefix, and keep
__iio_chan_prefix_emit() as a wrapper for its current users. This lets
the IIO core build a full attribute name in a single struct seq_buf.
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
drivers/iio/industrialio-core.c | 46 ++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index dabd57a0994e..5267a9c5908c 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -206,28 +206,24 @@ static const char * const iio_chan_info_postfix[] = {
[IIO_CHAN_INFO_POWERFACTOR] = "powerfactor",
};
-VISIBLE_IF_KUNIT
-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)
+static ssize_t iio_chan_prefix_seq_buf(struct device *dev,
+ const struct iio_chan_spec *chan,
+ enum iio_shared_by shared_by,
+ struct seq_buf *s)
{
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);
+ seq_buf_printf(s, "%s", dir);
break;
case IIO_SHARED_BY_TYPE:
- seq_buf_printf(&s, "%s_%s", dir, type);
+ seq_buf_printf(s, "%s_%s", dir, type);
if (chan->differential)
- seq_buf_printf(&s, "-%s", type);
+ seq_buf_printf(s, "-%s", type);
break;
case IIO_SEPARATE:
/* Validate differential channel settings */
@@ -242,23 +238,39 @@ ssize_t __iio_chan_prefix_emit(struct device *dev,
}
}
- seq_buf_printf(&s, "%s_%s", dir, type);
+ seq_buf_printf(s, "%s_%s", dir, type);
if (chan->indexed)
- seq_buf_printf(&s, "%d", chan->channel);
+ seq_buf_printf(s, "%d", chan->channel);
if (chan->differential)
- seq_buf_printf(&s, "-%s%d", type, chan->channel2);
+ seq_buf_printf(s, "-%s%d", type, chan->channel2);
if (chan->modified)
- seq_buf_printf(&s, "_%s", iio_modifier_names[chan->channel2]);
+ seq_buf_printf(s, "_%s", iio_modifier_names[chan->channel2]);
if (chan->extend_name)
- seq_buf_printf(&s, "_%s", chan->extend_name);
+ seq_buf_printf(s, "_%s", chan->extend_name);
break;
}
- return seq_buf_has_overflowed(&s) ? -EOVERFLOW : s.len;
+ if (seq_buf_has_overflowed(s))
+ return -EOVERFLOW;
+
+ return seq_buf_used(s);
+}
+
+VISIBLE_IF_KUNIT
+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)
+{
+ struct seq_buf s;
+
+ seq_buf_init(&s, buf, len);
+
+ return iio_chan_prefix_seq_buf(dev, chan, shared_by, &s);
}
EXPORT_SYMBOL_IF_KUNIT(__iio_chan_prefix_emit);
--
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 ` Rodrigo Alencar via B4 Relay [this message]
2026-11-27 9:47 ` [PATCH v2 2/5] iio: buffer: add iio_attr_to_buffer() helper Rodrigo Alencar via B4 Relay
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-1-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®