]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 5 Mar 2026 14:09:13 +0000 (15:09 +0100)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 9 Mar 2026 14:15:14 +0000 (16:15 +0200)
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>
Link: https://patch.msgid.link/20260305140912.258090-2-thorsten.blum@linux.dev
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c

index 6241f16fd3dae6ea1b531209fb91cf112205dc99..069cf958a90d026ff70e363bdbf3eee25a40ec5e 100644 (file)
@@ -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);