* [PATCH] riscv: hwprobe: avoid uninitialized variable use in hwprobe_arch_id()
@ 2025-10-18 15:32 Paul Walmsley
2025-10-20 18:17 ` Evan Green
0 siblings, 1 reply; 2+ messages in thread
From: Paul Walmsley @ 2025-10-18 15:32 UTC (permalink / raw)
To: linux-riscv; +Cc: Evan Green
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: ea3de9ce8aa280 ("RISC-V: Add a syscall for HW probing")
Cc: Evan Green <evan@rivosinc.com>
Signed-off-by: Paul Walmsley <pjw@kernel.org>
---
arch/riscv/kernel/sys_hwprobe.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c
index bc87bb9725fd..199d13f86f31 100644
--- a/arch/riscv/kernel/sys_hwprobe.c
+++ b/arch/riscv/kernel/sys_hwprobe.c
@@ -31,6 +31,11 @@ static void hwprobe_arch_id(struct riscv_hwprobe *pair,
bool first = true;
int cpu;
+ if (pair->key != RISCV_HWPROBE_KEY_MVENDORID &&
+ pair->key != RISCV_HWPROBE_KEY_MIMPID &&
+ pair->key != RISCV_HWPROBE_KEY_MARCHID)
+ goto out;
+
for_each_cpu(cpu, cpus) {
u64 cpu_id;
@@ -61,6 +66,7 @@ static void hwprobe_arch_id(struct riscv_hwprobe *pair,
}
}
+out:
pair->value = id;
}
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] riscv: hwprobe: avoid uninitialized variable use in hwprobe_arch_id()
2025-10-18 15:32 [PATCH] riscv: hwprobe: avoid uninitialized variable use in hwprobe_arch_id() Paul Walmsley
@ 2025-10-20 18:17 ` Evan Green
0 siblings, 0 replies; 2+ messages in thread
From: Evan Green @ 2025-10-20 18:17 UTC (permalink / raw)
To: Paul Walmsley; +Cc: linux-riscv
On Sat, Oct 18, 2025 at 8:32 AM Paul Walmsley <pjw@kernel.org> wrote:
>
> 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: ea3de9ce8aa280 ("RISC-V: Add a syscall for HW probing")
> Cc: Evan Green <evan@rivosinc.com>
> Signed-off-by: Paul Walmsley <pjw@kernel.org>
Reviewed-by: Evan Green <evan@rivosinc.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-20 18:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-18 15:32 [PATCH] riscv: hwprobe: avoid uninitialized variable use in hwprobe_arch_id() Paul Walmsley
2025-10-20 18:17 ` Evan Green
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).