diff options
author | Michael Brown <mcb30@ipxe.org> | 2023-01-23 19:12:49 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2023-01-23 19:27:13 +0000 |
commit | 1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4 (patch) | |
tree | 220d779957c96c81d558fd2286f352f319bf0edb /src/interface/efi/efi_path.c | |
parent | 204d39222a0ff9f91fdffc2809de0b7f5aaabbae (diff) | |
download | ipxe-1cd0a248cc54a8b2fadc0d2c287d2f3528b749b4.tar.gz |
[efi] Add efi_path_prev() utility function
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.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c index 50027b75a..b28ecddbb 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 ); } /** |