From: Lennart Poettering Date: Mon, 15 Jul 2024 14:07:51 +0000 (+0200) Subject: stub: tweak setting of common Loader* EFI vars X-Git-Tag: v257-rc1~489^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77d496c083097b0cf4dca773c76f4f6625d7866f;p=thirdparty%2Fsystemd.git stub: tweak setting of common Loader* EFI vars Let's always check if we have data to set *first*, and only then check if an EFI var is already set. Checking for the EFI var is more expensive after all. --- diff --git a/src/boot/efi/export-vars.c b/src/boot/efi/export-vars.c index 3f59922a7e5..12fbd10b054 100644 --- a/src/boot/efi/export-vars.c +++ b/src/boot/efi/export-vars.c @@ -10,7 +10,8 @@ void export_common_variables(EFI_LOADED_IMAGE_PROTOCOL *loaded_image) { assert(loaded_image); /* Export the device path this image is started from, if it's not set yet */ - if (efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", NULL, NULL) != EFI_SUCCESS) { + if (loaded_image->DeviceHandle && + efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", NULL, NULL) != EFI_SUCCESS) { _cleanup_free_ char16_t *uuid = disk_get_part_uuid(loaded_image->DeviceHandle); if (uuid) efivar_set_str16(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", uuid, 0); @@ -22,8 +23,8 @@ void export_common_variables(EFI_LOADED_IMAGE_PROTOCOL *loaded_image) { * in which case there's simple nothing to set for us. (The UEFI spec doesn't really say who's wrong * here, i.e. whether FilePath may be NULL or not, hence handle this gracefully and check if FilePath * is non-NULL explicitly.) */ - if (efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderImageIdentifier", NULL, NULL) != EFI_SUCCESS && - loaded_image->FilePath) { + if (loaded_image->FilePath && + efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderImageIdentifier", NULL, NULL) != EFI_SUCCESS) { _cleanup_free_ char16_t *s = NULL; if (device_path_to_str(loaded_image->FilePath, &s) == EFI_SUCCESS) efivar_set_str16(MAKE_GUID_PTR(LOADER), u"LoaderImageIdentifier", s, 0);