xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xen.org
Cc: Julien Grall <julien.grall@arm.com>,
	sstabellini@kernel.org, shankerd@codeaurora.org
Subject: [PATCH 5/8] xen/arm: efi: Avoid duplicating the addition of a new bank
Date: Fri,  3 Feb 2017 19:18:53 +0000	[thread overview]
Message-ID: <1486149538-20432-10-git-send-email-julien.grall@arm.com> (raw)
In-Reply-To: <1486149538-20432-1-git-send-email-julien.grall@arm.com>

The code to add a new bank is duplicated twice. Add a new helper that
checks if the maximum of bank has not reached and adds the bank.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/efi/efi-boot.h | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 045d6ce..757d9c6 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -124,15 +124,27 @@ static void __init *lookup_fdt_config_table(EFI_SYSTEM_TABLE *sys_table)
     return fdt;
 }
 
+static bool meminfo_add_bank(struct meminfo *mem, EFI_MEMORY_DESCRIPTOR *desc)
+{
+    struct membank *bank;
+
+    if ( mem->nr_banks > NR_MEM_BANKS )
+        return false;
+
+    bank = &mem->bank[mem->nr_banks];
+    bank->start = desc->PhysicalStart;
+    bank->size = desc->NumberOfPages * EFI_PAGE_SIZE;
+
+    mem->nr_banks++;
+
+    return true;
+}
+
 static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *map,
                                                 UINTN mmap_size,
                                                 UINTN desc_size)
 {
     int Index;
-    int i = 0;
-#ifdef CONFIG_ACPI
-    int j = 0;
-#endif
     EFI_MEMORY_DESCRIPTOR *desc_ptr = map;
 
     for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
@@ -142,37 +154,27 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *
               (desc_ptr->Type == EfiBootServicesCode ||
                desc_ptr->Type == EfiBootServicesData)) )
         {
-            if ( i >= NR_MEM_BANKS )
+            if ( !meminfo_add_bank(&bootinfo.mem, desc_ptr) )
             {
                 PrintStr(L"Warning: All " __stringify(NR_MEM_BANKS)
                           " bootinfo mem banks exhausted.\r\n");
                 break;
             }
-            bootinfo.mem.bank[i].start = desc_ptr->PhysicalStart;
-            bootinfo.mem.bank[i].size = desc_ptr->NumberOfPages * EFI_PAGE_SIZE;
-            ++i;
         }
 #ifdef CONFIG_ACPI
         else if ( desc_ptr->Type == EfiACPIReclaimMemory )
         {
-            if ( j >= NR_MEM_BANKS )
+            if ( !meminfo_add_bank(&acpi_mem, desc_ptr) )
             {
                 PrintStr(L"Error: All " __stringify(NR_MEM_BANKS)
                           " acpi meminfo mem banks exhausted.\r\n");
                 return EFI_LOAD_ERROR;
             }
-            acpi_mem.bank[j].start = desc_ptr->PhysicalStart;
-            acpi_mem.bank[j].size  = desc_ptr->NumberOfPages * EFI_PAGE_SIZE;
-            ++j;
         }
 #endif
         desc_ptr = NextMemoryDescriptor(desc_ptr, desc_size);
     }
 
-    bootinfo.mem.nr_banks = i;
-#ifdef CONFIG_ACPI
-    acpi_mem.nr_banks = j;
-#endif
     return EFI_SUCCESS;
 }
 
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-02-03 19:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 19:18 [PATCH 0/8] xen/arm: Fix and clean-up for ACPI and EFI Julien Grall
2017-02-03 19:18 ` [PATCH 1/8] xen/arm: acpi: Handle correctly detection of GICv2 on GICv3 Julien Grall
2017-02-16  1:36   ` Stefano Stabellini
2017-02-03 19:18 ` [PATCH 1/7] xen/arm: acpi: Rework acpi_boot_table_init error paths Julien Grall
2017-02-03 22:09   ` Wei Liu
2017-02-03 19:18 ` [PATCH 2/7] xen/arm: acpi: Don't fallback on DT when user request ACPI Julien Grall
2017-02-03 19:18 ` [PATCH 2/8] xen/arm: acpi: Rework acpi_boot_table_init error paths Julien Grall
2017-02-03 20:44   ` Andrew Cooper
2017-02-08 18:25     ` Julien Grall
2017-02-16  1:39   ` Stefano Stabellini
2017-02-03 19:18 ` [PATCH 3/8] xen/arm: acpi: Don't fallback on DT when user request ACPI Julien Grall
2017-02-16  1:41   ` Stefano Stabellini
2017-02-20  8:47     ` Julien Grall
2017-02-20 18:12       ` Stefano Stabellini
2017-02-20 18:13         ` Julien Grall
2017-03-03 18:35           ` Julien Grall
2017-02-03 19:18 ` [PATCH 3/7] xen/arm: Print whether Xen is booting using ACPI or DT Julien Grall
2017-02-03 19:18 ` [PATCH 4/7] xen/arm: efi: Avoid duplicating the addition of a new bank Julien Grall
2017-02-03 19:18 ` [PATCH 4/8] xen/arm: Print whether Xen is booting using ACPI or DT Julien Grall
2017-02-16  1:42   ` Stefano Stabellini
2017-02-03 19:18 ` Julien Grall [this message]
2017-02-16  1:47   ` [PATCH 5/8] xen/arm: efi: Avoid duplicating the addition of a new bank Stefano Stabellini
2017-02-16  1:49     ` Stefano Stabellini
2017-03-03 18:31       ` Julien Grall
2017-02-03 19:18 ` [PATCH 6/8] xen/arm: efi: Avoid duplicating the addition of a new efi memory descriptor Julien Grall
2017-02-16  1:52   ` Stefano Stabellini
2017-02-03 19:18 ` [PATCH 6/7] xen/arm: efi: Rework acpi_create_efi_mmap_table to avoid memory_map[offset] Julien Grall
2017-02-03 19:18 ` [PATCH 7/7] xen/arm: acpi: Move the ACPI banks in bootinfo Julien Grall
2017-02-03 19:18 ` [PATCH 7/8] xen/arm: efi: Rework acpi_create_efi_mmap_table to avoid memory_map[offset] Julien Grall
2017-02-16  1:57   ` Stefano Stabellini
2017-02-03 19:18 ` [PATCH 8/8] xen/arm: acpi: Move the ACPI banks in bootinfo Julien Grall
2017-02-16  2:00   ` Stefano Stabellini
2017-02-16  1:58 ` [PATCH 0/8] xen/arm: Fix and clean-up for ACPI and EFI Stefano Stabellini

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=1486149538-20432-10-git-send-email-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=shankerd@codeaurora.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).