From: "Pratyush Yadav (Google)" <[email protected]>

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) <[email protected]>
---
 kernel/liveupdate/kexec_handover.c | 31 ++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/kernel/liveupdate/kexec_handover.c 
b/kernel/liveupdate/kexec_handover.c
index 61e436f5077e..7e556afae283 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1412,8 +1412,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();
+       int err;
+
+       kho_scratch = phys_to_virt(kho_in.scratch_phys);
+
        /*
         * kho_get_mem_map() should always succeed. If it fails, kho_populate()
         * catches that and never sets kho_in.scratch_phys, which stops memory
@@ -1421,8 +1426,16 @@ static int __init kho_mem_retrieve(const void *fdt)
         */
        kho_in.radix_tree.root = kho_get_mem_map(fdt);
        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)
@@ -1626,16 +1639,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,
-- 
2.54.0.1032.g2f8565e1d1-goog


Reply via email to