Re: [PATCH] iio: cros_ec: use sysfs_emit() in show callbacks

From: David Laight

Date: Wed Nov 11 2026 - 06:26:16 EST


On Wed, 11 Nov 2026 07:26:08 +0000
Di Wu <diwux@xxxxxxxxxx> wrote:

> Replace sprintf() and snprintf() with sysfs_emit() in the sysfs show
> and ext_info read callbacks. sysfs_emit() is aware of the sysfs buffer
> PAGE_SIZE limit and is the preferred helper for show callbacks.

Reviewed-by: David Laight <david.laight.linux@xxxxxxxxx>

>
> Signed-off-by: Di Wu <diwux@xxxxxxxxxx>
> ---
> .../iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> index d03e40c91582..624d4b32b034 100644
> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> @@ -149,9 +149,9 @@ static ssize_t cros_ec_sensor_get_report_latency(struct device *dev,
> if (ret < 0)
> return ret;
>
> - return sprintf(buf, "%d.%06u\n",
> - latency / 1000,
> - (latency % 1000) * 1000);
> + return sysfs_emit(buf, "%d.%06u\n",
> + latency / 1000,
> + (latency % 1000) * 1000);

At least two of those lines can be merged.
I think it is 86 chars - maybe ok.
Personally I'd split after the format.

David

> }
>
> static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
> @@ -165,7 +165,7 @@ static ssize_t hwfifo_watermark_max_show(struct device *dev,
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
>
> - return sprintf(buf, "%d\n", st->fifo_max_event_count);
> + return sysfs_emit(buf, "%d\n", st->fifo_max_event_count);
> }
>
> static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
> @@ -465,7 +465,7 @@ static ssize_t cros_ec_sensors_id(struct iio_dev *indio_dev,
> {
> struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", st->param.info.sensor_num);
> + return sysfs_emit(buf, "%d\n", st->param.info.sensor_num);
> }
>
> const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[] = {
>
> base-commit: b70566610b48ba49dec636019da4d696db64b085