author: Geert Uytterhoeven <geert@linux-m68k.org> 2021-03-12 16:46:34 +0100
committer: Joshua Yeong <joshua.yeong@starfivetech.com> 2023-03-02 10:17:24 +0800
commit: 6976a471883fa5bf8765c4b377dd30bc98bdfdbf
parent: 49b7c5ce5baa80114fa7e7c4ec79e91743aebe03
Commit Summary:
Diffstat:
1 file changed, 2 insertions, 1 deletion
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 40f04cd04526..dfe6838edb14 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -147,7 +147,8 @@ static void __init init_resources(void)
bss_res.end = __pa_symbol(__bss_stop) - 1;
bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
- mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * sizeof(*mem_res);
+ /* + 1 as memblock_alloc() might increase memblock.reserved.cnt */
+ mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt + 1) * sizeof(*mem_res);
mem_res = memblock_alloc(mem_res_sz, SMP_CACHE_BYTES);
if (!mem_res)
panic("%s: Failed to allocate %zu bytes\n", __func__, mem_res_sz);