From b9e19b077ed54139dd23cc69e65af9fcb9cc8e78 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 6 May 2019 18:39:27 +0000 Subject: [PATCH] Abstract out efi_devpath_to_handle to search for a handle that matches the desired devpath. --- stand/efi/include/efilib.h | 1 + stand/efi/libefi/devpath.c | 22 ++++++++++++++++++++++ stand/efi/libefi/efipart.c | 17 +++-------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h index ebf889375424..154e73af5f5d 100644 --- a/stand/efi/include/efilib.h +++ b/stand/efi/include/efilib.h @@ -95,6 +95,7 @@ UINTN efi_devpath_length(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_name_to_devpath(const char *path); EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path); void efi_devpath_free(EFI_DEVICE_PATH *dp); +EFI_HANDLE efi_devpath_to_handle(EFI_DEVICE_PATH *path, EFI_HANDLE *handles, unsigned nhandles); int efi_status_to_errno(EFI_STATUS); EFI_STATUS errno_to_efi_status(int errno); diff --git a/stand/efi/libefi/devpath.c b/stand/efi/libefi/devpath.c index 46b42cce2762..44da1b3b6738 100644 --- a/stand/efi/libefi/devpath.c +++ b/stand/efi/libefi/devpath.c @@ -269,3 +269,25 @@ efi_devpath_length(EFI_DEVICE_PATH *path) path = NextDevicePathNode(path); return ((UINTN)path - (UINTN)start) + DevicePathNodeLength(path); } + +EFI_HANDLE +efi_devpath_to_handle(EFI_DEVICE_PATH *path, EFI_HANDLE *handles, unsigned nhandles) +{ + unsigned i; + EFI_DEVICE_PATH *media, *devpath; + EFI_HANDLE h; + + media = efi_devpath_to_media_path(path); + if (media == NULL) + return (NULL); + for (i = 0; i < nhandles; i++) { + h = handles[i]; + devpath = efi_lookup_devpath(h); + if (devpath == NULL) + continue; + if (!efi_devpath_match_node(media, efi_devpath_to_media_path(devpath))) + continue; + return (h); + } + return (NULL); +} diff --git a/stand/efi/libefi/efipart.c b/stand/efi/libefi/efipart.c index e893652bc3a6..63e3af4f097a 100644 --- a/stand/efi/libefi/efipart.c +++ b/stand/efi/libefi/efipart.c @@ -140,23 +140,12 @@ efiblk_get_pdinfo(struct devdesc *dev) pdinfo_t * efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path) { - unsigned i; - EFI_DEVICE_PATH *media, *devpath; EFI_HANDLE h; - media = efi_devpath_to_media_path(path); - if (media == NULL) + h = efi_devpath_to_handle(path, efipart_handles, efipart_nhandles); + if (h == NULL) return (NULL); - for (i = 0; i < efipart_nhandles; i++) { - h = efipart_handles[i]; - devpath = efi_lookup_devpath(h); - if (devpath == NULL) - continue; - if (!efi_devpath_match_node(media, efi_devpath_to_media_path(devpath))) - continue; - return (efiblk_get_pdinfo_by_handle(h)); - } - return (NULL); + return (efiblk_get_pdinfo_by_handle(h)); } static bool