]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
efi/libstub: Use C99-style for loop to traverse handle buffer
authorArd Biesheuvel <ardb@kernel.org>
Thu, 19 Dec 2024 09:53:23 +0000 (10:53 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 14 Jan 2025 07:34:25 +0000 (08:34 +0100)
Tweak the for_each_efi_handle() macro in order to avoid the need on the
part of the caller to provide a loop counter variable.

Also move efi_get_handle_num() to the callers, so that each occurrence
can be replaced with the actual number returned by the simplified
LocateHandleBuffer API.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/gop.c
drivers/firmware/efi/libstub/pci.c
drivers/firmware/efi/libstub/x86-stub.c

index e95ce6ae5c26b070248aa10d5e003dd4f24b3c55..55553038b8507101c75a8341544ab2c50a128a89 100644 (file)
@@ -122,11 +122,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
 #define efi_get_handle_num(size)                                       \
        ((size) / (efi_is_native() ? sizeof(efi_handle_t) : 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++)
+#define for_each_efi_handle(handle, array, num)                                \
+       for (int __i = 0; __i < (num) &&                                \
+               ((handle = efi_get_handle_at((array), __i)) || true);   \
+            __i++)
 
 static inline
 void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
index ea5da307d542fc2a3dc991f04ccfed4f542c2a52..8eef63c48288daa6706a995c735767a6d743532d 100644 (file)
@@ -466,11 +466,10 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles)
 {
        efi_graphics_output_protocol_t *first_gop;
        efi_handle_t h;
-       int i;
 
        first_gop = NULL;
 
-       for_each_efi_handle(h, handles, size, i) {
+       for_each_efi_handle(h, handles, efi_get_handle_num(size)) {
                efi_status_t status;
 
                efi_graphics_output_protocol_t *gop;
index 99fb25d2bcf54ce8af04420d02486846b7566a1c..b0ba372c26c55dc25dc65653169c5ffa7b512e9b 100644 (file)
@@ -21,7 +21,6 @@ void efi_pci_disable_bridge_busmaster(void)
        efi_handle_t handle;
        efi_status_t status;
        u16 class, command;
-       int i;
 
        status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto,
                             NULL, &pci_handle_size, NULL);
@@ -46,7 +45,7 @@ void efi_pci_disable_bridge_busmaster(void)
                goto free_handle;
        }
 
-       for_each_efi_handle(handle, pci_handle, pci_handle_size, i) {
+       for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) {
                efi_pci_io_protocol_t *pci;
                unsigned long segment_nr, bus_nr, device_nr, func_nr;
 
@@ -82,7 +81,7 @@ void efi_pci_disable_bridge_busmaster(void)
                efi_bs_call(disconnect_controller, handle, NULL, NULL);
        }
 
-       for_each_efi_handle(handle, pci_handle, pci_handle_size, i) {
+       for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) {
                efi_pci_io_protocol_t *pci;
 
                status = efi_bs_call(handle_protocol, handle, &pci_proto,
index 0c51d8307000bab9deb0fd6f963bef7400ce5990..71173471faf6c96d3a2184eae0e4741c9ffb9e76 100644 (file)
@@ -124,7 +124,6 @@ static void setup_efi_pci(struct boot_params *params)
        unsigned long size = 0;
        struct setup_data *data;
        efi_handle_t h;
-       int i;
 
        status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
                             &pci_proto, NULL, &size, pci_handle);
@@ -150,7 +149,7 @@ static void setup_efi_pci(struct boot_params *params)
        while (data && data->next)
                data = (struct setup_data *)(unsigned long)data->next;
 
-       for_each_efi_handle(h, pci_handle, size, i) {
+       for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) {
                efi_pci_io_protocol_t *pci = NULL;
                struct pci_setup_rom *rom;