From: Jonathan Cameron <jic23@kernel.org>
To: Andrew Ijano <andrew.ijano@gmail.com>
Cc: andrew.lopes@alumni.usp.br, gustavobastos@usp.br,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
jstephan@baylibre.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/4] iio: accel: sca3000: use sysfs_emit_at() instead of sprintf()
Date: Sat, 21 Jun 2025 18:58:24 +0100 [thread overview]
Message-ID: <20250621185824.69a11319@jic23-huawei> (raw)
In-Reply-To: <20250618031638.26477-5-andrew.lopes@alumni.usp.br>
On Wed, 18 Jun 2025 00:12:19 -0300
Andrew Ijano <andrew.ijano@gmail.com> wrote:
> Use sysfs_emit_at() instead of sprintf() for sysfs operations as
> suggested in the documentation, since it is aware of PAGE_SIZE buffer.
>
> Signed-off-by: Andrew Ijano <andrew.lopes@alumni.usp.br>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hi.
A few comments inline,
Thanks,
J
> ---
> drivers/iio/accel/sca3000.c | 22 +++++++++-------------
> 1 file changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
> index 058a2d67c91c..bc0046b19511 100644
> --- a/drivers/iio/accel/sca3000.c
> +++ b/drivers/iio/accel/sca3000.c
> @@ -423,16 +423,16 @@ sca3000_show_available_3db_freqs(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct sca3000_state *st = iio_priv(indio_dev);
> - int len;
> + unsigned int len = 0;
No need to initialize as set on the next line
>
> - len = sprintf(buf, "%d", st->info->measurement_mode_3db_freq);
> + len = sysfs_emit_at(buf, len, "%d", st->info->measurement_mode_3db_freq);
sysfs_emit() when you know you are at the start.
> if (st->info->option_mode_1)
> - len += sprintf(buf + len, " %d",
> + len += sysfs_emit_at(buf, len, " %d",
> st->info->option_mode_1_3db_freq);
Fix alignment.
> if (st->info->option_mode_2)
> - len += sprintf(buf + len, " %d",
> + len += sysfs_emit_at(buf, len, " %d",
> st->info->option_mode_2_3db_freq);
same here.
> - len += sprintf(buf + len, "\n");
> + len += sysfs_emit_at(buf, len, "\n");
>
> return len;
> }
> @@ -783,7 +783,6 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct sca3000_state *st = iio_priv(indio_dev);
> - unsigned int len = 0;
> int ret;
>
> scoped_guard(mutex, &st->lock) {
> @@ -794,25 +793,22 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
>
> switch (ret & SCA3000_REG_MODE_MODE_MASK) {
> case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
> - len += sprintf(buf + len, "%d %d %d\n",
> + return sysfs_emit(buf, "%d %d %d\n",
> st->info->measurement_mode_freq,
> st->info->measurement_mode_freq / 2,
> st->info->measurement_mode_freq / 4);
> - break;
> case SCA3000_REG_MODE_MEAS_MODE_OP_1:
> - len += sprintf(buf + len, "%d %d %d\n",
> + return sysfs_emit(buf, "%d %d %d\n",
> st->info->option_mode_1_freq,
> st->info->option_mode_1_freq / 2,
> st->info->option_mode_1_freq / 4);
> - break;
> case SCA3000_REG_MODE_MEAS_MODE_OP_2:
> - len += sprintf(buf + len, "%d %d %d\n",
> + return sysfs_emit(buf, "%d %d %d\n",
> st->info->option_mode_2_freq,
> st->info->option_mode_2_freq / 2,
> st->info->option_mode_2_freq / 4);
> - break;
> }
> - return len;
> + return 0;
> }
>
> /*
next prev parent reply other threads:[~2025-06-21 17:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 3:12 [PATCH v6 0/4] iio: accel: sca3000: simplify by using newer infrastructure Andrew Ijano
2025-06-18 3:12 ` [PATCH v6 1/4] iio: accel: sca3000: replace usages of internal read data helpers by spi helpers Andrew Ijano
2025-06-21 17:38 ` Jonathan Cameron
2025-07-05 3:17 ` Andrew Ijano
2025-06-18 3:12 ` [PATCH v6 2/4] iio: accel: sca3000: clean sca3000_read_data() Andrew Ijano
2025-06-21 17:40 ` Jonathan Cameron
2025-06-18 3:12 ` [PATCH v6 3/4] iio: accel: sca3000: use lock guards Andrew Ijano
2025-06-21 17:55 ` Jonathan Cameron
2025-07-05 3:37 ` Andrew Ijano
2025-07-06 9:37 ` Jonathan Cameron
2025-06-18 3:12 ` [PATCH v6 4/4] iio: accel: sca3000: use sysfs_emit_at() instead of sprintf() Andrew Ijano
2025-06-21 17:58 ` Jonathan Cameron [this message]
2025-07-05 3:45 ` Andrew Ijano
2025-07-06 9:41 ` Jonathan Cameron
2025-06-18 5:55 ` [PATCH v6 0/4] iio: accel: sca3000: simplify by using newer infrastructure Andy Shevchenko
2025-06-18 12:24 ` Andrew Ijano
2025-06-18 17:41 ` Andy Shevchenko
2025-06-18 18:20 ` Andrew Ijano
2025-06-19 15:23 ` Andy Shevchenko
2025-07-05 3:03 ` Andrew Ijano
2025-07-05 18:18 ` Andy Shevchenko
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=20250621185824.69a11319@jic23-huawei \
--to=jic23@kernel.org \
--cc=andrew.ijano@gmail.com \
--cc=andrew.lopes@alumni.usp.br \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavobastos@usp.br \
--cc=jstephan@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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