* [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
@ 2026-03-05 12:41 Thorsten Blum
2026-03-05 12:48 ` Ilpo Järvinen
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-03-05 12:41 UTC (permalink / raw)
To: Prasanth Ksr, Hans de Goede, Ilpo Järvinen
Cc: Thorsten Blum, Dell.Client.Kernel, platform-driver-x86,
linux-kernel
Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
functions. sysfs_emit() and sysfs_emit_at() are preferred for formatting
sysfs output because they provide safer bounds checking.
In reset_bios_show(), use sysfs_emit_at() to avoid manual buffer size
accounting.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
.../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
index 9dddab6c9397..0f24cecc93fc 100644
--- a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
+++ b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
@@ -11,6 +11,7 @@
#include <linux/dmi.h>
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/sysfs.h>
#include <linux/wmi.h>
#include "dell-wmi-sysman.h"
#include "../../firmware_attributes_class.h"
@@ -143,17 +144,14 @@ int map_wmi_error(int error_code)
*/
static ssize_t reset_bios_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
- char *start = buf;
+ ssize_t len = 0;
int i;
- for (i = 0; i < MAX_TYPES; i++) {
- if (i == reset_option)
- buf += sprintf(buf, "[%s] ", reset_types[i]);
- else
- buf += sprintf(buf, "%s ", reset_types[i]);
- }
- buf += sprintf(buf, "\n");
- return buf-start;
+ for (i = 0; i < MAX_TYPES; i++)
+ len += sysfs_emit_at(buf, len, i == reset_option ? "[%s] " : "%s ",
+ reset_types[i]);
+ len += sysfs_emit_at(buf, len, "\n");
+ return len;
}
/**
@@ -194,7 +192,7 @@ static ssize_t reset_bios_store(struct kobject *kobj,
static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", wmi_priv.pending_changes);
+ return sysfs_emit(buf, "%d\n", wmi_priv.pending_changes);
}
static struct kobj_attribute reset_bios = __ATTR_RW(reset_bios);
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
2026-03-05 12:41 [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions Thorsten Blum
@ 2026-03-05 12:48 ` Ilpo Järvinen
2026-03-05 13:00 ` Thorsten Blum
0 siblings, 1 reply; 4+ messages in thread
From: Ilpo Järvinen @ 2026-03-05 12:48 UTC (permalink / raw)
To: Thorsten Blum
Cc: Prasanth Ksr, Hans de Goede, Dell.Client.Kernel,
platform-driver-x86, LKML
On Thu, 5 Mar 2026, Thorsten Blum wrote:
> Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
> functions. sysfs_emit() and sysfs_emit_at() are preferred for formatting
> sysfs output because they provide safer bounds checking.
>
> In reset_bios_show(), use sysfs_emit_at() to avoid manual buffer size
> accounting.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
> index 9dddab6c9397..0f24cecc93fc 100644
> --- a/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
> +++ b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c
> @@ -11,6 +11,7 @@
> #include <linux/dmi.h>
> #include <linux/module.h>
> #include <linux/kernel.h>
> +#include <linux/sysfs.h>
> #include <linux/wmi.h>
> #include "dell-wmi-sysman.h"
> #include "../../firmware_attributes_class.h"
> @@ -143,17 +144,14 @@ int map_wmi_error(int error_code)
> */
> static ssize_t reset_bios_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
> {
> - char *start = buf;
> + ssize_t len = 0;
> int i;
>
> - for (i = 0; i < MAX_TYPES; i++) {
> - if (i == reset_option)
> - buf += sprintf(buf, "[%s] ", reset_types[i]);
> - else
> - buf += sprintf(buf, "%s ", reset_types[i]);
> - }
> - buf += sprintf(buf, "\n");
> - return buf-start;
> + for (i = 0; i < MAX_TYPES; i++)
> + len += sysfs_emit_at(buf, len, i == reset_option ? "[%s] " : "%s ",
Are all checkers okay with this construct? IIRC something doesn't
like having such logic in where only a formatting string is expected.
--
i.
> + reset_types[i]);
> + len += sysfs_emit_at(buf, len, "\n");
> + return len;
> }
>
> /**
> @@ -194,7 +192,7 @@ static ssize_t reset_bios_store(struct kobject *kobj,
> static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
> char *buf)
> {
> - return sprintf(buf, "%d\n", wmi_priv.pending_changes);
> + return sysfs_emit(buf, "%d\n", wmi_priv.pending_changes);
> }
>
> static struct kobj_attribute reset_bios = __ATTR_RW(reset_bios);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
2026-03-05 12:48 ` Ilpo Järvinen
@ 2026-03-05 13:00 ` Thorsten Blum
2026-03-05 13:10 ` Ilpo Järvinen
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-03-05 13:00 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Prasanth Ksr, Hans de Goede, Dell.Client.Kernel,
platform-driver-x86, LKML
On 5. Mar 2026, at 13:48, Ilpo Järvinen wrote:
> On Thu, 5 Mar 2026, Thorsten Blum wrote:
>> Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
>> functions. sysfs_emit() and sysfs_emit_at() are preferred for formatting
>> sysfs output because they provide safer bounds checking.
>>
>> In reset_bios_show(), use sysfs_emit_at() to avoid manual buffer size
>> accounting.
>>
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
>> .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++----------
>> 1 file changed, 8 insertions(+), 10 deletions(-)
>> [...]
>> + for (i = 0; i < MAX_TYPES; i++)
>> + len += sysfs_emit_at(buf, len, i == reset_option ? "[%s] " : "%s ",
>
> Are all checkers okay with this construct? IIRC something doesn't
> like having such logic in where only a formatting string is expected.
You mean checkpatch? No warnings, but I can split it again if needed.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
2026-03-05 13:00 ` Thorsten Blum
@ 2026-03-05 13:10 ` Ilpo Järvinen
0 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2026-03-05 13:10 UTC (permalink / raw)
To: Thorsten Blum
Cc: Prasanth Ksr, Hans de Goede, Dell.Client.Kernel,
platform-driver-x86, LKML
[-- Attachment #1: Type: text/plain, Size: 1237 bytes --]
On Thu, 5 Mar 2026, Thorsten Blum wrote:
> On 5. Mar 2026, at 13:48, Ilpo Järvinen wrote:
> > On Thu, 5 Mar 2026, Thorsten Blum wrote:
> >> Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
> >> functions. sysfs_emit() and sysfs_emit_at() are preferred for formatting
> >> sysfs output because they provide safer bounds checking.
> >>
> >> In reset_bios_show(), use sysfs_emit_at() to avoid manual buffer size
> >> accounting.
> >>
> >> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> >> ---
> >> .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++----------
> >> 1 file changed, 8 insertions(+), 10 deletions(-)
> >> [...]
> >> + for (i = 0; i < MAX_TYPES; i++)
> >> + len += sysfs_emit_at(buf, len, i == reset_option ? "[%s] " : "%s ",
> >
> > Are all checkers okay with this construct? IIRC something doesn't
> > like having such logic in where only a formatting string is expected.
>
> You mean checkpatch? No warnings, but I can split it again if needed.
Unfortunately, I don't recall what it was anymore (I didn't expect it
to be checkpatch) and couldn't locate the change either but I'm pretty
sure somebody did split a similar elvis operator.
--
i.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-05 13:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 12:41 [PATCH] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions Thorsten Blum
2026-03-05 12:48 ` Ilpo Järvinen
2026-03-05 13:00 ` Thorsten Blum
2026-03-05 13:10 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox