From patchwork Fri May 27 09:13:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 627030 X-Patchwork-Delegate: panto@antoniou-consulting.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rGL1j1RNGz9t44 for ; Fri, 27 May 2016 19:14:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F7E4A776D; Fri, 27 May 2016 11:14:09 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oqHTChtGHPVn; Fri, 27 May 2016 11:14:09 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 396A6A75EE; Fri, 27 May 2016 11:13:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B5A75A74E0 for ; Fri, 27 May 2016 11:13:29 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SnePXkjJ8SLa for ; Fri, 27 May 2016 11:13:29 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.free-electrons.com (down.free-electrons.com [37.187.137.238]) by theia.denx.de (Postfix) with ESMTP id 6D4FDA7498 for ; Fri, 27 May 2016 11:13:29 +0200 (CEST) Received: by mail.free-electrons.com (Postfix, from userid 110) id 848744B4; Fri, 27 May 2016 11:13:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LFbn-1-2034-31.w90-76.abo.wanadoo.fr [90.76.103.31]) by mail.free-electrons.com (Postfix) with ESMTPSA id 4DC101D5; Fri, 27 May 2016 11:13:27 +0200 (CEST) From: Maxime Ripard To: Pantelis Antoniou , Simon Glass Date: Fri, 27 May 2016 11:13:18 +0200 Message-Id: <1464340402-2249-6-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1464340402-2249-1-git-send-email-maxime.ripard@free-electrons.com> References: <1464340402-2249-1-git-send-email-maxime.ripard@free-electrons.com> Cc: Thomas Petazzoni , Tom Rini , u-boot@lists.denx.de, Alexander Kaplan , devicetree-compiler@vger.kernel.org Subject: [U-Boot] [PATCH v2 5/9] libfdt: Add iterator over properties X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Implement a macro based on fdt_first_property_offset and fdt_next_property_offset that provides a convenience to iterate over all the properties of a given node. Signed-off-by: Maxime Ripard Reviewed-by: Stefan Agner Acked-by: Pantelis Antoniou --- include/libfdt.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/libfdt.h b/include/libfdt.h index 74b1d149c2dd..4e8eb9ede3a4 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -441,6 +441,30 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset); int fdt_next_property_offset(const void *fdt, int offset); /** + * fdt_for_each_property - iterate over all properties of a node + * @fdt: FDT blob (const void *) + * @node: node offset (int) + * @property: property offset (int) + * + * This is actually a wrapper around a for loop and would be used like so: + * + * fdt_for_each_property(fdt, node, property) { + * ... + * use property + * ... + * } + * + * Note that this is implemented as a macro and property is used as + * iterator in the loop. It should therefore be a locally allocated + * variable. The node variable on the other hand is never modified, so + * it can be constant or even a literal. + */ +#define fdt_for_each_property(fdt, node, property) \ + for (property = fdt_first_property_offset(fdt, node); \ + property >= 0; \ + property = fdt_next_property_offset(fdt, property)) + +/** * fdt_get_property_by_offset - retrieve the property at a given offset * @fdt: pointer to the device tree blob * @offset: offset of the property to retrieve