Simplify boot1 allocation of handles.

There's no need to pre-malloc the number of handles. Instead call
LocateHandles twice, once to get the size, and once to get the
data.
This commit is contained in:
Warner Losh 2019-05-06 19:35:30 +00:00
parent 8cb46437a7
commit 141b1c328d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=347201

View File

@ -47,8 +47,6 @@ static const boot_module_t *boot_modules[] =
};
#define NUM_BOOT_MODULES nitems(boot_modules)
/* The initial number of handles used to query EFI for partitions. */
#define NUM_HANDLES_INIT 24
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
@ -420,32 +418,17 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
BS->Exit(IH, EFI_OUT_OF_RESOURCES, 0, NULL);
#endif
/* Get all the device handles */
hsize = (UINTN)NUM_HANDLES_INIT * sizeof(EFI_HANDLE);
hsize = 0;
BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL,
&hsize, NULL);
handles = malloc(hsize);
if (handles == NULL)
printf("Failed to allocate %d handles\n", NUM_HANDLES_INIT);
status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL,
&hsize, handles);
switch (status) {
case EFI_SUCCESS:
break;
case EFI_BUFFER_TOO_SMALL:
free(handles);
handles = malloc(hsize);
if (handles == NULL)
efi_panic(EFI_OUT_OF_RESOURCES, "Failed to allocate %d handles\n",
NUM_HANDLES_INIT);
status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
NULL, &hsize, handles);
if (status != EFI_SUCCESS)
efi_panic(status, "Failed to get device handles\n");
break;
default:
efi_panic(EFI_OUT_OF_RESOURCES, "Failed to allocate %d handles\n",
hsize);
status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
NULL, &hsize, handles);
if (status != EFI_SUCCESS)
efi_panic(status, "Failed to get device handles\n");
break;
}
/* Scan all partitions, probing with all modules. */
nhandles = hsize / sizeof(*handles);