Skip to contentSkip to conversation

kernel/cpu.c: don't use snprintf() for sysfs attrs

PATCH New Alex Dewar 1 participant 1 message Aug 24, 2020 CPU hotplug

lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 kernel/cpu.c: don't use snprintf() for sysfs attrs

As per the documentation (Documentation/filesystems/sysfs.rst), snprintf() should not be used for formatting values returned by sysfs.

In these two instances, we know that the string will be <PAGE_SIZE in length, so just use sprintf().

Issue identified by Coccinelle.

---
 kernel/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cpu.c +2 -2
index 6ff2578ecf17d..31694e02df958 100644
@@ -2334,7 +2334,7 @@ show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	const char *state = smt_states[cpu_smt_control];
 
-	return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
+	return sprintf(buf, "%s\n", state);
 }
 
 static ssize_t
@@ -2348,7 +2348,7 @@ static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
 static ssize_t
 show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
+	return sprintf(buf, "%d\n", sched_smt_active());
 }
 static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
 
Signature · 1 line
2.28.0