const ConfigEntry *entry) {
_cleanup_(devicetree_cleanup) struct devicetree_state dtstate = {};
- EFI_HANDLE image;
+ _cleanup_(unload_imagep) EFI_HANDLE image = NULL;
_cleanup_freepool_ EFI_DEVICE_PATH *path = NULL;
CHAR16 *options;
EFI_STATUS err;
err = BS->OpenProtocol(image, &LoadedImageProtocol, (void **)&loaded_image,
parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(err)) {
- log_error_stall(L"Error getting LoadedImageProtocol handle: %r", err);
- goto out_unload;
- }
+ if (EFI_ERROR(err))
+ return log_error_status_stall(err, L"Error getting LoadedImageProtocol handle: %r", err);
loaded_image->LoadOptions = options;
loaded_image->LoadOptionsSize = StrSize(loaded_image->LoadOptions);
efivar_set_time_usec(LOADER_GUID, L"LoaderTimeExecUSec", 0);
err = BS->StartImage(image, NULL, NULL);
-out_unload:
- BS->UnloadImage(image);
- return err;
+ graphics_mode(FALSE);
+ if (err != EFI_SUCCESS)
+ return log_error_status_stall(err, L"Failed to execute %s (%s): %r", entry->title_show, entry->loader, err);
+
+ return EFI_SUCCESS;
}
static void config_free(Config *config) {
(void) process_random_seed(root_dir, config.random_seed_mode);
err = image_start(image, &config, entry);
- if (EFI_ERROR(err)) {
- graphics_mode(FALSE);
- log_error_stall(L"Failed to execute %s (%s): %r", entry->title_show, entry->loader, err);
+ if (err != EFI_SUCCESS)
+ /* Not using EFI_ERROR here because positive values are also errors like with any
+ * other (userspace) program. */
goto out;
- }
menu = TRUE;
config.timeout_sec = 0;
#include "drivers.h"
#include "util.h"
-static void efi_unload_image(EFI_HANDLE *h) {
- if (*h)
- (void) BS->UnloadImage(*h);
-}
-
static EFI_STATUS load_one_driver(
EFI_HANDLE parent_image,
EFI_LOADED_IMAGE *loaded_image,
const CHAR16 *fname) {
- _cleanup_(efi_unload_image) EFI_HANDLE image = NULL;
+ _cleanup_(unload_imagep) EFI_HANDLE image = NULL;
_cleanup_freepool_ EFI_DEVICE_PATH *path = NULL;
_cleanup_freepool_ CHAR16 *spath = NULL;
EFI_STATUS err;
(*handle)->Close(*handle);
}
+static inline void unload_imagep(EFI_HANDLE *image) {
+ if (*image)
+ (void) BS->UnloadImage(*image);
+}
+
/*
* Allocated random UUID, intended to be shared across tools that implement
* the (ESP)\loader\entries\<vendor>-<revision>.conf convention and the