[PATCH 2/2] x86: add macro for_each_setup_data()
From: WANG Chao
Date: Wed Jan 07 2015 - 05:56:45 EST
A common task for parsing setup_data is to iterate over setup_data's
linked list, remap and do something and unmap. Now add macro
for_each_setup_data() to do that.
Signed-off-by: WANG Chao <chaowang@xxxxxxxxxx>
---
arch/x86/kernel/setup.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index c4648ada..1e24c37 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -424,35 +424,30 @@ static void __init reserve_initrd(void)
}
#endif /* CONFIG_BLK_DEV_INITRD */
+#define for_each_setup_data(pa_data, data) \
+ for (pa_data = boot_params.hdr.setup_data; \
+ pa_data && (data = early_memremap(pa_data, sizeof(*data))); \
+ pa_data = data->next, early_iounmap(data, sizeof(*data)))
+
static void __init parse_setup_data(void)
{
struct setup_data *data;
- u64 pa_data, pa_next;
-
- pa_data = boot_params.hdr.setup_data;
- while (pa_data) {
- u32 data_len, data_type;
-
- data = early_memremap(pa_data, sizeof(*data));
- data_len = data->len + sizeof(struct setup_data);
- data_type = data->type;
- pa_next = data->next;
- early_iounmap(data, sizeof(*data));
+ u64 pa_data;
- switch (data_type) {
+ for_each_setup_data(pa_data, data) {
+ switch (data->type) {
case SETUP_E820_EXT:
- parse_e820_ext(pa_data, data_len);
+ parse_e820_ext(pa_data, data->len + sizeof(*data));
break;
case SETUP_DTB:
add_dtb(pa_data);
break;
case SETUP_EFI:
- parse_efi_setup(pa_data, data_len);
+ parse_efi_setup(pa_data, data->len + sizeof(*data));
break;
default:
break;
}
- pa_data = pa_next;
}
}
@@ -462,14 +457,10 @@ static void __init e820_reserve_setup_data(void)
u64 pa_data;
int found = 0;
- pa_data = boot_params.hdr.setup_data;
- while (pa_data) {
- data = early_memremap(pa_data, sizeof(*data));
+ for_each_setup_data(pa_data, data) {
e820_update_range(pa_data, sizeof(*data)+data->len,
E820_RAM, E820_RESERVED_KERN);
found = 1;
- pa_data = data->next;
- early_iounmap(data, sizeof(*data));
}
if (!found)
return;
@@ -485,12 +476,8 @@ static void __init memblock_x86_reserve_range_setup_data(void)
struct setup_data *data;
u64 pa_data;
- pa_data = boot_params.hdr.setup_data;
- while (pa_data) {
- data = early_memremap(pa_data, sizeof(*data));
+ for_each_setup_data(pa_data, data) {
memblock_reserve(pa_data, sizeof(*data) + data->len);
- pa_data = data->next;
- early_iounmap(data, sizeof(*data));
}
}
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/