Re: [PATCH v2 1/3] of: reserved_mem: avoid unnecessary memory allocation when __reserved_mem_check_root() fails

From: Krzysztof Kozlowski

Date: Wed May 20 2026 - 03:49:45 EST


On Tue, May 19, 2026 at 04:24:25PM +0800, Wandun Chen wrote:
> total_reserved_mem_cnt will keep the init value (MAX_RESERVED_REGIONS)
> in fdt_scan_reserved_mem() if __reserved_mem_check_root() fails.
>
> fdt_scan_reserved_mem_late() calls alloc_reserved_mem_array() to
> allocate memory according to total_reserved_mem_cnt before
> __reserved_mem_check_root(), so if __reserved_mem_check_root() fails,
> the allocated array has nowhere to be used, so no need to allocate
> memory.
>
> Move alloc_reserved_mem_array() after __reserved_mem_check_root() to
> avoid potential memory waste.
>
> Signed-off-by: Wandun Chen <chenwandun@xxxxxxxxxxx>

Authorship/DCO mismatch.

> Tested-by: Meijing Zhao <zhaomeijing@xxxxxxxxxxx>

Best regards,
Krzysztof