diff options
author | Warner Losh <imp@FreeBSD.org> | 2019-05-06 19:35:30 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2019-05-06 19:35:30 +0000 |
commit | 141b1c328d34a54b78d91481bfe5f465ee68c3c0 (patch) | |
tree | f65b45675ef60eda6a43b8e3d2bfcac2a75f4e28 /stand/efi/boot1 | |
parent | 8cb46437a770e6e48f7751b1e8e794c216bfc9c8 (diff) | |
download | src-141b1c328d34a54b78d91481bfe5f465ee68c3c0.tar.gz src-141b1c328d34a54b78d91481bfe5f465ee68c3c0.zip |
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.
Notes
Notes:
svn path=/head/; revision=347201
Diffstat (limited to 'stand/efi/boot1')
-rw-r--r-- | stand/efi/boot1/boot1.c | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/stand/efi/boot1/boot1.c b/stand/efi/boot1/boot1.c index bc32f7e84530..d325d53962d7 100644 --- a/stand/efi/boot1/boot1.c +++ b/stand/efi/boot1/boot1.c @@ -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); |