Skip to contentSkip to conversation

thermal: intel: Use sysfs_emit in sysfs show functions

PATCH Applied Thorsten Blum 2 participants 2 messages Jan 13 – Jan 15 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: intel: Use sysfs_emit in sysfs show functions

Replace sprintf() with sysfs_emit() in sysfs show functions. sysfs_emit() is preferred to format sysfs output as it provides better bounds checking.

---
 drivers/thermal/intel/therm_throt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/intel/therm_throt.c +3 -2
index debc94e2dc16..44fa4dd15dd1 100644
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/smp.h>
+#include <linux/sysfs.h>
 #include <linux/cpu.h>
 
 #include <asm/processor.h>
@@ -144,8 +145,8 @@ static ssize_t therm_throt_device_show_##event##_##name(		\
 									\
 	preempt_disable();	/* CPU hotplug */			\
 	if (cpu_online(cpu)) {						\
-		ret = sprintf(buf, "%lu\n",				\
-			      per_cpu(thermal_state, cpu).event.name);	\
+		ret = sysfs_emit(buf, "%lu\n",				\
+			per_cpu(thermal_state, cpu).event.name);	\
 	} else								\
 		ret = 0;						\
 	preempt_enable();						\
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer Applied
#1 lore raw
Quoted 24 lines · Thorsten Blum

Replace sprintf() with sysfs_emit() in sysfs show functions. sysfs_emit() is preferred to format sysfs output as it provides better bounds checking.

---
 drivers/thermal/intel/therm_throt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/thermal/intel/therm_throt.c +1 -0
index debc94e2dc16..44fa4dd15dd1 100644
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/smp.h>
+#include <linux/sysfs.h>
 #include <linux/cpu.h>
 
 #include <asm/processor.h>
@@ -144,8 +145,8 @@ static ssize_t therm_throt_device_show_##event##_##name(            \
                                                                        \

drivers/thermal/intel/therm_throt.c static ssize_t therm_throt_device_show_##event##_##name( \

Quoted 10 lines
drivers/thermal/intel/therm_throt.c +2 -3
        preempt_disable();      /* CPU hotplug */                       \
        if (cpu_online(cpu)) {                                          \
-               ret = sprintf(buf, "%lu\n",                             \
-                             per_cpu(thermal_state, cpu).event.name);  \
+               ret = sysfs_emit(buf, "%lu\n",                          \
+                       per_cpu(thermal_state, cpu).event.name);        \
        } else                                                          \
                ret = 0;                                                \
        preempt_enable();                                               \
--

Applied as 6.20 material, thanks!