[PATCH v2 02/15] efi/riscv: libstub: Don't set image_size in handle_kernel_image()
Jonathan Cameron
jonathan.cameron at oss.qualcomm.com
Wed Oct 21 09:00:19 PDT 2026
On Fri, 2 Oct 2026 20:31:39 -0300
Jason Gunthorpe <jgg at nvidia.com> wrote:
> Sashiko points out the image_size should only be set if image_addr was
> reassigned to some allocated memory. If image_size is not zero then the
> caller will free the image_addr pointer.
>
> efi_kaslr_relocate_kernel() never works like that, if it changes
> image_addr to allocated memory the free is done through reserve_size.
>
> Fixes: b7ac4b8ee73d ("riscv: libstub: Implement KASLR by using generic functions")
> Signed-off-by: Jason Gunthorpe <jgg at nvidia.com>
Hi Jason,
This made me curious on the differences across architectures...
Looks like there is perhaps some room to make them look more similar at least!
One small step below.
> ---
> drivers/firmware/efi/libstub/riscv-stub.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c
> index e7d9204baee312..725b634c517919 100644
> --- a/drivers/firmware/efi/libstub/riscv-stub.c
> +++ b/drivers/firmware/efi/libstub/riscv-stub.c
> @@ -37,17 +37,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
> kernel_codesize = __init_text_end - _start;
> kernel_memsize = kernel_size + (_end - _edata);
> *image_addr = (unsigned long)_start;
> - *image_size = kernel_memsize;
> - *reserve_size = *image_size;
> + *reserve_size = kernel_memsize;
>
> status = efi_kaslr_relocate_kernel(image_addr,
> reserve_addr, reserve_size,
> kernel_size, kernel_codesize, kernel_memsize,
> efi_kaslr_get_phys_seed(image_handle));
> - if (status != EFI_SUCCESS) {
> + if (status != EFI_SUCCESS)
> efi_err("Failed to relocate kernel\n");
This print is replicated at the caller, so can drop this as well I think.
> - *image_size = 0;
> - }
>
> return status;
> }
More information about the linux-riscv
mailing list