From: Guenter Roeck <linux@roeck-us.net>
To: Kari Argillander <kari.argillander@gmail.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] hwmon: Use sysfs_emit in show function callsbacks
Date: Fri, 19 Dec 2025 08:47:14 -0800 [thread overview]
Message-ID: <160f3844-e142-47ab-a0b5-5e9512aac568@roeck-us.net> (raw)
In-Reply-To: <20251219-hwmon-fixes-v1-2-21b29097ea3b@gmail.com>
On Fri, Dec 19, 2025 at 05:48:15PM +0200, Kari Argillander wrote:
> Use sysfs_emit() over sprintf() to prevent potential overflows. In
> hwmon_attr_show() that is totally impossible but looking other places
> many still use sysfs_emit().
>
> Also according Documentation/filesystems/sysfs.rst code should use
> sysfs_emit().
>
> Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/hwmon.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 7a784d685d77..714caa6a36a3 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -73,7 +73,7 @@ struct hwmon_thermal_data {
> static ssize_t
> name_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> - return sprintf(buf, "%s\n", to_hwmon_device(dev)->name);
> + return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->name);
> }
> static DEVICE_ATTR_RO(name);
>
> @@ -446,7 +446,7 @@ static ssize_t hwmon_attr_show(struct device *dev,
> trace_hwmon_attr_show(hattr->index + hwmon_attr_base(hattr->type),
> hattr->name, val64);
>
> - return sprintf(buf, "%lld\n", val64);
> + return sysfs_emit(buf, "%lld\n", val64);
> }
>
> static ssize_t hwmon_attr_show_string(struct device *dev,
> @@ -469,7 +469,7 @@ static ssize_t hwmon_attr_show_string(struct device *dev,
> trace_hwmon_attr_show_string(hattr->index + hwmon_attr_base(type),
> hattr->name, s);
>
> - return sprintf(buf, "%s\n", s);
> + return sysfs_emit(buf, "%s\n", s);
> }
>
> static ssize_t hwmon_attr_store(struct device *dev,
prev parent reply other threads:[~2025-12-19 16:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-19 15:48 [PATCH 0/2] hwmon: Minor errno and sysfs fixes Kari Argillander
2025-12-19 15:48 ` [PATCH 1/2] hwmon: Fix wrong return errno in *sanitize_name() Kari Argillander
2025-12-19 16:46 ` Guenter Roeck
2025-12-19 15:48 ` [PATCH 2/2] hwmon: Use sysfs_emit in show function callsbacks Kari Argillander
2025-12-19 16:47 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=160f3844-e142-47ab-a0b5-5e9512aac568@roeck-us.net \
--to=linux@roeck-us.net \
--cc=kari.argillander@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®