Continuing walk of a device path until the next compatible node will come in handy later as well, so factor that out into a new device_path_next_compatible_node(). No functional change intended. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- efi/devicepath.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/efi/devicepath.c b/efi/devicepath.c index 6ec0c3780f37..d562bf482955 100644 --- a/efi/devicepath.c +++ b/efi/devicepath.c @@ -801,33 +801,40 @@ u8 device_path_to_subtype(const struct efi_device_path *dev_path) return dev_path->sub_type; } +static const struct efi_device_path * +device_path_next_compatible_node(const struct efi_device_path *dev_path, + u8 type, u8 subtype) +{ + for (; !is_device_path_end(dev_path); + dev_path = next_device_path_node(dev_path)) { + + if (device_path_type(dev_path) != type) + continue; + + if (dev_path->sub_type != subtype) + continue; + + return dev_path; + } + + return NULL; +} char *device_path_to_partuuid(const struct efi_device_path *dev_path) { - const struct efi_device_path *dev_path_node; - struct harddrive_device_path *hd; - char *str = NULL;; - dev_path = unpack_device_path(dev_path); - for (dev_path_node = dev_path; !is_device_path_end(dev_path_node); - dev_path_node = next_device_path_node(dev_path_node)) { - - if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH) - continue; - - if (dev_path_node->sub_type != MEDIA_HARDDRIVE_DP) - continue; - - hd = (struct harddrive_device_path *)dev_path_node; + while ((dev_path = device_path_next_compatible_node(dev_path, + MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP))) { + struct harddrive_device_path *hd = + (struct harddrive_device_path *)dev_path; if (hd->signature_type != SIGNATURE_TYPE_GUID) continue; - str = xasprintf("%pUl", (efi_guid_t *)&(hd->signature[0])); - break; + return xasprintf("%pUl", (efi_guid_t *)&(hd->signature[0])); } - return str; + return NULL; } -- 2.39.2