Re: [PATCH 06/12] rtc: abx80x: use sysfs_emit() instead of sprintf()
From: David Laight
Date: Fri Oct 30 2026 - 12:41:09 EST
On Thu, 29 Oct 2026 14:23:29 +0100
alexandre.belloni@xxxxxxxxxxx wrote:
> From: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
>
> Use sysfs_emit() instead of sprintf() in sysfs show callbacks
> (autocalibration_show and oscillator_show) to conform to the
> recommended sysfs attribute formatting guidelines in
> Documentation/filesystems/sysfs.rst.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
> ---
> drivers/rtc/rtc-abx80x.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> index 1c69d0e2f940..a0d67818eb58 100644
> --- a/drivers/rtc/rtc-abx80x.c
> +++ b/drivers/rtc/rtc-abx80x.c
> @@ -442,11 +442,11 @@ static ssize_t autocalibration_show(struct device *dev,
> autocalibration = abx80x_rtc_get_autocalibration(dev->parent);
> if (autocalibration < 0) {
> dev_err(dev, "Failed to read RTC autocalibration\n");
> - sprintf(buf, "0\n");
> + sysfs_emit(buf, "0\n");
> return autocalibration;
That doesn't make sense.
The return value is the length of data in the buffer.
So there is no point calling sprintf/sysfs_emit and then returning
an error.
David
> }
>
> - return sprintf(buf, "%d\n", autocalibration);
> + return sysfs_emit(buf, "%d\n", autocalibration);
> }
>
> static DEVICE_ATTR_RW(autocalibration);
> @@ -490,14 +490,14 @@ static ssize_t oscillator_show(struct device *dev,
>
> if (rc_mode < 0) {
> dev_err(dev, "Failed to read RTC oscillator selection\n");
> - sprintf(buf, "\n");
> + sysfs_emit(buf, "\n");
> return rc_mode;
> }
>
> if (rc_mode)
> - return sprintf(buf, "rc\n");
> + return sysfs_emit(buf, "rc\n");
> else
> - return sprintf(buf, "xtal\n");
> + return sysfs_emit(buf, "xtal\n");
> }
>
> static DEVICE_ATTR_RW(oscillator);