summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2023-01-23 20:12:49 +0100
committerMichael Brown2023-01-23 20:27:13 +0100
commit1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4 (patch)
tree220d779957c96c81d558fd2286f352f319bf0edb
parent[efi] Add efi_path_terminate() utility function (diff)
downloadipxe-1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4.tar.gz
ipxe-1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4.tar.xz
ipxe-1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4.zip
[efi] Add efi_path_prev() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/include/ipxe/efi/efi_path.h3
-rw-r--r--src/interface/efi/efi_path.c27
2 files changed, 23 insertions, 7 deletions
diff --git a/src/include/ipxe/efi/efi_path.h b/src/include/ipxe/efi/efi_path.h
index 98b922ac..e75ae42c 100644
--- a/src/include/ipxe/efi/efi_path.h
+++ b/src/include/ipxe/efi/efi_path.h
@@ -37,6 +37,9 @@ static inline void efi_path_terminate ( EFI_DEVICE_PATH_PROTOCOL *end ) {
extern EFI_DEVICE_PATH_PROTOCOL *
efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path );
extern EFI_DEVICE_PATH_PROTOCOL *
+efi_path_prev ( EFI_DEVICE_PATH_PROTOCOL *path,
+ EFI_DEVICE_PATH_PROTOCOL *curr );
+extern EFI_DEVICE_PATH_PROTOCOL *
efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
extern unsigned int efi_path_vlan ( EFI_DEVICE_PATH_PROTOCOL *path );
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
index 50027b75..b28ecddb 100644
--- a/src/interface/efi/efi_path.c
+++ b/src/interface/efi/efi_path.c
@@ -66,20 +66,33 @@ EFI_DEVICE_PATH_PROTOCOL * efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path ) {
}
/**
+ * Find previous element of device path
+ *
+ * @v path Device path, or NULL for no path
+ * @v curr Current element in device path, or NULL for end of path
+ * @ret prev Previous element in device path, or NULL
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_path_prev ( EFI_DEVICE_PATH_PROTOCOL *path,
+ EFI_DEVICE_PATH_PROTOCOL *curr ) {
+ EFI_DEVICE_PATH_PROTOCOL *tmp;
+
+ /* Find immediately preceding element */
+ while ( ( tmp = efi_path_next ( path ) ) != curr ) {
+ path = tmp;
+ }
+
+ 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;
- /* Find end of device path */
- while ( ( next = efi_path_next ( path ) ) != NULL ) {
- path = next;
- }
-
- return path;
+ return efi_path_prev ( path, NULL );
}
/**