mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/5] efi: implement and use for_each_efi_config_table
Date: Mon, 10 Oct 2022 08:08:41 +0200	[thread overview]
Message-ID: <20221010060842.2083550-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221010060842.2083550-1-a.fatoum@pengutronix.de>

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@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




  parent reply	other threads:[~2022-10-10  6:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10  6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
2022-10-10  6:08 ` [PATCH 2/5] efi: capitalize enumeration constants Ahmad Fatoum
2022-10-10  6:08 ` [PATCH 3/5] hw_random: add EFI RNG driver Ahmad Fatoum
2022-10-10  6:08 ` Ahmad Fatoum [this message]
2022-10-10  6:08 ` [PATCH 5/5] efi: add device tree configuration table support Ahmad Fatoum
2022-10-13  6:33 ` [PATCH 1/5] efi: retire efi_bool_t Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010060842.2083550-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox