platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
Subsystems (2)
PATCH 1/1 platform/x86: dell-wmi-sysman: Use sysfs_emit{_at} in show functions
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.
--- .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +8 -10
@@ -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);
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Ilpo Järvinen
maintainerQuoted 32 lines · Thorsten Blum
Replace
sprintf()withsysfs_emit()andsysfs_emit_at()in sysfs show functions.sysfs_emit()andsysfs_emit_at()are preferred for formatting sysfs output because they provide safer bounds checking.In
reset_bios_show(), usesysfs_emit_at()to avoid manual buffer size accounting.Signed-off-by Thorsten Blum <[email protected]>--- .../platform/x86/dell/dell-wmi-sysman/sysman.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +2
-1@@ -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;
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c int map_wmi_error(int error_code) · line 151
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +2
-8-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.
Quoted 16 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +4
-1+ 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);
Quoted 8 lines · Ilpo Järvinen
Quoted 7 lines · Thorsten Blum
Replace
sprintf()withsysfs_emit()andsysfs_emit_at()in sysfs show functions.sysfs_emit()andsysfs_emit_at()are preferred for formatting sysfs output because they provide safer bounds checking.In
reset_bios_show(), usesysfs_emit_at()to avoid manual buffer size accounting.
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c int map_wmi_error(int error_code) · line 151
Quoted 7 lines
Signed-off-by Thorsten Blum <[email protected]>---
.../platform/x86/dell/dell-wmi-sysman/sysman.c| 18 ++++++++----------1 file changed, 8 insertions(+), 10 deletions(-)[...]
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +2
-0+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
Ilpo Järvinen
maintainerQuoted 20 lines · Thorsten Blum
Quoted 8 lines · Ilpo Järvinen
Quoted 7 lines · Thorsten Blum
Replace
sprintf()withsysfs_emit()andsysfs_emit_at()in sysfs show functions.sysfs_emit()andsysfs_emit_at()are preferred for formatting sysfs output because they provide safer bounds checking.In
reset_bios_show(), usesysfs_emit_at()to avoid manual buffer size accounting.Quoted 10 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c int map_wmi_error(int error_code) · line 151
Quoted 7 lines
Signed-off-by Thorsten Blum <[email protected]>---
.../platform/x86/dell/dell-wmi-sysman/sysman.c| 18 ++++++++----------1 file changed, 8 insertions(+), 10 deletions(-)[...]
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +2
-0+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.
Quoted 1 line
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.
Signature · 1 line
i.