History

efi/libstub: Use a helper to iterate over a EFI handle array

Iterating over a EFI handle array is a bit finicky, since we have to take mixed mode into account, where handles are only 32-bit while the native efi_handle_t type is 64-bit. So introduce a helper, and replace the various occurrences of this pattern.

Ard Biesheuvel committed 6 years ago

Commit 2732ea01 parent a8147db3 files · +20 −16Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/efi.h+13−0
@@ -48,6 +48,19 @@ typedef u16 efi_char16_t; /* UNICODE character */ · 47 unmodified lines
48typedef u64 efi_physical_addr_t;48typedef u64 efi_physical_addr_t;
49typedef void *efi_handle_t;49typedef void *efi_handle_t;
50 50
51#define efi_get_handle_at(array, idx) \
52 (efi_is_64bit() ? (efi_handle_t)(unsigned long)((u64 *)(array))[idx] \
53 : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
54
55#define efi_get_handle_num(size) \
56 ((size) / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)))
57
58#define for_each_efi_handle(handle, array, size, i) \
59 for (i = 0; \
60 i < efi_get_handle_num(size) && \
61 ((handle = efi_get_handle_at((array), i)) || true); \
62 i++)
63
51/*64/*
52 * The UEFI spec and EDK2 reference implementation both define EFI_GUID as65 * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
53 * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment66 * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment