stub: tweak setting of common Loader* EFI vars
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Jul 2024 14:07:51 +0000 (16:07 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Sep 2024 04:48:27 +0000 (06:48 +0200)
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.

src/boot/efi/export-vars.c

index 3f59922a7e5c03dc39be3efa659f52f85ee5d02b..12fbd10b054da2f9715a742a9373bf9f91bcd59c 100644 (file)
@@ -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);