Re: [PATCH v3] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit

From: Andy Shevchenko
Date: Wed Jul 23 2025 - 10:43:11 EST


On Wed, Jul 23, 2025 at 07:43:59PM +0530, Akshay Bansod 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.

...

> 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 ",
> + fs_table->fs_avl[i].gain);
> +
> + sysfs_emit_at(buf, len - 1, "\n");

Still looks a bit weird (while working).

> return len;

I deally we should have a helper doing all this under the hood for plenty of
the (existing) users in the kernel.

In any case, I leave this change to others to comment, I don't object pushing
it in this form, either way len - 1 is simply weird.


--
With Best Regards,
Andy Shevchenko