mirror of
https://github.com/systemd/systemd
synced 2024-07-21 10:17:21 +00:00
boot: Unify protocol opening
We are using HandleProtocol everywhere except in these few cases. This unifies on HandleProtocol as it is simpler to use and equivalent to OpenProtocol. The only difference between the two is that OpenProtocol attributes the opened protocol to a firmware-owned handle instead of our image handle. This has no real use for regular UEFI applications as any protocols opened via BY_HANDLE or GET_PROTOCOL is not required to be closed. In fact, when a protocol is uninstalled it will do nothing more than reduce the open count for these.
This commit is contained in:
parent
2efddcb245
commit
b4eb2de7e3
|
@ -2647,13 +2647,7 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
|||
* By default, Shim uninstalls its protocol when calling StartImage(). */
|
||||
shim_retain_protocol();
|
||||
|
||||
err = BS->OpenProtocol(
|
||||
image,
|
||||
MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL),
|
||||
(void **) &loaded_image,
|
||||
image,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
err = BS->HandleProtocol(image, MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL), (void **) &loaded_image);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error getting a LoadedImageProtocol handle: %m");
|
||||
|
||||
|
@ -2669,10 +2663,10 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
|||
|
||||
config_load_all_entries(&config, loaded_image, loaded_image_path, root_dir);
|
||||
|
||||
if (config.entry_count == 0) {
|
||||
log_error("No loader found. Configuration files in \\loader\\entries\\*.conf are needed.");
|
||||
goto out;
|
||||
}
|
||||
if (config.entry_count == 0)
|
||||
return log_error_status(
|
||||
EFI_NOT_FOUND,
|
||||
"No loader found. Configuration files in \\loader\\entries\\*.conf are needed.");
|
||||
|
||||
/* select entry or show menu when key is pressed or timeout is set */
|
||||
if (config.force_menu || config.timeout_sec > 0)
|
||||
|
@ -2699,7 +2693,7 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
|||
if (menu) {
|
||||
efivar_set_time_usec(MAKE_GUID_PTR(LOADER), u"LoaderTimeMenuUSec", 0);
|
||||
if (!menu_run(&config, &entry, loaded_image_path))
|
||||
break;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/* if auto enrollment is activated, we try to load keys for the given entry. */
|
||||
|
@ -2725,15 +2719,11 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
|||
|
||||
err = image_start(image, entry);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
return err;
|
||||
|
||||
menu = true;
|
||||
config.timeout_sec = 0;
|
||||
}
|
||||
err = EFI_SUCCESS;
|
||||
out:
|
||||
BS->CloseProtocol(image, MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL), image, NULL);
|
||||
return err;
|
||||
}
|
||||
|
||||
DEFINE_EFI_MAIN_FUNCTION(run, "systemd-boot", /*wait_for_debugger=*/false);
|
||||
|
|
|
@ -117,19 +117,10 @@ EFI_STATUS initrd_unregister(EFI_HANDLE initrd_handle) {
|
|||
return EFI_SUCCESS;
|
||||
|
||||
/* get the LoadFile2 protocol that we allocated earlier */
|
||||
err = BS->OpenProtocol(
|
||||
initrd_handle,
|
||||
MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL),
|
||||
(void **) &loader,
|
||||
NULL,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
err = BS->HandleProtocol(initrd_handle, MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL), (void **) &loader);
|
||||
if (err != EFI_SUCCESS)
|
||||
return err;
|
||||
|
||||
/* close the handle */
|
||||
(void) BS->CloseProtocol(initrd_handle, MAKE_GUID_PTR(EFI_LOAD_FILE2_PROTOCOL), NULL, NULL);
|
||||
|
||||
/* uninstall all protocols thus destroying the handle */
|
||||
err = BS->UninstallMultipleProtocolInterfaces(
|
||||
initrd_handle, MAKE_GUID_PTR(EFI_DEVICE_PATH_PROTOCOL),
|
||||
|
|
|
@ -379,13 +379,7 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
|||
uint64_t loader_features = 0;
|
||||
EFI_STATUS err;
|
||||
|
||||
err = BS->OpenProtocol(
|
||||
image,
|
||||
MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL),
|
||||
(void **) &loaded_image,
|
||||
image,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
err = BS->HandleProtocol(image, MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL), (void **) &loaded_image);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error getting a LoadedImageProtocol handle: %m");
|
||||
|
||||
|
|
Loading…
Reference in a new issue