* [PATCH v4] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit
@ 2025-08-11 16:56 Akshay Bansod
2025-08-11 19:17 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Akshay Bansod @ 2025-08-11 16:56 UTC (permalink / raw)
To: Lorenzo Bianconi, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko
Cc: linux-kernel-mentees, linux-iio, linux-kernel
Update the sysfs interface for sampling frequency and scale attributes.
Replace `scnprintf()` with `sysfs_emit_at()` which is PAGE_SIZE-aware
and recommended for use in sysfs.
Signed-off-by: Akshay Bansod <akbansd@gmail.com>
---
changes in v4:
- reformatted as per sugessions, used ternary operator
- Link to v3: https://lore.kernel.org/linux-iio/20250723141359.11723-1-akbansd@gmail.com/
changes in v3:
- Use `sysfs_emit_at(buf, len - 1, "\n")` instead of directly modifying `buf[len - 1]`
for newline termination, aligning with `sysfs_emit_at()` usage.
- Link to v2: https://lore.kernel.org/linux-iio/20250703053900.36530-1-akbansd@gmail.com/
changes in v2:
- Fixed indentation for line wrap
- Link to v1: https://lore.kernel.org/linux-iio/20250702135855.59955-1-akbansd@gmail.com/
Testing:
- Built the driver (`st_lsm6dsx_i2c`) as a module.
- Tested using `i2c-stub` to mock the device.
- Verified that reading sysfs attributes like `sampling_frequency_available`
works correctly and shows no change in functionality.
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index c65ad4982..d8cb4b021 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2035,10 +2035,10 @@ 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);
- buf[len - 1] = '\n';
+ len += sysfs_emit_at(buf, len, "%d.%03d%c",
+ odr_table->odr_avl[i].milli_hz / 1000,
+ odr_table->odr_avl[i].milli_hz % 1000,
+ (i == odr_table->odr_len - 1) ? '\n' : ' ');
return len;
}
@@ -2054,9 +2054,9 @@ 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);
- buf[len - 1] = '\n';
+ len += sysfs_emit_at(buf, len, "0.%09u%c",
+ fs_table->fs_avl[i].gain,
+ (i == fs_table->fs_len - 1) ? '\n' : ' ');
return len;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit
2025-08-11 16:56 [PATCH v4] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit Akshay Bansod
@ 2025-08-11 19:17 ` Andy Shevchenko
2025-08-16 13:34 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2025-08-11 19:17 UTC (permalink / raw)
To: Akshay Bansod
Cc: Lorenzo Bianconi, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-kernel-mentees, linux-iio, linux-kernel
On Mon, Aug 11, 2025 at 6:57 PM Akshay Bansod <akbansd@gmail.com> wrote:
>
> Update the sysfs interface for sampling frequency and scale attributes.
> Replace `scnprintf()` with `sysfs_emit_at()` which is PAGE_SIZE-aware
> and recommended for use in sysfs.
LGTM,
Reviewed-by: Andy Shevchenko <andy@kernel.org>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit
2025-08-11 19:17 ` Andy Shevchenko
@ 2025-08-16 13:34 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-08-16 13:34 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Akshay Bansod, Lorenzo Bianconi, David Lechner, Nuno Sá,
Andy Shevchenko, linux-kernel-mentees, linux-iio, linux-kernel
On Mon, 11 Aug 2025 21:17:18 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Mon, Aug 11, 2025 at 6:57 PM Akshay Bansod <akbansd@gmail.com> wrote:
> >
> > Update the sysfs interface for sampling frequency and scale attributes.
> > Replace `scnprintf()` with `sysfs_emit_at()` which is PAGE_SIZE-aware
> > and recommended for use in sysfs.
>
> LGTM,
> Reviewed-by: Andy Shevchenko <andy@kernel.org>
>
Tweaked patch title to include () for the two functions mentioned.
I think that just makes things a tiny bit clearer.
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-16 13:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 16:56 [PATCH v4] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit Akshay Bansod
2025-08-11 19:17 ` Andy Shevchenko
2025-08-16 13:34 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox