kho: move all memory retrieval logic to kho_mem_retrieve()

The memory retrieval logic is spread out across kho_mem_retrieve() and
kho_memory_init(). The incoming scratch area is initialized at
kho_memory_init(), and the error handling is done there too.

Consolidate all this logic into kho_mem_retrieve() to make the code
cleaner.

Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Link: https://patch.msgid.link/20260801084833.1897543-7-pratyush@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
This commit is contained in:
Pratyush Yadav (Google) 2026-08-01 10:48:15 +02:00 committed by Mike Rapoport (Microsoft)
parent e228b380cd
commit e9e4ecd4b7

View File

@ -1417,9 +1417,13 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size)
}
EXPORT_SYMBOL_GPL(kho_retrieve_subtree);
static int __init kho_mem_retrieve(const void *fdt)
static void __init kho_mem_retrieve(void)
{
const void *fdt = kho_get_fdt();
void *mem_map = kho_get_mem_map(fdt);
int err;
kho_scratch = phys_to_virt(kho_in.scratch_phys);
/*
* kho_get_mem_map() should always succeed. If it fails, kho_populate()
@ -1427,12 +1431,20 @@ static int __init kho_mem_retrieve(const void *fdt)
* retrieval.
*/
if (WARN_ON(!mem_map))
return -EINVAL;
return;
kho_in.radix_tree.root = mem_map;
mutex_init(&kho_in.radix_tree.lock);
return kho_radix_walk_tree(&kho_in.radix_tree,
kho_preserved_memory_reserve);
err = kho_radix_walk_tree(&kho_in.radix_tree, kho_preserved_memory_reserve);
if (err) {
/*
* Failed to initialize preserved memory. Clear FDT and radix
* so KHO users don't treat it as a KHO boot.
*/
kho_in.fdt_phys = 0;
kho_in.radix_tree.root = NULL;
}
}
static __init int kho_out_fdt_setup(void)
@ -1636,16 +1648,10 @@ fs_initcall(kho_init);
void __init kho_memory_init(void)
{
if (kho_in.scratch_phys) {
kho_scratch = phys_to_virt(kho_in.scratch_phys);
if (kho_mem_retrieve(kho_get_fdt())) {
kho_in.fdt_phys = 0;
kho_in.radix_tree.root = NULL;
}
} else {
if (kho_in.scratch_phys)
kho_mem_retrieve();
else
kho_reserve_scratch();
}
}
void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,