summaryrefslogtreecommitdiffstats
path: root/src/interface/efi/efi_path.c
diff options
context:
space:
mode:
authorMichael Brown2022-12-22 14:33:38 +0100
committerMichael Brown2022-12-22 14:34:28 +0100
commit099e4d39b355a10b0bc7d23bb0e96615bf06470b (patch)
tree0d92cb14109fe07f6055d5c67b256646629bfcc0 /src/interface/efi/efi_path.c
parent[efi] Allow passing a NULL device path to path utility functions (diff)
downloadipxe-099e4d39b355a10b0bc7d23bb0e96615bf06470b.tar.gz
ipxe-099e4d39b355a10b0bc7d23bb0e96615bf06470b.tar.xz
ipxe-099e4d39b355a10b0bc7d23bb0e96615bf06470b.zip
[efi] Expose efi_path_next() utility function
Provide a single central implementation of the logic for stepping through elements of an EFI device path. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface/efi/efi_path.c')
-rw-r--r--src/interface/efi/efi_path.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
index 1a95a3b9..937d3c70 100644
--- a/src/interface/efi/efi_path.c
+++ b/src/interface/efi/efi_path.c
@@ -41,18 +41,42 @@
*/
/**
+ * Find next element in device path
+ *
+ * @v path Device path, or NULL
+ * @v next Next element in device path, or NULL if at end
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+
+ /* Check for non-existent device path */
+ if ( ! path )
+ return NULL;
+
+ /* Check for end of device path */
+ if ( path->Type == END_DEVICE_PATH_TYPE )
+ return NULL;
+
+ /* Move to next component of the device path */
+ path = ( ( ( void * ) path ) +
+ /* There's this amazing new-fangled thing known as
+ * a UINT16, but who wants to use one of those? */
+ ( ( path->Length[1] << 8 ) | path->Length[0] ) );
+
+ return path;
+}
+
+/**
* Find end of device path
*
* @v path Device path, or NULL
* @ret path_end End of device path, or NULL
*/
EFI_DEVICE_PATH_PROTOCOL * efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+ EFI_DEVICE_PATH_PROTOCOL *next;
- while ( path && ( path->Type != END_DEVICE_PATH_TYPE ) ) {
- path = ( ( ( void * ) path ) +
- /* There's this amazing new-fangled thing known as
- * a UINT16, but who wants to use one of those? */
- ( ( path->Length[1] << 8 ) | path->Length[0] ) );
+ /* Find end of device path */
+ while ( ( next = efi_path_next ( path ) ) != NULL ) {
+ path = next;
}
return path;