[PATCH] iio: imu: st_lsm6dsx: Convert to use sysfs_emit_at() API

From: ye.xingchen
Date: Wed Dec 07 2022 - 02:40:46 EST


From: ye xingchen <ye.xingchen@xxxxxxxxxx>

Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: ye xingchen <ye.xingchen@xxxxxxxxxx>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 9 ++++-----
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 6 ++----
2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 3f6060c64f32..ac89978a6da1 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1993,9 +1993,9 @@ st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,

odr_table = &sensor->hw->settings->odr_table[sensor->id];
for (i = 0; i < odr_table->odr_len; i++)
- len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ",
- odr_table->odr_avl[i].milli_hz / 1000,
- odr_table->odr_avl[i].milli_hz % 1000);
+ len += sysfs_emit_at(buf, len, "%d.%03d ",
+ odr_table->odr_avl[i].milli_hz / 1000,
+ odr_table->odr_avl[i].milli_hz % 1000);
buf[len - 1] = '\n';

return len;
@@ -2012,8 +2012,7 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,

fs_table = &hw->settings->fs_table[sensor->id];
for (i = 0; i < fs_table->fs_len; i++)
- len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ",
- fs_table->fs_avl[i].gain);
+ len += sysfs_emit_at(buf, len, "0.%09u ", fs_table->fs_avl[i].gain);
buf[len - 1] = '\n';

return len;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index f2b64b4956a3..554b235f75a0 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -676,8 +676,7 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
for (i = 0; i < settings->odr_table.odr_len; i++) {
u32 val = settings->odr_table.odr_avl[i].milli_hz;

- len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ",
- val / 1000, val % 1000);
+ len += sysfs_emit_at(buf, len, "%d.%03d ", val / 1000, val % 1000);
}
buf[len - 1] = '\n';

@@ -694,8 +693,7 @@ static ssize_t st_lsm6dsx_shub_scale_avail(struct device *dev,

settings = sensor->ext_info.settings;
for (i = 0; i < settings->fs_table.fs_len; i++)
- len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
- settings->fs_table.fs_avl[i].gain);
+ len += sysfs_emit_at(buf, len, "0.%06u ", settings->fs_table.fs_avl[i].gain);
buf[len - 1] = '\n';

return len;
--
2.25.1