From patchwork Fri Feb 3 19:18:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 93306 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp738128qgi; Fri, 3 Feb 2017 11:21:04 -0800 (PST) X-Received: by 10.107.178.3 with SMTP id b3mr10845659iof.50.1486149664463; Fri, 03 Feb 2017 11:21:04 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id j74si4165732ioj.69.2017.02.03.11.21.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Feb 2017 11:21:04 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZjOC-0004IB-6Y; Fri, 03 Feb 2017 19:19:20 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZjOA-0004FI-9t for xen-devel@lists.xen.org; Fri, 03 Feb 2017 19:19:18 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id A5/CC-29440-5B7D4985; Fri, 03 Feb 2017 19:19:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTXfL9Sk RBt0LzC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxvv7ewFEwXq5jZ8YalgfEcfxcjF4eQwGZG iaUnHjFDOKcZJS5NnQPkcHKwCWhK3Pn8iQnEFhGQlrj2+TIjiM0sECVx5+JOFhBbWMBf4uLhk 2A2i4CqxJ29W9lAbF4BF4njx3aA1UsIyEmcPDaZFcTmFHCV+H5uHdhMIaCaxe0dLBMYuRcwMq xiVC9OLSpLLdI11UsqykzPKMlNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECPQvAxDsYJx+2f8 QoyQHk5Iob9G1KRFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHj1QXKCRanpqRVpmTnAQINJS3Dw KInw6oGkeYsLEnOLM9MhUqcYFaXEeQ+BJARAEhmleXBtsOC+xCgrJczLCHSIEE9BalFuZgmq/ CtGcQ5GJWFee5ApPJl5JXDTXwEtZgJa/PPxJJDFJYkIKakGRuWXs8MEdrwsUQybeu/2SfM9tk suKu3+NU1n3z3r5kea6y6aLqj2XO/MfOjd75iEmFaPD9O4XCbyJ/mlZrhdY51ncv72XuVZX5b +XVC0LHH/B4Ogoy3Fkr6MwX/NZz6d8cL15cyS4PqTXJNjHAzW9e2dnmWX9dNaLfBQxUeTG9U1 eimucuK155RYijMSDbWYi4oTAYatxT1pAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1486149556!84496856!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17385 invoked from network); 3 Feb 2017 19:19:16 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-27.messagelabs.com with SMTP; 3 Feb 2017 19:19:16 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 326ED152B; Fri, 3 Feb 2017 11:19:16 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7218A3F242; Fri, 3 Feb 2017 11:19:15 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 3 Feb 2017 19:18:51 +0000 Message-Id: <1486149538-20432-8-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486149538-20432-1-git-send-email-julien.grall@arm.com> References: <1486149538-20432-1-git-send-email-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org, shankerd@codeaurora.org Subject: [Xen-devel] [PATCH 4/7] xen/arm: efi: Avoid duplicating the addition of a new bank X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" 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 --- 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; }