]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Allow creating an image device handle with no parent device
authorMichael Brown <mcb30@ipxe.org>
Thu, 5 Mar 2026 12:24:35 +0000 (12:24 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 5 Mar 2026 13:25:25 +0000 (13:25 +0000)
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 <mcb30@ipxe.org>
src/image/efi_image.c

index f293c82c74c462dd6bb8c9c961b01f1d174ad508..0b4e257b5b97203b139fe72c1a3222ef655cdfd0 100644 (file)
@@ -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,