Browse Source

[efi] Provide efi_devpath_len()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
7107334391

+ 2
- 3
src/drivers/usb/usbio.c View File

1492
 	path = u.interface;
1492
 	path = u.interface;
1493
 
1493
 
1494
 	/* Locate end of device path and sanity check */
1494
 	/* Locate end of device path and sanity check */
1495
-	end = efi_devpath_end ( path );
1496
-	len = ( ( ( void * ) end ) - ( ( void * ) path ) );
1495
+	len = efi_devpath_len ( path );
1497
 	if ( len < sizeof ( *usbpath ) ) {
1496
 	if ( len < sizeof ( *usbpath ) ) {
1498
 		DBGC ( usbio, "USBIO %s underlength device path\n",
1497
 		DBGC ( usbio, "USBIO %s underlength device path\n",
1499
 		       efi_handle_name ( handle ) );
1498
 		       efi_handle_name ( handle ) );
1500
 		rc = -EINVAL;
1499
 		rc = -EINVAL;
1501
 		goto err_underlength;
1500
 		goto err_underlength;
1502
 	}
1501
 	}
1503
-	usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
1502
+	usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) );
1504
 	if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) &&
1503
 	if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) &&
1505
 		 ( usbpath->Header.SubType == MSG_USB_DP ) ) ) {
1504
 		 ( usbpath->Header.SubType == MSG_USB_DP ) ) ) {
1506
 		DBGC ( usbio, "USBIO %s not a USB device path: ",
1505
 		DBGC ( usbio, "USBIO %s not a USB device path: ",

+ 1
- 2
src/image/efi_image.c View File

73
 	size_t len;
73
 	size_t len;
74
 
74
 
75
 	/* Calculate device path lengths */
75
 	/* Calculate device path lengths */
76
-	end = efi_devpath_end ( parent );
77
-	prefix_len = ( ( void * ) end - ( void * ) parent );
76
+	prefix_len = efi_devpath_len ( parent );
78
 	name_len = strlen ( image->name );
77
 	name_len = strlen ( image->name );
79
 	filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
78
 	filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
80
 			 ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );
79
 			 ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );

+ 1
- 0
src/include/ipxe/efi/efi_utils.h View File

15
 
15
 
16
 extern EFI_DEVICE_PATH_PROTOCOL *
16
 extern EFI_DEVICE_PATH_PROTOCOL *
17
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
17
 efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
18
+extern size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path );
18
 extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
19
 extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
19
 			       EFI_HANDLE *parent );
20
 			       EFI_HANDLE *parent );
20
 extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
21
 extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );

+ 2
- 10
src/interface/efi/efi_debug.c View File

359
 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
359
 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
360
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
360
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
361
 	static char text[256];
361
 	static char text[256];
362
-	void *start;
363
-	void *end;
364
-	size_t max_len;
365
 	size_t len;
362
 	size_t len;
366
 	CHAR16 *wtext;
363
 	CHAR16 *wtext;
367
 
364
 
374
 	/* If we have no DevicePathToText protocol then use a raw hex string */
371
 	/* If we have no DevicePathToText protocol then use a raw hex string */
375
 	if ( ! efidpt ) {
372
 	if ( ! efidpt ) {
376
 		DBG ( "[No DevicePathToText]" );
373
 		DBG ( "[No DevicePathToText]" );
377
-		start = path;
378
-		end = efi_devpath_end ( path );
379
-		len = ( end - start );
380
-		max_len = ( ( sizeof ( text ) - 1 /* NUL */ ) / 2 /* "xx" */ );
381
-		if ( len > max_len )
382
-			len = max_len;
383
-		base16_encode ( start, len, text, sizeof ( text ) );
374
+		len = efi_devpath_len ( path );
375
+		base16_encode ( path, len, text, sizeof ( text ) );
384
 		return text;
376
 		return text;
385
 	}
377
 	}
386
 
378
 

+ 1
- 2
src/interface/efi/efi_snp.c View File

1033
 	}
1033
 	}
1034
 
1034
 
1035
 	/* Allocate the new device path */
1035
 	/* Allocate the new device path */
1036
-	path_end = efi_devpath_end ( path.path );
1037
-	path_prefix_len = ( ( ( void * ) path_end ) - ( ( void * ) path.path ));
1036
+	path_prefix_len = efi_devpath_len ( path.path );
1038
 	snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
1037
 	snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
1039
 				sizeof ( *path_end ) );
1038
 				sizeof ( *path_end ) );
1040
 	if ( ! snpdev->path ) {
1039
 	if ( ! snpdev->path ) {

+ 12
- 0
src/interface/efi/efi_utils.c View File

50
 	return path;
50
 	return path;
51
 }
51
 }
52
 
52
 
53
+/**
54
+ * Find length of device path (excluding terminator)
55
+ *
56
+ * @v path		Path to device
57
+ * @ret path_len	Length of device path
58
+ */
59
+size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
60
+	EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path );
61
+
62
+	return ( ( ( void * ) end ) - ( ( void * ) path ) );
63
+}
64
+
53
 /**
65
 /**
54
  * Locate parent device supporting a given protocol
66
  * Locate parent device supporting a given protocol
55
  *
67
  *

Loading…
Cancel
Save