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@
-/* $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 <mengshi.li.mars@gmail.com>
struct fdt_attach_args *faa;
uint32_t *cells;
uint32_t irq;
- uint32_t cpu;
+ int cpu;
int node;
int len;
int ncell;
/* 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.