From: visa Date: Tue, 18 Jan 2022 07:44:37 +0000 (+0000) Subject: plic: Fix cpuid handling X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=985778ebca26751777e823064b37511eb8f13331;p=openbsd plic: Fix cpuid handling Make `cpu' signed so that the possible return value -1 from plic_get_cpuid() gets handled correctly in the (cpu < 0) condition. This prevents plic_attach() from updating sc_contexts[] out of bounds. When plic_get_cpuid() returns -1, ignore the entry and continue processing. The error is not fatal. It is normal that secondary CPUs are not found when running a non-MULTIPROCESSOR kernel on a multiprocessor machine. OK kettenis@ --- diff --git a/sys/arch/riscv64/dev/plic.c b/sys/arch/riscv64/dev/plic.c index f058d66aae7..a9f53b5b622 100644 --- a/sys/arch/riscv64/dev/plic.c +++ b/sys/arch/riscv64/dev/plic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: plic.c,v 1.8 2022/01/03 03:06:50 jsg Exp $ */ +/* $OpenBSD: plic.c,v 1.9 2022/01/18 07:44:37 visa Exp $ */ /* * Copyright (c) 2020, Mars Li @@ -162,7 +162,7 @@ plic_attach(struct device *parent, struct device *dev, void *aux) struct fdt_attach_args *faa; uint32_t *cells; uint32_t irq; - uint32_t cpu; + int cpu; int node; int len; int ncell; @@ -251,11 +251,8 @@ plic_attach(struct device *parent, struct device *dev, void *aux) /* Get the corresponding cpuid. */ cpu = plic_get_cpuid(OF_getnodebyphandle(cells[i])); - if (cpu < 0) { - printf(": invalid hart!\n"); - free(cells, M_TEMP, len); - return; - } + if (cpu < 0) + continue; /* * Set the enable and context register offsets for the CPU.