Procházet zdrojové kódy

[efi] Provide efi_devpath_len()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown před 9 roky
rodič
revize
7107334391

+ 2
- 3
src/drivers/usb/usbio.c Zobrazit soubor

@@ -1492,15 +1492,14 @@ static int usbio_path ( struct usbio_device *usbio ) {
1492 1492
 	path = u.interface;
1493 1493
 
1494 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 1496
 	if ( len < sizeof ( *usbpath ) ) {
1498 1497
 		DBGC ( usbio, "USBIO %s underlength device path\n",
1499 1498
 		       efi_handle_name ( handle ) );
1500 1499
 		rc = -EINVAL;
1501 1500
 		goto err_underlength;
1502 1501
 	}
1503
-	usbpath = ( ( ( void * ) end ) - sizeof ( *usbpath ) );
1502
+	usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) );
1504 1503
 	if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) &&
1505 1504
 		 ( usbpath->Header.SubType == MSG_USB_DP ) ) ) {
1506 1505
 		DBGC ( usbio, "USBIO %s not a USB device path: ",

+ 1
- 2
src/image/efi_image.c Zobrazit soubor

@@ -73,8 +73,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) {
73 73
 	size_t len;
74 74
 
75 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 77
 	name_len = strlen ( image->name );
79 78
 	filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
80 79
 			 ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );

+ 1
- 0
src/include/ipxe/efi/efi_utils.h Zobrazit soubor

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

+ 2
- 10
src/interface/efi/efi_debug.c Zobrazit soubor

@@ -359,9 +359,6 @@ const __attribute__ (( pure )) char *
359 359
 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
360 360
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
361 361
 	static char text[256];
362
-	void *start;
363
-	void *end;
364
-	size_t max_len;
365 362
 	size_t len;
366 363
 	CHAR16 *wtext;
367 364
 
@@ -374,13 +371,8 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
374 371
 	/* If we have no DevicePathToText protocol then use a raw hex string */
375 372
 	if ( ! efidpt ) {
376 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 376
 		return text;
385 377
 	}
386 378
 

+ 1
- 2
src/interface/efi/efi_snp.c Zobrazit soubor

@@ -1033,8 +1033,7 @@ static int efi_snp_probe ( struct net_device *netdev ) {
1033 1033
 	}
1034 1034
 
1035 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 1037
 	snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
1039 1038
 				sizeof ( *path_end ) );
1040 1039
 	if ( ! snpdev->path ) {

+ 12
- 0
src/interface/efi/efi_utils.c Zobrazit soubor

@@ -50,6 +50,18 @@ EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
50 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 66
  * Locate parent device supporting a given protocol
55 67
  *

Načítá se…
Zrušit
Uložit