dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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