]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: factor out searching for loader entry 10174/head
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Jun 2018 16:44:55 +0000 (18:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2018 14:44:34 +0000 (16:44 +0200)
src/boot/efi/boot.c

index ce8f7535b615328c705ca9d07826501f82534823..4ff7594a9a61afea34e6450d422e63cfca3b22d5 100644 (file)
@@ -1519,10 +1519,20 @@ static VOID config_sort_entries(Config *config) {
         }
 }
 
+static INTN config_entry_find(Config *config, CHAR16 *id) {
+        UINTN i;
+
+        for (i = 0; i < config->entry_count; i++)
+                if (StrCmp(config->entries[i]->id, id) == 0)
+                        return (INTN) i;
+
+        return -1;
+}
+
 static VOID config_default_entry_select(Config *config) {
         _cleanup_freepool_ CHAR16 *entry_oneshot = NULL, *entry_default = NULL;
         EFI_STATUS err;
-        UINTN i;
+        INTN i;
 
         /*
          * The EFI variable to specify a boot entry for the next, and only the
@@ -1530,19 +1540,15 @@ static VOID config_default_entry_select(Config *config) {
          */
         err = efivar_get(L"LoaderEntryOneShot", &entry_oneshot);
         if (!EFI_ERROR(err)) {
-                BOOLEAN found = FALSE;
-
-                for (i = 0; i < config->entry_count; i++)
-                        if (StrCmp(config->entries[i]->id, entry_oneshot) == 0) {
-                                config->idx_default = i;
-                                found = TRUE;
-                                break;
-                        }
 
                 config->entry_oneshot = StrDuplicate(entry_oneshot);
                 efivar_set(L"LoaderEntryOneShot", NULL, TRUE);
-                if (found)
+
+                i = config_entry_find(config, entry_oneshot);
+                if (i >= 0) {
+                        config->idx_default = i;
                         return;
+                }
         }
 
         /*
@@ -1553,12 +1559,13 @@ static VOID config_default_entry_select(Config *config) {
          */
         err = efivar_get(L"LoaderEntryDefault", &entry_default);
         if (!EFI_ERROR(err)) {
-                for (i = 0; i < config->entry_count; i++)
-                        if (StrCmp(config->entries[i]->id, entry_default) == 0) {
-                                config->idx_default = i;
-                                config->idx_default_efivar = i;
-                                return;
-                        }
+
+                i = config_entry_find(config, entry_default);
+                if (i >= 0) {
+                        config->idx_default = i;
+                        config->idx_default_efivar = i;
+                        return;
+                }
         }
         config->idx_default_efivar = -1;