From patchwork Tue May 31 15:14:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 9145003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF1A260752 for ; Tue, 31 May 2016 15:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF7C62198E for ; Tue, 31 May 2016 15:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A44592796F; Tue, 31 May 2016 15:16:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1FBF27811 for ; Tue, 31 May 2016 15:16:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7lNk-0004dK-WE; Tue, 31 May 2016 15:15:01 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7lNi-0004a3-Bc for linux-arm-kernel@lists.infradead.org; Tue, 31 May 2016 15:14:58 +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 B25694C; Tue, 31 May 2016 08:15:07 -0700 (PDT) Received: from e104818-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DC9053F246; Tue, 31 May 2016 08:14:37 -0700 (PDT) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] efi: Introduce *_continue efi_memory_desc iterators Date: Tue, 31 May 2016 16:14:30 +0100 Message-Id: <1464707672-21882-2-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464707672-21882-1-git-send-email-catalin.marinas@arm.com> References: <1464707672-21882-1-git-send-email-catalin.marinas@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160531_081458_424002_8653DEA1 X-CRM114-Status: UNSURE ( 9.43 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matt Fleming , Mark Rutland , linux-efi@vger.kernel.org, Will Deacon , Jeremy Linton MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The for_each_efi_memory_desc_continue() macro and corresponding "_in_map" allow iterating over an efi_memory_map from a given position. For code reuse between the existing iterator and the _continue variant, this patch also introduces efi_memory_desc_next_entry_map(). Cc: Matt Fleming Signed-off-by: Catalin Marinas --- include/linux/efi.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/efi.h b/include/linux/efi.h index c2db3ca22217..4b0d880f1cd7 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1002,11 +1002,16 @@ extern int efi_memattr_init(void); extern int efi_memattr_apply_permissions(struct mm_struct *mm, efi_memattr_perm_setter fn); +/* Find next entry in an efi_memory_map or NULL if md is last */ +#define efi_memory_desc_next_entry_map(m, md) \ + ((md) == (efi_memory_desc_t *)((m)->map_end - (m)->desc_size) \ + ? NULL : (void *)(md) + (m)->desc_size) + /* Iterate through an efi_memory_map */ #define for_each_efi_memory_desc_in_map(m, md) \ for ((md) = (m)->map; \ - (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \ - (md) = (void *)(md) + (m)->desc_size) + (md); \ + (md) = efi_memory_desc_next_entry_map(m, md)) /** * for_each_efi_memory_desc - iterate over descriptors in efi.memmap @@ -1017,6 +1022,16 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm, #define for_each_efi_memory_desc(md) \ for_each_efi_memory_desc_in_map(&efi.memmap, md) +/* Continue iterating through an efi_memory_map */ +#define for_each_efi_memory_desc_in_map_continue(m, md) \ + for ((md) = efi_memory_desc_next_entry_map(m, md); \ + (md); \ + (md) = efi_memory_desc_next_entry_map(m, md)) + +/* Continue iterating through efi.memmap */ +#define for_each_efi_memory_desc_continue(md) \ + for_each_efi_memory_desc_in_map_continue(&efi.memmap, md) + /* * Format an EFI memory descriptor's type and attributes to a user-provided * character buffer, as per snprintf(), and return the buffer.