Re: [PATCH 01/11] of: reserved_mem: fix region count for nodes with multiple reg entries

From: Wandun

Date: Thu May 07 2026 - 04:42:12 EST



在 2026/5/6 09:47, Rob Herring 写道:
On Wed, Apr 29, 2026 at 02:58:21PM +0800, Chen Wandun wrote:
When a reserved-memory node contains multiple reg entries (e.g.,
reg = <base1 size1>, <base2 size2>), the count used for
total_reserved_mem_cnt is wrong in two places:

1) __reserved_mem_reserve_reg() returns 0 on success regardless of how
many regions it reserved in memblock. The caller in
fdt_scan_reserved_mem() then increments count by just 1.
Just to make sure, more than 1 worked before the referenced commits? It
would be easier to just define we only expect/support 1 entry.
Looking at the pre-8a6e02d0c00e code, __reserved_mem_reserve_reg()
reserved memblock memory for all reg entries, but only called
fdt_reserved_mem_save_node() for the first one (guarded by an 'if (first)' flag).

So multiple reg entries were never fully supported: subsequent entries
got their memory reserved in memblock, but their metadata was lost
and driver-specific init callbacks were never invoked for them.

The referenced commits made this worse by also breaking the count
tracking, but the root limitation predates them.

I support documenting "only 1 entry supported" based on the
following reasons:

  - of_reserved_mem_lookup() does a name-based linear scan and returns
    the *first* matching entry. A node with N reg entries would create
    N entries with identical names; entries [1..N-1] are permanently
    unreachable via lookup.

  - Drivers like CMA and DMA coherent are designed to initialize a
    single contiguous pool per node_init call. Calling node_init
    multiple times with the same FDT node is not a supported usage.



2) fdt_scan_reserved_mem_late() uses of_flat_dt_get_addr_size() which
only reads the first reg entry. Subsequent entries are never
initialized via fdt_init_reserved_mem_node(), so their metadata is
lost.

Fix both issues:
- Make __reserved_mem_reserve_reg() return the actual number of
regions successfully reserved. Update the caller to accumulate
the returned count.
- Rewrite fdt_scan_reserved_mem_late() to use
of_flat_dt_get_addr_size_prop() and iterate all reg entries,
initializing each one via fdt_init_reserved_mem_node().

Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory regions are processed")
Fixes: 00c9a452a235 ("of: reserved_mem: Add code to dynamically allocate reserved_mem array")