Skip to content

Commit aa3e1ba

Browse files
petrpavlupalmer-dabbelt
authored andcommitted
riscv: Fix a number of free'd resources in init_resources()
Function init_resources() allocates a boot memory block to hold an array of resources which it adds to iomem_resource. The array is filled in from its end and the function then attempts to free any unused memory at the beginning. The problem is that size of the unused memory is incorrectly calculated and this can result in releasing memory which is in use by active resources. Their data then gets corrupted later when the memory is reused by a different part of the system. Fix the size of the released memory to correctly match the number of unused resource entries. Fixes: ffe0e52 ("RISC-V: Improve init_resources()") Signed-off-by: Petr Pavlu <[email protected]> Reviewed-by: Sunil V L <[email protected]> Acked-by: Nick Kossifidis <[email protected]> Tested-by: Sunil V L <[email protected]> Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1c8094e commit aa3e1ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ static void __init init_resources(void)
229229
}
230230

231231
/* Clean-up any unused pre-allocated resources */
232-
mem_res_sz = (num_resources - res_idx + 1) * sizeof(*mem_res);
233-
memblock_free(__pa(mem_res), mem_res_sz);
232+
if (res_idx >= 0)
233+
memblock_free(__pa(mem_res), (res_idx + 1) * sizeof(*mem_res));
234234
return;
235235

236236
error:

0 commit comments

Comments
 (0)