]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: use sysfs_emit in cpu_show_ghostwrite
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 7 Jun 2026 02:17:52 +0000 (20:17 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 7 Jun 2026 02:17:52 +0000 (20:17 -0600)
Replace sprintf() with sysfs_emit() in cpu_show_ghostwrite(), which is
preferred for formatting sysfs output because it provides safer bounds
checking.

While the current code only emits fixed strings that fit easily within
PAGE_SIZE, use sysfs_emit() to follow secure coding best practices.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260510165420.109453-3-thorsten.blum@linux.dev
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/kernel/bugs.c

index 3655fe7d678cd1123f427029c5433b003c3287d4..e5758e3f1c7ef4bed0569e948b922aa09441e9c4 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <linux/cpu.h>
 #include <linux/device.h>
-#include <linux/sprintf.h>
+#include <linux/sysfs.h>
 
 #include <asm/bugs.h>
 #include <asm/vendor_extensions/thead.h>
@@ -46,15 +46,15 @@ ssize_t cpu_show_ghostwrite(struct device *dev, struct device_attribute *attr, c
        if (IS_ENABLED(CONFIG_RISCV_ISA_XTHEADVECTOR)) {
                switch (ghostwrite_state) {
                case UNAFFECTED:
-                       return sprintf(buf, "Not affected\n");
+                       return sysfs_emit(buf, "Not affected\n");
                case MITIGATED:
-                       return sprintf(buf, "Mitigation: xtheadvector disabled\n");
+                       return sysfs_emit(buf, "Mitigation: xtheadvector disabled\n");
                case VULNERABLE:
                        fallthrough;
                default:
-                       return sprintf(buf, "Vulnerable\n");
+                       return sysfs_emit(buf, "Vulnerable\n");
                }
-       } else {
-               return sprintf(buf, "Not affected\n");
        }
+
+       return sysfs_emit(buf, "Not affected\n");
 }