From 7107334391d05bd60a44daaee732c19860ca87bc Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 10 Sep 2015 23:22:43 +0100 Subject: [efi] Provide efi_devpath_len() Signed-off-by: Michael Brown --- src/drivers/usb/usbio.c | 5 ++--- src/image/efi_image.c | 3 +-- src/include/ipxe/efi/efi_utils.h | 1 + src/interface/efi/efi_debug.c | 12 ++---------- src/interface/efi/efi_snp.c | 3 +-- src/interface/efi/efi_utils.c | 12 ++++++++++++ 6 files changed, 19 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c index a80f7c8..2c15200 100644 --- a/src/drivers/usb/usbio.c +++ b/src/drivers/usb/usbio.c @@ -1492,15 +1492,14 @@ static int usbio_path ( struct usbio_device *usbio ) { path = u.interface; /* Locate end of device path and sanity check */ - end = efi_devpath_end ( path ); - len = ( ( ( void * ) end ) - ( ( void * ) path ) ); + len = efi_devpath_len ( path ); if ( len < sizeof ( *usbpath ) ) { DBGC ( usbio, "USBIO %s underlength device path\n", efi_handle_name ( handle ) ); rc = -EINVAL; goto err_underlength; } - usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) ); + usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) ); if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) && ( usbpath->Header.SubType == MSG_USB_DP ) ) ) { DBGC ( usbio, "USBIO %s not a USB device path: ", diff --git a/src/image/efi_image.c b/src/image/efi_image.c index 89d57bb..79dfe06 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -73,8 +73,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) { size_t len; /* Calculate device path lengths */ - end = efi_devpath_end ( parent ); - prefix_len = ( ( void * ) end - ( void * ) parent ); + prefix_len = efi_devpath_len ( parent ); name_len = strlen ( image->name ); filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH + ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) ); diff --git a/src/include/ipxe/efi/efi_utils.h b/src/include/ipxe/efi/efi_utils.h index 57268da..67acba1 100644 --- a/src/include/ipxe/efi/efi_utils.h +++ b/src/include/ipxe/efi/efi_utils.h @@ -15,6 +15,7 @@ struct device; extern EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ); +extern size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ); extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent ); extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index ed18ff9..069ca3f 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -359,9 +359,6 @@ const __attribute__ (( pure )) char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; static char text[256]; - void *start; - void *end; - size_t max_len; size_t len; CHAR16 *wtext; @@ -374,13 +371,8 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) { /* If we have no DevicePathToText protocol then use a raw hex string */ if ( ! efidpt ) { DBG ( "[No DevicePathToText]" ); - start = path; - end = efi_devpath_end ( path ); - len = ( end - start ); - max_len = ( ( sizeof ( text ) - 1 /* NUL */ ) / 2 /* "xx" */ ); - if ( len > max_len ) - len = max_len; - base16_encode ( start, len, text, sizeof ( text ) ); + len = efi_devpath_len ( path ); + base16_encode ( path, len, text, sizeof ( text ) ); return text; } diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index 2ff1e97..5729a39 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -1033,8 +1033,7 @@ static int efi_snp_probe ( struct net_device *netdev ) { } /* Allocate the new device path */ - path_end = efi_devpath_end ( path.path ); - path_prefix_len = ( ( ( void * ) path_end ) - ( ( void * ) path.path )); + path_prefix_len = efi_devpath_len ( path.path ); snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) + sizeof ( *path_end ) ); if ( ! snpdev->path ) { diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c index 1bebaa5..4dc7541 100644 --- a/src/interface/efi/efi_utils.c +++ b/src/interface/efi/efi_utils.c @@ -51,6 +51,18 @@ EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) { } /** + * Find length of device path (excluding terminator) + * + * @v path Path to device + * @ret path_len Length of device path + */ +size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ) { + EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path ); + + return ( ( ( void * ) end ) - ( ( void * ) path ) ); +} + +/** * Locate parent device supporting a given protocol * * @v device EFI device handle -- cgit v1.1