public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
@ 2026-03-05 14:09 Thorsten Blum
  2026-03-09 14:58 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-03-05 14:09 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>
---
Changes in v2:
- Use if-else instead of inline ternary operator (Ilpo)
- Link to v1: https://lore.kernel.org/lkml/20260305124126.255026-2-thorsten.blum@linux.dev/
---
 drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 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..80820451710b 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,17 @@ 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]);
+			len += sysfs_emit_at(buf, len, "[%s] ", reset_types[i]);
 		else
-			buf += sprintf(buf, "%s ", reset_types[i]);
+			len += sysfs_emit_at(buf, len, "%s ", reset_types[i]);
 	}
-	buf += sprintf(buf, "\n");
-	return buf-start;
+	len += sysfs_emit_at(buf, len, "\n");
+	return len;
 }
 
 /**
@@ -194,7 +195,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] 2+ messages in thread

* Re: [PATCH v2] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
  2026-03-05 14:09 [PATCH v2] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions Thorsten Blum
@ 2026-03-09 14:58 ` Ilpo Järvinen
  0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2026-03-09 14:58 UTC (permalink / raw)
  To: Prasanth Ksr, Hans de Goede, Thorsten Blum
  Cc: Dell.Client.Kernel, platform-driver-x86, linux-kernel

On Thu, 05 Mar 2026 15:09:13 +0100, 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.
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
      commit: 9b0ee949f7940786b0292329c2ae1f5dd63e69ba

--
 i.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-09 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 14:09 [PATCH v2] platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions Thorsten Blum
2026-03-09 14:58 ` 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