[PATCH] riscv: Fix a number of free'd resources in init_resources()
Palmer Dabbelt
palmer at dabbelt.com
Fri Aug 20 10:33:32 PDT 2021
On Sat, 07 Aug 2021 10:54:50 PDT (-0700), petr.pavlu at suse.com wrote:
> 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: ffe0e5261268 ("RISC-V: Improve init_resources()")
> Signed-off-by: Petr Pavlu <petr.pavlu at suse.com>
> ---
> arch/riscv/kernel/setup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 18bd0e4bc36c..120b2f6f71bc 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -229,8 +229,8 @@ static void __init init_resources(void)
> }
>
> /* Clean-up any unused pre-allocated resources */
> - mem_res_sz = (num_resources - res_idx + 1) * sizeof(*mem_res);
> - memblock_free(__pa(mem_res), mem_res_sz);
> + if (res_idx >= 0)
> + memblock_free(__pa(mem_res), (res_idx + 1) * sizeof(*mem_res));
> return;
>
> error:
Thanks, this is on fixes.
More information about the linux-riscv
mailing list