From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Alexander Graf <graf@amazon.com>,
Pratyush Yadav <ptyadav@amazon.de>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH] kho: cleanup error handling in kho_populate()
Date: Thu, 22 Jan 2026 13:12:18 -0500 [thread overview]
Message-ID: <CA+CK2bB-JZEFp57rCYK8wGKoGP8U1NX_nLd=RRu3ozuVn339UQ@mail.gmail.com> (raw)
In-Reply-To: <20260122121757.575987-1-rppt@kernel.org>
On Thu, Jan 22, 2026 at 7:18 AM Mike Rapoport <rppt@kernel.org> wrote:
>
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> * 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
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> kernel/liveupdate/kexec_handover.c | 39 +++++++++++++-----------------
> 1 file changed, 17 insertions(+), 22 deletions(-)
>
> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
> index d4482b6e3cae..e248ce2e04b7 100644
> --- a/kernel/liveupdate/kexec_handover.c
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -1441,46 +1441,40 @@ void __init kho_memory_init(void)
> void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
> phys_addr_t scratch_phys, u64 scratch_len)
> {
> + unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch);
> struct kho_scratch *scratch = NULL;
> phys_addr_t mem_map_phys;
> void *fdt = NULL;
> - int err = 0;
> - unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch);
> + int err;
>
> /* Validate the input FDT */
> fdt = early_memremap(fdt_phys, fdt_len);
> if (!fdt) {
> pr_warn("setup: failed to memremap FDT (0x%llx)\n", fdt_phys);
> - err = -EFAULT;
> - goto out;
> + goto err_report;
> }
> err = fdt_check_header(fdt);
> if (err) {
> pr_warn("setup: handover FDT (0x%llx) is invalid: %d\n",
> fdt_phys, err);
> - err = -EINVAL;
> - goto out;
> + goto err_unmap_fdt;
> }
> err = fdt_node_check_compatible(fdt, 0, KHO_FDT_COMPATIBLE);
> if (err) {
> pr_warn("setup: handover FDT (0x%llx) is incompatible with '%s': %d\n",
> fdt_phys, KHO_FDT_COMPATIBLE, err);
> - err = -EINVAL;
> - goto out;
> + goto err_unmap_fdt;
> }
>
> mem_map_phys = kho_get_mem_map_phys(fdt);
> - if (!mem_map_phys) {
> - err = -ENOENT;
> - goto out;
> - }
> + if (!mem_map_phys)
> + goto err_unmap_fdt;
>
> scratch = early_memremap(scratch_phys, scratch_len);
> if (!scratch) {
> pr_warn("setup: failed to memremap scratch (phys=0x%llx, len=%lld)\n",
> scratch_phys, scratch_len);
> - err = -EFAULT;
> - goto out;
> + goto err_unmap_fdt;
> }
>
> /*
> @@ -1497,7 +1491,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
> if (WARN_ON(err)) {
> pr_warn("failed to mark the scratch region 0x%pa+0x%pa: %pe",
> &area->addr, &size, ERR_PTR(err));
> - goto out;
> + goto err_unmap_scratch;
> }
> pr_debug("Marked 0x%pa+0x%pa as scratch", &area->addr, &size);
> }
> @@ -1519,13 +1513,14 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
> kho_scratch_cnt = scratch_cnt;
> pr_info("found kexec handover data.\n");
>
> -out:
> - if (fdt)
> - early_memunmap(fdt, fdt_len);
> - if (scratch)
> - early_memunmap(scratch, scratch_len);
> - if (err)
> - pr_warn("disabling KHO revival: %d\n", err);
> + return;
> +
> +err_unmap_scratch:
> + early_memunmap(scratch, scratch_len);
> +err_unmap_fdt:
> + early_memunmap(fdt, fdt_len);
> +err_report:
> + pr_warn("disabling KHO revival\n");
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Nice clean-up, thanks.
Pasha
next prev parent reply other threads:[~2026-01-22 18:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 12:17 Mike Rapoport
2026-01-22 13:25 ` Mike Rapoport
2026-01-22 18:12 ` Pasha Tatashin [this message]
2026-01-27 9:29 ` Pratyush Yadav
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+CK2bB-JZEFp57rCYK8wGKoGP8U1NX_nLd=RRu3ozuVn339UQ@mail.gmail.com' \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=graf@amazon.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ptyadav@amazon.de \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox