Skip to contentSkip to conversation

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

PATCH Applied Gabriel Rondon 2 participants 2 messages Mar 23 – Mar 25 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: bmc150-accel-core: use sysfs_emit() in show functions

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.

---
 drivers/iio/accel/bmc150-accel-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +2 -2
index 42ccf0316..2398eb7e1 100644
@@ -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 *
Signature · 1 line
2.33.0
maintainer Applied
#1 lore raw
Quoted 5 lines · On Mon, 23 Mar 2026 21:56:19 +0000 Gabriel Rondon <[email protected]> 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.

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 static ssize_t bmc150_accel_get_fifo_watermark(struct device *dev, · line 852

Quoted 11 lines
---
 drivers/iio/accel/bmc150-accel-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +0 -0
index 42ccf0316..2398eb7e1 100644
@@ -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.

Quoted 15 lines
drivers/iio/accel/bmc150-accel-core.c +2 -2
-	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 *