summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPratyush Yadav (Google) <pratyush@kernel.org>2026-08-01 10:48:15 +0200
committerMike Rapoport (Microsoft) <rppt@kernel.org>2026-08-04 09:18:44 +0300
commite9e4ecd4b7e9c089ca22bf783f801f62f3fc8ecd (patch)
treeacd00c5a90dd5cc78cf9f4073551d2d8c6619660
parente228b380cdb184089ac00cdf7ba232e3e6b9fbcf (diff)
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>
-rw-r--r--kernel/liveupdate/kexec_handover.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index d79047d9ebb6..b89fe9a9ccc8 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -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,