All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trammell Hudson <hudson@trmm.net>
To: xen-devel@lists.xenproject.org
Subject: [PATCH v5 2/5] efi/boot.c: add file.need_to_free
Date: Thu, 17 Sep 2020 11:40:45 -0400	[thread overview]
Message-ID: <20200917154048.1140580-3-hudson@trmm.net> (raw)
In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net>

The config file, kernel, initrd, etc should only be freed if they
are allocated with the UEFI allocator.

Signed-off-by: Trammell Hudson <hudson@trmm.net>
---
 xen/common/efi/boot.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 157fe0e8c5..77530a0595 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -102,6 +102,7 @@ union string {
 
 struct file {
     UINTN size;
+    bool need_to_free;
     union {
         EFI_PHYSICAL_ADDRESS addr;
         char *str;
@@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
     if ( !efi_bs )
         efi_arch_halt();
 
-    if ( cfg.addr )
+    if ( cfg.addr && cfg.need_to_free )
         efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-    if ( kernel.addr )
+    if ( kernel.addr && kernel.need_to_free )
         efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
-    if ( ramdisk.addr )
+    if ( ramdisk.addr && ramdisk.need_to_free )
         efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
-    if ( xsm.addr )
+    if ( xsm.addr && xsm.need_to_free )
         efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
 
     efi_arch_blexit();
@@ -573,6 +574,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
                          HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START);
         ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData,
                                     PFN_UP(size), &file->addr);
+        file->need_to_free = true;
     }
     if ( EFI_ERROR(ret) )
     {
-- 
2.25.1



  parent reply	other threads:[~2020-09-17 15:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 15:40 [PATCH v5 0/5] efi: Unified Xen hypervisor/kernel/initrd images Trammell Hudson
2020-09-17 15:40 ` [PATCH v5 1/5] efi/boot.c: Make file->ptr const void* Trammell Hudson
2020-09-18 14:44   ` Jan Beulich
2020-09-17 15:40 ` Trammell Hudson [this message]
2020-09-18 14:45   ` [PATCH v5 2/5] efi/boot.c: add file.need_to_free Jan Beulich
2020-09-17 15:40 ` [PATCH v5 3/5] efi/boot.c: add handle_file_info() Trammell Hudson
2020-09-18 14:52   ` Jan Beulich
2020-09-17 15:40 ` [PATCH v5 4/5] efi: Enable booting unified hypervisor/kernel/initrd images Trammell Hudson
2020-09-18 15:15   ` Jan Beulich
2020-09-21 11:47     ` Trammell Hudson
2020-09-21 11:52       ` Jan Beulich
2020-09-17 15:40 ` [PATCH v5 5/5] efi: Do not use command line if unified config is included Trammell Hudson
2020-09-18 15:24   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917154048.1140580-3-hudson@trmm.net \
    --to=hudson@trmm.net \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.