[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250621185824.69a11319@jic23-huawei>
Date: Sat, 21 Jun 2025 18:58:24 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Andrew Ijano <andrew.ijano@...il.com>
Cc: andrew.lopes@...mni.usp.br, gustavobastos@....br, dlechner@...libre.com,
nuno.sa@...log.com, andy@...nel.org, jstephan@...libre.com,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 4/4] iio: accel: sca3000: use sysfs_emit_at() instead
of sprintf()
On Wed, 18 Jun 2025 00:12:19 -0300
Andrew Ijano <andrew.ijano@...il.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@...mni.usp.br>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@...ux.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;
> }
>
> /*
Powered by blists - more mailing lists