summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2019-12-24 16:10:07 +0100
committerIngo Molnar <mingo@kernel.org>2019-12-25 10:49:16 +0100
commit2732ea0d5c0a67ec86bfbde2bd68b6152e23ec4e (patch)
tree46b819245ac67d0a279a10701fa2a5b784bbc29b /include
parenta8147dba75b188bff87d4ad072db84a0b70d716d (diff)
downloadlinux-2732ea0d5c0a67ec86bfbde2bd68b6152e23ec4e.tar.gz
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>
Diffstat (limited to 'include')
-rw-r--r--include/linux/efi.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 561db9deedae..8d267715ce22 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -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