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. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Cc: Arvind Sankar <nivedita@alum.mit.edu> Cc: Borislav Petkov <bp@alien8.de> Cc: James Morse <james.morse@arm.com> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191224151025.32482-8-ardb@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
a8147dba75
commit
2732ea0d5c
3 changed files with 20 additions and 16 deletions
|
|
@ -48,6 +48,19 @@ typedef u16 efi_char16_t; /* UNICODE character */
|
|||
typedef u64 efi_physical_addr_t;
|
||||
typedef void *efi_handle_t;
|
||||
|
||||
#define efi_get_handle_at(array, idx) \
|
||||
(efi_is_64bit() ? (efi_handle_t)(unsigned long)((u64 *)(array))[idx] \
|
||||
: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
|
||||
|
||||
#define efi_get_handle_num(size) \
|
||||
((size) / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)))
|
||||
|
||||
#define for_each_efi_handle(handle, array, size, i) \
|
||||
for (i = 0; \
|
||||
i < efi_get_handle_num(size) && \
|
||||
((handle = efi_get_handle_at((array), i)) || true); \
|
||||
i++)
|
||||
|
||||
/*
|
||||
* The UEFI spec and EDK2 reference implementation both define EFI_GUID as
|
||||
* struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue