Blame SOURCES/0263-efi-use-enumerated-array-positions-for-our-allocatio.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Peter Jones <pjones@redhat.com>
fd0330
Date: Mon, 1 Aug 2022 14:06:30 -0400
fd0330
Subject: [PATCH] efi: use enumerated array positions for our allocation
fd0330
 choices
fd0330
fd0330
In our kernel allocator on EFI systems, we currently have a growing
fd0330
amount of code that references the various allocation policies by
fd0330
position in the array, and of course maintenance of this code scales
fd0330
very poorly.
fd0330
fd0330
This patch changes them to be enumerated, so they're easier to refer to
fd0330
farther along in the code without confusion.
fd0330
fd0330
Signed-off-by: Peter Jones <pjones@redhat.com>
fd0330
---
fd0330
 grub-core/loader/i386/efi/linux.c | 31 ++++++++++++++++++++-----------
fd0330
 1 file changed, 20 insertions(+), 11 deletions(-)
fd0330
fd0330
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
fd0330
index 91ae274299..8daa070132 100644
fd0330
--- a/grub-core/loader/i386/efi/linux.c
fd0330
+++ b/grub-core/loader/i386/efi/linux.c
fd0330
@@ -60,17 +60,26 @@ struct allocation_choice {
fd0330
     grub_efi_allocate_type_t alloc_type;
fd0330
 };
fd0330
 
fd0330
-static struct allocation_choice max_addresses[4] =
fd0330
+enum {
fd0330
+    KERNEL_PREF_ADDRESS,
fd0330
+    KERNEL_4G_LIMIT,
fd0330
+    KERNEL_NO_LIMIT,
fd0330
+};
fd0330
+
fd0330
+static struct allocation_choice max_addresses[] =
fd0330
   {
fd0330
     /* the kernel overrides this one with pref_address and
fd0330
      * GRUB_EFI_ALLOCATE_ADDRESS */
fd0330
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
+    [KERNEL_PREF_ADDRESS] =
fd0330
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
+    /* If the flag in params is set, this one gets changed to be above 4GB. */
fd0330
+    [KERNEL_4G_LIMIT] =
fd0330
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
     /* this one is always below 4GB, which we still *prefer* even if the flag
fd0330
      * is set. */
fd0330
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
-    /* If the flag in params is set, this one gets changed to be above 4GB. */
fd0330
-    { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
-    { 0, 0 }
fd0330
+    [KERNEL_NO_LIMIT] =
fd0330
+      { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS },
fd0330
+    { NO_MEM, 0, 0 }
fd0330
   };
fd0330
 static struct allocation_choice saved_addresses[4];
fd0330
 
fd0330
@@ -405,7 +414,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
fd0330
   if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G)
fd0330
     {
fd0330
       grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n");
fd0330
-      max_addresses[2].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
fd0330
+      max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_USABLE_ADDRESS;
fd0330
     }
fd0330
   else
fd0330
     {
fd0330
@@ -478,11 +487,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
fd0330
   grub_dprintf ("linux", "lh->pref_address: %p\n", (void *)(grub_addr_t)lh->pref_address);
fd0330
   if (lh->pref_address < (grub_uint64_t)GRUB_EFI_MAX_ALLOCATION_ADDRESS)
fd0330
     {
fd0330
-      max_addresses[0].addr = lh->pref_address;
fd0330
-      max_addresses[0].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS;
fd0330
+      max_addresses[KERNEL_PREF_ADDRESS].addr = lh->pref_address;
fd0330
+      max_addresses[KERNEL_PREF_ADDRESS].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS;
fd0330
     }
fd0330
-  max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
fd0330
-  max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
fd0330
+  max_addresses[KERNEL_4G_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
fd0330
+  max_addresses[KERNEL_NO_LIMIT].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS;
fd0330
   kernel_size = lh->init_size;
fd0330
   kernel_mem = kernel_alloc (kernel_size, GRUB_EFI_RUNTIME_SERVICES_CODE,
fd0330
 			     N_("can't allocate kernel"));