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.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -1417,9 +1417,13 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size) · 1416 unmodified lines | ||
| 1417 | 1417 | } |
| 1418 | 1418 | EXPORT_SYMBOL_GPL(kho_retrieve_subtree); |
| 1419 | 1419 | |
| 1420 | −static int __init kho_mem_retrieve(const void *fdt) | |
| 1420 | +static void __init kho_mem_retrieve(void) | |
| 1421 | 1421 | { |
| 1422 | + const void *fdt = kho_get_fdt(); | |
| 1422 | 1423 | void *mem_map = kho_get_mem_map(fdt); |
| 1424 | + int err; | |
| 1425 | + | |
| 1426 | + kho_scratch = phys_to_virt(kho_in.scratch_phys); | |
| 1423 | 1427 | |
| 1424 | 1428 | /* |
| 1425 | 1429 | * 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) · 1 unmodified line | ||
| 1427 | 1431 | * retrieval. |
| 1428 | 1432 | */ |
| 1429 | 1433 | if (WARN_ON(!mem_map)) |
| 1430 | − return -EINVAL; | |
| 1434 | + return; | |
| 1431 | 1435 | |
| 1432 | 1436 | kho_in.radix_tree.root = mem_map; |
| 1433 | 1437 | mutex_init(&kho_in.radix_tree.lock); |
| 1434 | − return kho_radix_walk_tree(&kho_in.radix_tree, | |
| 1435 | − kho_preserved_memory_reserve); | |
| 1438 | + | |
| 1439 | + err = kho_radix_walk_tree(&kho_in.radix_tree, kho_preserved_memory_reserve); | |
| 1440 | + if (err) { | |
| 1441 | + /* | |
| 1442 | + * Failed to initialize preserved memory. Clear FDT and radix | |
| 1443 | + * so KHO users don't treat it as a KHO boot. | |
| 1444 | + */ | |
| 1445 | + kho_in.fdt_phys = 0; | |
| 1446 | + kho_in.radix_tree.root = NULL; | |
| 1447 | + } | |
| 1436 | 1448 | } |
| 1437 | 1449 | |
| 1438 | 1450 | static __init int kho_out_fdt_setup(void) |
| @@ -1636,16 +1648,10 @@ fs_initcall(kho_init); · 197 unmodified lines | ||
| 1636 | 1648 | |
| 1637 | 1649 | void __init kho_memory_init(void) |
| 1638 | 1650 | { |
| 1639 | − if (kho_in.scratch_phys) { | |
| 1640 | − kho_scratch = phys_to_virt(kho_in.scratch_phys); | |
| 1641 | − | |
| 1642 | − if (kho_mem_retrieve(kho_get_fdt())) { | |
| 1643 | − kho_in.fdt_phys = 0; | |
| 1644 | − kho_in.radix_tree.root = NULL; | |
| 1645 | − } | |
| 1646 | − } else { | |
| 1651 | + if (kho_in.scratch_phys) | |
| 1652 | + kho_mem_retrieve(); | |
| 1653 | + else | |
| 1647 | 1654 | kho_reserve_scratch(); |
| 1648 | − } | |
| 1649 | 1655 | } |
| 1650 | 1656 | |
| 1651 | 1657 | void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, |