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 <ardb@kernel.org>
This commit is contained in:
Ard Biesheuvel 2024-12-19 10:53:23 +01:00
parent 144d52dd8f
commit c14bca3f7a
4 changed files with 8 additions and 12 deletions

View 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)

View 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;

View 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,

View 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;