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

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