1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

boot: Use cleanup handler to unload image

This also moves the message about failed image execution into
image_start() as we would otherwise show two error messages if
any of the preparatory steps failed.
This commit is contained in:
Jan Janssen 2022-02-07 13:05:56 +01:00 committed by Luca Boccassi
parent 93a72170bd
commit f386daa054
3 changed files with 17 additions and 18 deletions

View File

@ -2322,7 +2322,7 @@ static EFI_STATUS image_start(
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;
@ -2363,10 +2363,8 @@ static EFI_STATUS image_start(
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);
@ -2376,9 +2374,11 @@ static EFI_STATUS image_start(
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) {
@ -2623,11 +2623,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
(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;

View File

@ -6,17 +6,12 @@
#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;

View File

@ -86,6 +86,11 @@ static inline void file_closep(EFI_FILE **handle) {
(*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