]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi: add common implementation for loop finding EFI configuration tables 25350/head
authorLennart Poettering <lennart@poettering.net>
Wed, 14 Dec 2022 17:48:52 +0000 (18:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 14 Dec 2022 18:16:54 +0000 (19:16 +0100)
src/boot/efi/devicetree.c
src/boot/efi/random-seed.c
src/boot/efi/util.c
src/boot/efi/util.h

index daba5582aad8f6db919045d7fae7502f1c815aad..12015fce6b8533bb06d3509cb795c4730a3a46ac 100644 (file)
@@ -8,13 +8,6 @@
 
 #define FDT_V1_SIZE (7*4)
 
-static void *get_dtb_table(void) {
-        for (UINTN i = 0; i < ST->NumberOfTableEntries; i++)
-                if (efi_guid_equal(&ST->ConfigurationTable[i].VendorGuid, &EfiDtbTableGuid))
-                        return ST->ConfigurationTable[i].VendorTable;
-        return NULL;
-}
-
 static EFI_STATUS devicetree_allocate(struct devicetree_state *state, UINTN size) {
         UINTN pages = DIV_ROUND_UP(size, EFI_PAGE_SIZE);
         EFI_STATUS err;
@@ -81,7 +74,7 @@ EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir
         assert(root_dir);
         assert(name);
 
-        state->orig = get_dtb_table();
+        state->orig = find_configuration_table(&EfiDtbTableGuid);
         if (!state->orig)
                 return EFI_UNSUPPORTED;
 
@@ -121,7 +114,7 @@ EFI_STATUS devicetree_install_from_memory(struct devicetree_state *state,
         assert(state);
         assert(dtb_buffer && dtb_length > 0);
 
-        state->orig = get_dtb_table();
+        state->orig = find_configuration_table(&EfiDtbTableGuid);
         if (!state->orig)
                 return EFI_UNSUPPORTED;
 
index bdaed2625a64419fffe62dd885881806e50795d0..5b0693dfe1182c9f9555bc53ebc0e05347102123 100644 (file)
@@ -141,11 +141,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir) {
         /* Some basic domain separation in case somebody uses this data elsewhere */
         sha256_process_bytes(HASH_LABEL, sizeof(HASH_LABEL) - 1, &hash);
 
-        for (size_t i = 0; i < ST->NumberOfTableEntries; ++i)
-                if (efi_guid_equal(&ST->ConfigurationTable[i].VendorGuid, &(const EFI_GUID) LINUX_EFI_RANDOM_SEED_TABLE_GUID)) {
-                        previous_seed_table = ST->ConfigurationTable[i].VendorTable;
-                        break;
-                }
+        previous_seed_table = find_configuration_table(&(const EFI_GUID) LINUX_EFI_RANDOM_SEED_TABLE_GUID);
         if (!previous_seed_table) {
                 size = 0;
                 sha256_process_bytes(&size, sizeof(size), &hash);
index 1f07fbc38c44cd64dc62bb88b531954674acc88a..0a6bb59dced93e8aa388b6b89ea78cdd976d0b94 100644 (file)
@@ -747,3 +747,11 @@ bool in_hypervisor(void) {
         return !!(ecx & 0x80000000U);
 }
 #endif
+
+void *find_configuration_table(const EFI_GUID *guid) {
+        for (UINTN i = 0; i < ST->NumberOfTableEntries; i++)
+                if (efi_guid_equal(&ST->ConfigurationTable[i].VendorGuid, guid))
+                        return ST->ConfigurationTable[i].VendorTable;
+
+        return NULL;
+}
index bacc114114f5d1107837130b98a8822de431d84c..699f1a2c7cf6ae5203b25a29bb4c918686ad37b6 100644 (file)
@@ -246,3 +246,5 @@ static inline bool in_hypervisor(void) {
 static inline bool efi_guid_equal(const EFI_GUID *a, const EFI_GUID *b) {
         return memcmp(a, b, sizeof(EFI_GUID)) == 0;
 }
+
+void *find_configuration_table(const EFI_GUID *guid);