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