* [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf()
@ 2024-10-18 9:55 chen zhang
2024-10-22 12:37 ` Ilpo Järvinen
2024-10-22 12:41 ` Hans de Goede
0 siblings, 2 replies; 3+ messages in thread
From: chen zhang @ 2024-10-18 9:55 UTC (permalink / raw)
To: hdegoede, ilpo.jarvinen, corentin.chary, luke
Cc: linux-kernel, chenzhang_0901, chen zhang
Follow the advice in Documentation/filesystems/sysfs.rst:
show() should only use sysfs_emit() or sysfs_emit_at() when formatting
the value to be returned to user space.
Signed-off-by: chen zhang <chenzhang@kylinos.cn>
---
drivers/platform/x86/eeepc-laptop.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 03319a80e114..ba36b7bf6dc4 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -285,7 +285,7 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
if (value < 0)
return -EIO;
- return sprintf(buf, "%d\n", value);
+ return sysfs_emit(buf, "%d\n", value);
}
#define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
@@ -361,7 +361,7 @@ static ssize_t cpufv_show(struct device *dev,
if (get_cpufv(eeepc, &c))
return -ENODEV;
- return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
+ return sysfs_emit(buf, "%#x\n", (c.num << 8) | c.cur);
}
static ssize_t cpufv_store(struct device *dev,
@@ -393,7 +393,7 @@ static ssize_t cpufv_disabled_show(struct device *dev,
{
struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
- return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
+ return sysfs_emit(buf, "%d\n", eeepc->cpufv_disabled);
}
static ssize_t cpufv_disabled_store(struct device *dev,
@@ -1025,7 +1025,7 @@ static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
{
- return sprintf(buf, "%d\n", get());
+ return sysfs_emit(buf, "%d\n", get());
}
#define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf()
2024-10-18 9:55 [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf() chen zhang
@ 2024-10-22 12:37 ` Ilpo Järvinen
2024-10-22 12:41 ` Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2024-10-22 12:37 UTC (permalink / raw)
To: chen zhang; +Cc: Hans de Goede, corentin.chary, luke, LKML, chenzhang_0901
On Fri, 18 Oct 2024, chen zhang wrote:
> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
>
> Signed-off-by: chen zhang <chenzhang@kylinos.cn>
> ---
> drivers/platform/x86/eeepc-laptop.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
> index 03319a80e114..ba36b7bf6dc4 100644
> --- a/drivers/platform/x86/eeepc-laptop.c
> +++ b/drivers/platform/x86/eeepc-laptop.c
> @@ -285,7 +285,7 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
>
> if (value < 0)
> return -EIO;
> - return sprintf(buf, "%d\n", value);
> + return sysfs_emit(buf, "%d\n", value);
Please add also #include <linux/sysfs.h> and include the correct list
among receipients when sending v2.
--
i.
> }
>
> #define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
> @@ -361,7 +361,7 @@ static ssize_t cpufv_show(struct device *dev,
>
> if (get_cpufv(eeepc, &c))
> return -ENODEV;
> - return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
> + return sysfs_emit(buf, "%#x\n", (c.num << 8) | c.cur);
> }
>
> static ssize_t cpufv_store(struct device *dev,
> @@ -393,7 +393,7 @@ static ssize_t cpufv_disabled_show(struct device *dev,
> {
> struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
> + return sysfs_emit(buf, "%d\n", eeepc->cpufv_disabled);
> }
>
> static ssize_t cpufv_disabled_store(struct device *dev,
> @@ -1025,7 +1025,7 @@ static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
>
> static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
> {
> - return sprintf(buf, "%d\n", get());
> + return sysfs_emit(buf, "%d\n", get());
> }
>
> #define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf()
2024-10-18 9:55 [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf() chen zhang
2024-10-22 12:37 ` Ilpo Järvinen
@ 2024-10-22 12:41 ` Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2024-10-22 12:41 UTC (permalink / raw)
To: chen zhang, ilpo.jarvinen, corentin.chary, luke
Cc: linux-kernel, chenzhang_0901, platform-driver-x86
Hi,
On 18-Oct-24 11:55 AM, chen zhang wrote:
> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
>
> Signed-off-by: chen zhang <chenzhang@kylinos.cn>
> ---
> drivers/platform/x86/eeepc-laptop.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
> index 03319a80e114..ba36b7bf6dc4 100644
> --- a/drivers/platform/x86/eeepc-laptop.c
> +++ b/drivers/platform/x86/eeepc-laptop.c
You need to add a:
#include <linux/sysfs.h>
when using sysfs_emit() .
Please send a v2 with this fixed and please don't forget to Cc:
platform-driver-x86@vger.kernel.org
for the v2.
Regards,
Hans
> @@ -285,7 +285,7 @@ static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
>
> if (value < 0)
> return -EIO;
> - return sprintf(buf, "%d\n", value);
> + return sysfs_emit(buf, "%d\n", value);
> }
>
> #define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
> @@ -361,7 +361,7 @@ static ssize_t cpufv_show(struct device *dev,
>
> if (get_cpufv(eeepc, &c))
> return -ENODEV;
> - return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
> + return sysfs_emit(buf, "%#x\n", (c.num << 8) | c.cur);
> }
>
> static ssize_t cpufv_store(struct device *dev,
> @@ -393,7 +393,7 @@ static ssize_t cpufv_disabled_show(struct device *dev,
> {
> struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
> + return sysfs_emit(buf, "%d\n", eeepc->cpufv_disabled);
> }
>
> static ssize_t cpufv_disabled_store(struct device *dev,
> @@ -1025,7 +1025,7 @@ static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
>
> static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
> {
> - return sprintf(buf, "%d\n", get());
> + return sysfs_emit(buf, "%d\n", get());
> }
>
> #define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-22 12:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-18 9:55 [PATCH] platform/x86: eeepc-laptop: use sysfs_emit() instead of sprintf() chen zhang
2024-10-22 12:37 ` Ilpo Järvinen
2024-10-22 12:41 ` Hans de Goede
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®