From patchwork Wed Mar 8 17:54:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 95052 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp22454obz; Wed, 8 Mar 2017 09:56:51 -0800 (PST) X-Received: by 10.107.164.204 with SMTP id d73mr7435848ioj.182.1488995811384; Wed, 08 Mar 2017 09:56:51 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a203si657304itg.7.2017.03.08.09.56.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 09:56:51 -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 1clfnV-0005wN-J3; Wed, 08 Mar 2017 17:54:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfnU-0005vz-EO for xen-devel@lists.xen.org; Wed, 08 Mar 2017 17:54:48 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 3B/BB-13095-76540C85; Wed, 08 Mar 2017 17:54:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTTfN9UC EQXuLkMWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrG94zFjwTPxig13e1kaGC8KdDFycQgJbGaU uPB6PQuEc5pR4tvte0AOJwebgKbEnc+fmEBsEQFpiWufLzOC2MwCDhJvPkLUCAsESXx494Edx GYRUJU4cKwXLM4rYCmx6/d+sLiEgLzErraLrCA2p4CVxNumr2A1QkA13+d8ZJvAyL2AkWEVo3 pxalFZapGuuV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJSsV5yfu4mRqB/GYBgB+PMy/6HGCU 5mJREea+qHogQ4kvKT6nMSCzOiC8qzUktPsQow8GhJMEb7QKUEyxKTU+tSMvMAQYaTFqCg0dJ hJcTJM1bXJCYW5yZDpE6xagoJc7rC5IQAElklObBtcGC+xKjrJQwLyPQIUI8BalFuZklqPKvG MU5GJWEebtApvBk5pXATX8FtJgJaLG2616QxSWJCCmpBsaEzfLsXz3/PTBbdv2SgtgiC67ZW7 axnN41Rcec28Bk+eZcz5UTS29dta7oOdF48aNsgEJO6C4u1X5tXcnbSw7WVJ+Krjsg27hzm3C 2QRh3s+mNVr9r3J2/jcL/SAXtDgt6vbF3zsTPyruUr21rU1j7Q3x9oqCJ5cIdnJGvZuzVcw07 1sN5Q0mJpTgj0VCLuag4EQDAohwWaQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-11.tower-21.messagelabs.com!1488995685!61243581!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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47520 invoked from network); 8 Mar 2017 17:54:46 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-11.tower-21.messagelabs.com with SMTP; 8 Mar 2017 17:54:46 -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 8A68F14F6; Wed, 8 Mar 2017 09:54:45 -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 DF5BE3F23B; Wed, 8 Mar 2017 09:54:44 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 8 Mar 2017 17:54:33 +0000 Message-Id: <20170308175436.24001-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170308175436.24001-1-julien.grall@arm.com> References: <20170308175436.24001-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 1/4] 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by - Mark the function as __init --- xen/arch/arm/efi/efi-boot.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 045d6ce976..4877e6714d 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -124,15 +124,28 @@ static void __init *lookup_fdt_config_table(EFI_SYSTEM_TABLE *sys_table) return fdt; } +static bool __init 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 +155,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; }