Skip to content

Commit c14bca3

Browse files
committed
efi/libstub: Use C99-style for loop to traverse handle buffer
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 <[email protected]>
1 parent 144d52d commit c14bca3

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

drivers/firmware/efi/libstub/efistub.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
122122
#define efi_get_handle_num(size) \
123123
((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
124124

125-
#define for_each_efi_handle(handle, array, size, i) \
126-
for (i = 0; \
127-
i < efi_get_handle_num(size) && \
128-
((handle = efi_get_handle_at((array), i)) || true); \
129-
i++)
125+
#define for_each_efi_handle(handle, array, num) \
126+
for (int __i = 0; __i < (num) && \
127+
((handle = efi_get_handle_at((array), __i)) || true); \
128+
__i++)
130129

131130
static inline
132131
void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)

drivers/firmware/efi/libstub/gop.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,10 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles)
466466
{
467467
efi_graphics_output_protocol_t *first_gop;
468468
efi_handle_t h;
469-
int i;
470469

471470
first_gop = NULL;
472471

473-
for_each_efi_handle(h, handles, size, i) {
472+
for_each_efi_handle(h, handles, efi_get_handle_num(size)) {
474473
efi_status_t status;
475474

476475
efi_graphics_output_protocol_t *gop;

drivers/firmware/efi/libstub/pci.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ void efi_pci_disable_bridge_busmaster(void)
2121
efi_handle_t handle;
2222
efi_status_t status;
2323
u16 class, command;
24-
int i;
2524

2625
status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto,
2726
NULL, &pci_handle_size, NULL);
@@ -46,7 +45,7 @@ void efi_pci_disable_bridge_busmaster(void)
4645
goto free_handle;
4746
}
4847

49-
for_each_efi_handle(handle, pci_handle, pci_handle_size, i) {
48+
for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) {
5049
efi_pci_io_protocol_t *pci;
5150
unsigned long segment_nr, bus_nr, device_nr, func_nr;
5251

@@ -82,7 +81,7 @@ void efi_pci_disable_bridge_busmaster(void)
8281
efi_bs_call(disconnect_controller, handle, NULL, NULL);
8382
}
8483

85-
for_each_efi_handle(handle, pci_handle, pci_handle_size, i) {
84+
for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) {
8685
efi_pci_io_protocol_t *pci;
8786

8887
status = efi_bs_call(handle_protocol, handle, &pci_proto,

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static void setup_efi_pci(struct boot_params *params)
124124
unsigned long size = 0;
125125
struct setup_data *data;
126126
efi_handle_t h;
127-
int i;
128127

129128
status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL,
130129
&pci_proto, NULL, &size, pci_handle);
@@ -150,7 +149,7 @@ static void setup_efi_pci(struct boot_params *params)
150149
while (data && data->next)
151150
data = (struct setup_data *)(unsigned long)data->next;
152151

153-
for_each_efi_handle(h, pci_handle, size, i) {
152+
for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) {
154153
efi_pci_io_protocol_t *pci = NULL;
155154
struct pci_setup_rom *rom;
156155

0 commit comments

Comments
 (0)