From cbeda2012a693d81a51aa6694aa24da02c6e4f0b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 5 Mar 2026 12:24:35 +0000 Subject: [PATCH] [efi] Allow creating an image device handle with no parent device When we fall back to using our own loaded image's device handle (instead of the most recently opened SNP device handle), we may find that the device handle is no longer valid since we have disconnected the driver that originally provided it. Check for existence of the device path protocol on the identified parent handle, and choose not to attempt to set a parent-child relationship if the parent handle appears to no longer be valid. Signed-off-by: Michael Brown --- src/image/efi_image.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/image/efi_image.c b/src/image/efi_image.c index f293c82c7..0b4e257b5 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -230,8 +230,11 @@ static int efi_image_exec ( struct image *image ) { parent = efi_loaded_image->DeviceHandle; basepath = efi_loaded_image_path; netdev = NULL; - DBGC ( image, "EFIIMAGE %s using %s\n", - image->name, efi_devpath_text ( basepath ) ); + if ( efi_test ( parent, &efi_device_path_protocol_guid ) != 0 ) + parent = NULL; + DBGC ( image, "EFIIMAGE %s using %s%s\n", + image->name, efi_devpath_text ( basepath ), + ( parent ? "" : " (removed)" ) ); } /* Construct URI device path */ @@ -259,7 +262,8 @@ static int efi_image_exec ( struct image *image ) { image->name, efi_handle_name ( device ) ); /* Add as a child of the parent device */ - if ( ( rc = efi_child_add ( parent, device ) ) != 0 ) { + if ( ( parent != NULL ) && + ( rc = efi_child_add ( parent, device ) ) != 0 ) { DBGC ( image, "EFIIMAGE %s could not become child of %s: %s\n", image->name, efi_handle_name ( parent ), strerror ( rc ) ); @@ -454,7 +458,8 @@ static int efi_image_exec ( struct image *image ) { unregister_image ( image ); err_register_image: image->flags ^= toggle; - efi_child_del ( parent, device ); + if ( parent ) + efi_child_del ( parent, device ); err_child_add: bs->UninstallMultipleProtocolInterfaces ( device,