summaryrefslogtreecommitdiff
path: root/kernel/cpu.c
diff options
context:
space:
mode:
authorBradley Morgan <include@grrlz.net>2026-06-19 16:37:18 +0000
committerThomas Gleixner <tglx@kernel.org>2026-06-21 20:44:00 +0200
commit86f436567f2516a0083b210bedc933544826a2c3 (patch)
treeaa671b2fef14701c1ee87dc90861297a52a2e8d2 /kernel/cpu.c
parent673db10729fb121ea1b16fe57791a0cb9eac1eb5 (diff)
downloadlinux-next-86f436567f2516a0083b210bedc933544826a2c3.tar.gz
linux-next-86f436567f2516a0083b210bedc933544826a2c3.zip
cpu: hotplug: Bound hotplug states sysfs output
states_show() adds CPU hotplug state names into a single sysfs buffer using sprintf(). With enough registered states, this can write past the end of the PAGE_SIZE buffer. Use sysfs_emit_at() so output is bounded. Fixes: 98f8cdce1db5 ("cpu/hotplug: Add sysfs state interface") Signed-off-by: Bradley Morgan <include@grrlz.net> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260619163719.12103-2-include@grrlz.net
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r--kernel/cpu.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 3ed24c711e3f..77fdb2013ab8 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2865,21 +2865,17 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
.name = "hotplug",
};
-static ssize_t states_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+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;