Skip to content

Commit

Permalink
riscv/efi_stub: Fix get_boot_hartid_from_fdt() return value
Browse files Browse the repository at this point in the history
The get_boot_hartid_from_fdt() function currently returns U32_MAX
for failure case which is not correct because U32_MAX is a valid
hartid value. This patch fixes the issue by returning error code.

Cc: <[email protected]>
Fixes: d707174 ("RISC-V: Add EFI stub support.")
Signed-off-by: Sunil V L <[email protected]>
Reviewed-by: Heinrich Schuchardt <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
  • Loading branch information
vlsunil authored and ardbiesheuvel committed Feb 28, 2022
1 parent f5390cd commit dcf0c83
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions drivers/firmware/efi/libstub/riscv-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,34 @@ typedef void __noreturn (*jump_kernel_func)(unsigned int, unsigned long);

static u32 hartid;

static u32 get_boot_hartid_from_fdt(void)
static int get_boot_hartid_from_fdt(void)
{
const void *fdt;
int chosen_node, len;
const fdt32_t *prop;

fdt = get_efi_config_table(DEVICE_TREE_GUID);
if (!fdt)
return U32_MAX;
return -EINVAL;

chosen_node = fdt_path_offset(fdt, "/chosen");
if (chosen_node < 0)
return U32_MAX;
return -EINVAL;

prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len);
if (!prop || len != sizeof(u32))
return U32_MAX;
return -EINVAL;

return fdt32_to_cpu(*prop);
hartid = fdt32_to_cpu(*prop);
return 0;
}

efi_status_t check_platform_features(void)
{
hartid = get_boot_hartid_from_fdt();
if (hartid == U32_MAX) {
int ret;

ret = get_boot_hartid_from_fdt();
if (ret) {
efi_err("/chosen/boot-hartid missing or invalid!\n");
return EFI_UNSUPPORTED;
}
Expand Down

0 comments on commit dcf0c83

Please sign in to comment.