From patchwork Fri Feb 3 19:18:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 93303 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp738108qgi; Fri, 3 Feb 2017 11:21:02 -0800 (PST) X-Received: by 10.36.57.10 with SMTP id l10mr2413812ita.8.1486149661989; Fri, 03 Feb 2017 11:21:01 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id z67si4168788ioi.19.2017.02.03.11.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Feb 2017 11:21:01 -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-0004Jc-NA; 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 1cZjOB-00048E-Or for xen-devel@lists.xen.org; Fri, 03 Feb 2017 19:19:19 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 5D/A0-27165-7B7D4985; Fri, 03 Feb 2017 19:19:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTXfb9Sk RBgcXm1gs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnffm9hKZguVjGz4w1LA+M5/i5GLg4hgc2M Ev2Xl7J1MXICOacZJXpeGYPYbAKaEnc+f2ICsUUEpCWufb7MCGIzC0RJ3Lm4kwXEFhbwl/hz5 wlYDYuAqsTnf+dYQWxeAVeJzzcnM4PYEgJyEiePTQaLcwLFv59bxwSxy0VicXsHywRG7gWMDK sYNYpTi8pSi3QNjfSSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQL9ywAEOxgvbww 4xCjJwaQkylt0bUqEEF9SfkplRmJxRnxRaU5q8SFGGQ4OJQneBSA5waLU9NSKtMwcYKDBpCU4 eJREePVA0rzFBYm5xZnpEKlTjIpS4rzGIAkBkERGaR5cGyy4LzHKSgnzMgIdIsRTkFqUm1mCK v+KUZyDUUmY1x5kCk9mXgnc9FdAi5mAFv98PAlkcUkiQkqqgXEl+5zTyXXhWnvWOLlN/9Bqr2 DGNUvH0OfZ1+kf7h2TWxx3JP3v6WK/t4t3LS2+f/Np2lrLuN55+1y3LT1b8dapOPSTtGBLSHl +qVvS7G8Wv7ubDzvM7jPpO/PtpMKDl3OSRSTDGAV5Cjc/e9LGvCL680eedc2J8fpnyow2qUcG 5abwPpw0b6YSS3FGoqEWc1FxIgDhbCLVaQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1486149558!56015706!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 42122 invoked from network); 3 Feb 2017 19:19:18 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-12.tower-21.messagelabs.com with SMTP; 3 Feb 2017 19:19:18 -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 272D5152B; Fri, 3 Feb 2017 11:19:18 -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 6638B3F242; Fri, 3 Feb 2017 11:19:17 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Fri, 3 Feb 2017 19:18:53 +0000 Message-Id: <1486149538-20432-10-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 5/8] 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 --- 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; }