Skip to content

Commit f2913d0

Browse files
RISC-V: Avoid dereferening NULL regs in die()
I don't think we can actually die() without a regs pointer, but the compiler was warning about a NULL check after a dereference. It seems prudent to just avoid the possibly-NULL dereference, given that when die()ing the system is already toast so who knows how we got there. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20220920200037.6727-1-palmer@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 1b5964b commit f2913d0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

arch/riscv/kernel/traps.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void die(struct pt_regs *regs, const char *str)
3333
{
3434
static int die_counter;
3535
int ret;
36+
long cause;
3637

3738
oops_enter();
3839

@@ -42,11 +43,13 @@ void die(struct pt_regs *regs, const char *str)
4243

4344
pr_emerg("%s [#%d]\n", str, ++die_counter);
4445
print_modules();
45-
show_regs(regs);
46+
if (regs)
47+
show_regs(regs);
4648

47-
ret = notify_die(DIE_OOPS, str, regs, 0, regs->cause, SIGSEGV);
49+
cause = regs ? regs->cause : -1;
50+
ret = notify_die(DIE_OOPS, str, regs, 0, cause, SIGSEGV);
4851

49-
if (regs && kexec_should_crash(current))
52+
if (kexec_should_crash(current))
5053
crash_kexec(regs);
5154

5255
bust_spinlocks(0);

0 commit comments

Comments
 (0)