[PATCH 4/5] efi: implement and use for_each_efi_config_table
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Oct 9 23:08:41 PDT 2022
Iterating over the system table is something we do at two places,
already and the third will soon follow. Use the occasion to factor the
loop head into a macro.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
drivers/bus/acpi.c | 6 ++----
drivers/efi/efi-device.c | 9 ++++-----
include/efi.h | 5 +++++
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 63d3f618b4fb..1d6069b6d82a 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -231,11 +231,9 @@ struct bus_type acpi_bus = {
static int efi_acpi_probe(void)
{
- efi_config_table_t *table = NULL;
- int i;
+ efi_config_table_t *ect, *table = NULL;
- for (i = 0; i < efi_sys_table->nr_tables; i++) {
- efi_config_table_t *ect = &efi_sys_table->tables[i];
+ for_each_efi_config_table(ect) {
/* take ACPI < 2 table only if no ACPI 2.0 is available */
if (!efi_guidcmp(ect->guid, EFI_ACPI_20_TABLE_GUID)) {
acpi_bus.name = "acpi2";
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6b903723524e..defde7018696 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -347,13 +347,12 @@ struct bus_type efi_bus = {
static void efi_businfo(struct device_d *dev)
{
- int i;
+ efi_config_table_t *t;
+ int i = 0;
printf("Tables:\n");
- for (i = 0; i < efi_sys_table->nr_tables; i++) {
- efi_config_table_t *t = &efi_sys_table->tables[i];
-
- printf(" %d: %pUl: %s\n", i, &t->guid,
+ for_each_efi_config_table(t) {
+ printf(" %d: %pUl: %s\n", i++, &t->guid,
efi_guid_string(&t->guid));
}
}
diff --git a/include/efi.h b/include/efi.h
index 149c4e74c6cb..36e08af67bf3 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -547,6 +547,11 @@ typedef struct {
unsigned long table;
} efi_config_table_t;
+#define for_each_efi_config_table(t) \
+ for (t = efi_sys_table->tables; \
+ t - efi_sys_table->tables < efi_sys_table->nr_tables; \
+ t++)
+
#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
#define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
--
2.30.2
More information about the barebox
mailing list