efi: create memory map iteration helper
authorMark Salter <msalter@redhat.com>
Fri, 10 Jan 2014 19:26:06 +0000 (14:26 -0500)
committerMatt Fleming <matt.fleming@intel.com>
Mon, 14 Apr 2014 16:49:37 +0000 (17:49 +0100)
There are a lot of places in the kernel which iterate through an
EFI memory map. Most of these places use essentially the same
for-loop code. This patch adds a for_each_efi_memory_desc()
helper to clean up all of the existing duplicate code and avoid
more in the future.

Signed-off-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
include/linux/efi.h

index 6c100ff0cae4b6eb886e48530c9f48c858b0f257..82d0abb2b19f3823d4a9bfbe5c395733a2d6528e 100644 (file)
@@ -863,6 +863,12 @@ extern int efi_set_rtc_mmss(const struct timespec *now);
 extern void efi_reserve_boot_services(void);
 extern struct efi_memory_map memmap;
 
+/* Iterate through an efi_memory_map */
+#define for_each_efi_memory_desc(m, md)                                           \
+       for ((md) = (m)->map;                                              \
+            (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
+            (md) = (void *)(md) + (m)->desc_size)
+
 /**
  * efi_range_is_wc - check the WC bit on an address range
  * @start: starting kvirt address