Blame SOURCES/0098-Use-grub_efi_.-memory-helpers-where-reasonable.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Thu, 1 Jun 2017 10:06:38 -0400
8631a2
Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable.
8631a2
8631a2
This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and
8631a2
grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we
8631a2
get more reasonable type checking.
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/loader/efi/chainloader.c | 24 +++++++++---------------
8631a2
 1 file changed, 9 insertions(+), 15 deletions(-)
8631a2
8631a2
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
8631a2
index 5cd9b6e08a8..106eb10a362 100644
8631a2
--- a/grub-core/loader/efi/chainloader.c
8631a2
+++ b/grub-core/loader/efi/chainloader.c
8631a2
@@ -65,7 +65,7 @@ grub_chainloader_unload (void)
8631a2
 
8631a2
   b = grub_efi_system_table->boot_services;
8631a2
   efi_call_1 (b->unload_image, image_handle);
8631a2
-  efi_call_2 (b->free_pages, address, pages);
8631a2
+  grub_efi_free_pages (address, pages);
8631a2
 
8631a2
   grub_free (file_path);
8631a2
   grub_free (cmdline);
8631a2
@@ -108,7 +108,7 @@ grub_chainloader_boot (void)
8631a2
     }
8631a2
 
8631a2
   if (exit_data)
8631a2
-    efi_call_1 (b->free_pool, exit_data);
8631a2
+    grub_efi_free_pool (exit_data);
8631a2
 
8631a2
   grub_loader_unset ();
8631a2
 
8631a2
@@ -500,10 +500,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp)
8631a2
 static grub_efi_boolean_t
8631a2
 handle_image (void *data, grub_efi_uint32_t datasize)
8631a2
 {
8631a2
-  grub_efi_boot_services_t *b;
8631a2
   grub_efi_loaded_image_t *li, li_bak;
8631a2
   grub_efi_status_t efi_status;
8631a2
-  char *buffer = NULL;
8631a2
+  void *buffer = NULL;
8631a2
   char *buffer_aligned = NULL;
8631a2
   grub_efi_uint32_t i;
8631a2
   struct grub_pe32_section_table *section;
8631a2
@@ -514,8 +513,6 @@ handle_image (void *data, grub_efi_uint32_t datasize)
8631a2
   int found_entry_point = 0;
8631a2
   int rc;
8631a2
 
8631a2
-  b = grub_efi_system_table->boot_services;
8631a2
-
8631a2
   rc = read_header (data, datasize, &context);
8631a2
   if (rc < 0)
8631a2
     {
8631a2
@@ -555,8 +552,8 @@ handle_image (void *data, grub_efi_uint32_t datasize)
8631a2
   grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n",
8631a2
 	       context.image_size, datasize);
8631a2
 
8631a2
-  efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
8631a2
-			   buffer_size, &buffer);
8631a2
+  efi_status = grub_efi_allocate_pool (GRUB_EFI_LOADER_DATA, buffer_size,
8631a2
+				       &buffer);
8631a2
 
8631a2
   if (efi_status != GRUB_EFI_SUCCESS)
8631a2
     {
8631a2
@@ -788,14 +785,14 @@ handle_image (void *data, grub_efi_uint32_t datasize)
8631a2
 
8631a2
   grub_dprintf ("chain", "entry_point returned %ld\n", efi_status);
8631a2
   grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t));
8631a2
-  efi_status = efi_call_1 (b->free_pool, buffer);
8631a2
+  efi_status = grub_efi_free_pool (buffer);
8631a2
 
8631a2
   return 1;
8631a2
 
8631a2
 error_exit:
8631a2
   grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno);
8631a2
   if (buffer)
8631a2
-      efi_call_1 (b->free_pool, buffer);
8631a2
+    grub_efi_free_pool (buffer);
8631a2
 
8631a2
   return 0;
8631a2
 }
8631a2
@@ -803,10 +800,7 @@ error_exit:
8631a2
 static grub_err_t
8631a2
 grub_secureboot_chainloader_unload (void)
8631a2
 {
8631a2
-  grub_efi_boot_services_t *b;
8631a2
-
8631a2
-  b = grub_efi_system_table->boot_services;
8631a2
-  efi_call_2 (b->free_pages, address, pages);
8631a2
+  grub_efi_free_pages (address, pages);
8631a2
   grub_free (file_path);
8631a2
   grub_free (cmdline);
8631a2
   cmdline = 0;
8631a2
@@ -1073,7 +1067,7 @@ fail:
8631a2
   grub_free (file_path);
8631a2
 
8631a2
   if (address)
8631a2
-    efi_call_2 (b->free_pages, address, pages);
8631a2
+    grub_efi_free_pages (address, pages);
8631a2
 
8631a2
   if (cmdline)
8631a2
     grub_free (cmdline);