Skip to content

Commit b7776a8

Browse files
author
Paul Walmsley
committed
riscv: hwprobe: avoid uninitialized variable use in hwprobe_arch_id()
Resolve this smatch warning: arch/riscv/kernel/sys_hwprobe.c:50 hwprobe_arch_id() error: uninitialized symbol 'cpu_id'. This could happen if hwprobe_arch_id() was called with a key ID of something other than MVENDORID, MIMPID, and MARCHID. This does not happen in the current codebase. The only caller of hwprobe_arch_id() is a function that only passes one of those three key IDs. For the sake of reducing static analyzer warning noise, and in the unlikely event that hwprobe_arch_id() is someday called with some other key ID, validate hwprobe_arch_id()'s input to ensure that 'cpu_id' is always initialized before use. Fixes: ea3de9c ("RISC-V: Add a syscall for HW probing") Cc: Evan Green <[email protected]> Signed-off-by: Paul Walmsley <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2dc99ea commit b7776a8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ static void hwprobe_arch_id(struct riscv_hwprobe *pair,
3131
bool first = true;
3232
int cpu;
3333

34+
if (pair->key != RISCV_HWPROBE_KEY_MVENDORID &&
35+
pair->key != RISCV_HWPROBE_KEY_MIMPID &&
36+
pair->key != RISCV_HWPROBE_KEY_MARCHID)
37+
goto out;
38+
3439
for_each_cpu(cpu, cpus) {
3540
u64 cpu_id;
3641

@@ -61,6 +66,7 @@ static void hwprobe_arch_id(struct riscv_hwprobe *pair,
6166
}
6267
}
6368

69+
out:
6470
pair->value = id;
6571
}
6672

0 commit comments

Comments
 (0)