diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index b894403ff6777132327bcb3230cece53c0093fc8..0915192bbb7368a9ee82db200c15e62df0f64d02 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -349,8 +349,10 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		set_load_options(&loaded_image_info, "efi_selftest");
 		/* Execute the test */
 		r = efi_selftest(&loaded_image_info, &systab);
+		efi_restore_gd();
 		free(loaded_image_info.load_options);
-		return r;
+		list_del(&loaded_image_info_obj.link);
+		return r != EFI_SUCCESS;
 	} else
 #endif
 	if (!strcmp(argv[1], "bootmgr")) {