Skip to contentSkip to conversation

cpu/hotplug: Use sysfs_emit_at() in states_show()

PATCH In review Bradley Morgan 2 participants 2 messages Jul 4 – Jul 7 CPU hotplug

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu/hotplug: Use sysfs_emit_at() in states_show()

Replace raw sprintf() and manual buffer arithmetic with sysfs_emit_at(), which bounds output to PAGE_SIZE.

---
 kernel/cpu.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/cpu.c +3 -6
index f975bb34915b..25d88cf2bb15 100644
@@ -2857,18 +2857,15 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
 static ssize_t states_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {
-	ssize_t cur, res = 0;
+	ssize_t res = 0;
 	int i;
 
 	mutex_lock(&cpuhp_state_mutex);
 	for (i = CPUHP_OFFLINE; i <= CPUHP_ONLINE; i++) {
 		struct cpuhp_step *sp = cpuhp_get_step(i);
 
-		if (sp->name) {
-			cur = sprintf(buf, "%3d: %s\n", i, sp->name);
-			buf += cur;
-			res += cur;
-		}
+		if (sp->name)
+			res += sysfs_emit_at(buf, res, "%3d: %s\n", i, sp->name);
 	}
 	mutex_unlock(&cpuhp_state_mutex);
 	return res;
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 2 lines · Bradley Morgan

Replace raw sprintf() and manual buffer arithmetic with sysfs_emit_at(), which bounds output to PAGE_SIZE.

Seems you failed to keep track of your patch flood. :)

86f436567f25 ("cpu: hotplug: Bound hotplug states sysfs output")