kho: cleanup error handling in kho_populate()

* use dedicated labels for error handling instead of checking if a pointer
  is not null to decide if it should be unmapped
* drop assignment of values to err that are only used to print a numeric
  error code, there are pr_warn()s for each failure already so printing a
  numeric error code in the next line does not add anything useful

Link: https://lkml.kernel.org/r/20260122121757.575987-1-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Mike Rapoport (Microsoft) 2026-01-22 14:17:57 +02:00 committed by Andrew Morton
parent 0895a000e4
commit b50634c5e8

View File

@ -1455,46 +1455,40 @@ void __init kho_memory_init(void)
void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len, void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
phys_addr_t scratch_phys, u64 scratch_len) phys_addr_t scratch_phys, u64 scratch_len)
{ {
unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch);
struct kho_scratch *scratch = NULL; struct kho_scratch *scratch = NULL;
phys_addr_t mem_map_phys; phys_addr_t mem_map_phys;
void *fdt = NULL; void *fdt = NULL;
int err = 0; int err;
unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch);
/* Validate the input FDT */ /* Validate the input FDT */
fdt = early_memremap(fdt_phys, fdt_len); fdt = early_memremap(fdt_phys, fdt_len);
if (!fdt) { if (!fdt) {
pr_warn("setup: failed to memremap FDT (0x%llx)\n", fdt_phys); pr_warn("setup: failed to memremap FDT (0x%llx)\n", fdt_phys);
err = -EFAULT; goto err_report;
goto out;
} }
err = fdt_check_header(fdt); err = fdt_check_header(fdt);
if (err) { if (err) {
pr_warn("setup: handover FDT (0x%llx) is invalid: %d\n", pr_warn("setup: handover FDT (0x%llx) is invalid: %d\n",
fdt_phys, err); fdt_phys, err);
err = -EINVAL; goto err_unmap_fdt;
goto out;
} }
err = fdt_node_check_compatible(fdt, 0, KHO_FDT_COMPATIBLE); err = fdt_node_check_compatible(fdt, 0, KHO_FDT_COMPATIBLE);
if (err) { if (err) {
pr_warn("setup: handover FDT (0x%llx) is incompatible with '%s': %d\n", pr_warn("setup: handover FDT (0x%llx) is incompatible with '%s': %d\n",
fdt_phys, KHO_FDT_COMPATIBLE, err); fdt_phys, KHO_FDT_COMPATIBLE, err);
err = -EINVAL; goto err_unmap_fdt;
goto out;
} }
mem_map_phys = kho_get_mem_map_phys(fdt); mem_map_phys = kho_get_mem_map_phys(fdt);
if (!mem_map_phys) { if (!mem_map_phys)
err = -ENOENT; goto err_unmap_fdt;
goto out;
}
scratch = early_memremap(scratch_phys, scratch_len); scratch = early_memremap(scratch_phys, scratch_len);
if (!scratch) { if (!scratch) {
pr_warn("setup: failed to memremap scratch (phys=0x%llx, len=%lld)\n", pr_warn("setup: failed to memremap scratch (phys=0x%llx, len=%lld)\n",
scratch_phys, scratch_len); scratch_phys, scratch_len);
err = -EFAULT; goto err_unmap_fdt;
goto out;
} }
/* /*
@ -1511,7 +1505,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
if (WARN_ON(err)) { if (WARN_ON(err)) {
pr_warn("failed to mark the scratch region 0x%pa+0x%pa: %pe", pr_warn("failed to mark the scratch region 0x%pa+0x%pa: %pe",
&area->addr, &size, ERR_PTR(err)); &area->addr, &size, ERR_PTR(err));
goto out; goto err_unmap_scratch;
} }
pr_debug("Marked 0x%pa+0x%pa as scratch", &area->addr, &size); pr_debug("Marked 0x%pa+0x%pa as scratch", &area->addr, &size);
} }
@ -1533,13 +1527,14 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
kho_scratch_cnt = scratch_cnt; kho_scratch_cnt = scratch_cnt;
pr_info("found kexec handover data.\n"); pr_info("found kexec handover data.\n");
out: return;
if (fdt)
early_memunmap(fdt, fdt_len); err_unmap_scratch:
if (scratch) early_memunmap(scratch, scratch_len);
early_memunmap(scratch, scratch_len); err_unmap_fdt:
if (err) early_memunmap(fdt, fdt_len);
pr_warn("disabling KHO revival: %d\n", err); err_report:
pr_warn("disabling KHO revival\n");
} }
/* Helper functions for kexec_file_load */ /* Helper functions for kexec_file_load */