* [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions
@ 2026-03-23 21:56 Gabriel Rondon
2026-03-25 20:25 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Gabriel Rondon @ 2026-03-23 21:56 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sa, Andy Shevchenko, linux-iio, linux-kernel
Replace sprintf() with sysfs_emit() in sysfs attribute show
callbacks. sysfs_emit() is the preferred API as it is aware of the
sysfs buffer page size limit.
Signed-off-by: Gabriel Rondon <grondon@gmail.com>
---
drivers/iio/accel/bmc150-accel-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 42ccf0316..2398eb7e1 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -851,7 +851,7 @@ static ssize_t bmc150_accel_get_fifo_watermark(struct device *dev,
wm = data->watermark;
mutex_unlock(&data->mutex);
- return sprintf(buf, "%d\n", wm);
+ return sysfs_emit(buf, "%d\n", wm);
}
static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
@@ -866,7 +866,7 @@ static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
state = data->fifo_mode;
mutex_unlock(&data->mutex);
- return sprintf(buf, "%d\n", state);
+ return sysfs_emit(buf, "%d\n", state);
}
static const struct iio_mount_matrix *
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions
2026-03-23 21:56 [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions Gabriel Rondon
@ 2026-03-25 20:25 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-03-25 20:25 UTC (permalink / raw)
To: Gabriel Rondon
Cc: David Lechner, Nuno Sa, Andy Shevchenko, linux-iio, linux-kernel
On Mon, 23 Mar 2026 21:56:19 +0000
Gabriel Rondon <grondon@gmail.com> wrote:
> Replace sprintf() with sysfs_emit() in sysfs attribute show
> callbacks. sysfs_emit() is the preferred API as it is aware of the
> sysfs buffer page size limit.
>
> Signed-off-by: Gabriel Rondon <grondon@gmail.com>
Applied. Note there is more that could be done in these two functions
(look beyond it if considering doing this).
> ---
> drivers/iio/accel/bmc150-accel-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 42ccf0316..2398eb7e1 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -851,7 +851,7 @@ static ssize_t bmc150_accel_get_fifo_watermark(struct device *dev,
> wm = data->watermark;
> mutex_unlock(&data->mutex);
That mutex is only held for setting local copy of wm. Should be no problem
in bolding it over the sysfs_emit. So
include cleanup.h if not already and use a guard.
guard(mutex)(&data->mutex);
return sysfs_emit(buf, "%d\n", data->watermark);
No need for a local variable.
>
> - return sprintf(buf, "%d\n", wm);
> + return sysfs_emit(buf, "%d\n", wm);
> }
>
> static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
> @@ -866,7 +866,7 @@ static ssize_t bmc150_accel_get_fifo_state(struct device *dev,
> state = data->fifo_mode;
> mutex_unlock(&data->mutex);
>
> - return sprintf(buf, "%d\n", state);
> + return sysfs_emit(buf, "%d\n", state);
> }
>
> static const struct iio_mount_matrix *
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-25 20:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 21:56 [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions Gabriel Rondon
2026-03-25 20:25 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox