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.
Showing the changes to include/linux (1 of 3 files). Show all
Unified · Split
| @@ -48,6 +48,19 @@ typedef u16 efi_char16_t; /* UNICODE character */ · 47 unmodified lines | |||
| 48 | typedef u64 efi_physical_addr_t; | 48 | typedef u64 efi_physical_addr_t; |
| 49 | typedef void *efi_handle_t; | 49 | typedef 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 as | 65 | * 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 alignment | 66 | * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment |