[PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions

Gabriel Rondon posted 1 patch 1 week, 3 days ago
drivers/iio/accel/bmc150-accel-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions
Posted by Gabriel Rondon 1 week, 3 days ago
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
Re: [PATCH] iio: accel: bmc150-accel-core: use sysfs_emit() in show functions
Posted by Jonathan Cameron 1 week, 1 day ago
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 *