{"id":798310,"url":"http://patchwork.ozlabs.org/api/1.2/patches/798310/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20170805214555.75567-2-sjg@chromium.org/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.2/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170805214555.75567-2-sjg@chromium.org>","list_archive_url":null,"date":"2017-08-05T21:45:54","name":"[U-Boot,2/3] dm: core: Add ofnode_for_each_subnode()","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d700ce9e3b59764f78628aee53f3ac47c977e21c","submitter":{"id":6170,"url":"http://patchwork.ozlabs.org/api/1.2/people/6170/?format=json","name":"Simon Glass","email":"sjg@chromium.org"},"delegate":{"id":3184,"url":"http://patchwork.ozlabs.org/api/1.2/users/3184/?format=json","username":"sjg","first_name":"Simon","last_name":"Glass","email":"sjg@chromium.org"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20170805214555.75567-2-sjg@chromium.org/mbox/","series":[],"comments":"http://patchwork.ozlabs.org/api/patches/798310/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/798310/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"JTXS9KgL\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xPy7f6h5lz9sDB\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun,  6 Aug 2017 07:47:26 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 13633C21DE1; Sat,  5 Aug 2017 21:46:26 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id C7AB3C21EE7;\n\tSat,  5 Aug 2017 21:46:09 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 61395C21D82; Sat,  5 Aug 2017 21:46:08 +0000 (UTC)","from mail-oi0-f41.google.com (mail-oi0-f41.google.com\n\t[209.85.218.41])\n\tby lists.denx.de (Postfix) with ESMTPS id DA8C6C21C72\n\tfor <u-boot@lists.denx.de>; Sat,  5 Aug 2017 21:46:07 +0000 (UTC)","by mail-oi0-f41.google.com with SMTP id g131so40287130oic.3\n\tfor <u-boot@lists.denx.de>; Sat, 05 Aug 2017 14:46:07 -0700 (PDT)","from kiwi.bld.corp.google.com ([100.101.164.89])\n\tby smtp.gmail.com with ESMTPSA id\n\tj188sm6399435oib.47.2017.08.05.14.46.05\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSat, 05 Aug 2017 14:46:05 -0700 (PDT)","by kiwi.bld.corp.google.com (Postfix, from userid 121222)\n\tid 12C45141675; Sat,  5 Aug 2017 15:46:05 -0600 (MDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable\n\tautolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=20161025; \n\th=sender:from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=gNoL7p2VnH4JVaTvL7iDB2qZwC2K1RqGCtzSftDiMew=;\n\tb=JTXS9KgL1XQL82lBBtg20KIggANzEmny00mWb5QF0KPk1PC2JoaOd67WkcNr5oT3Yg\n\tXrU7bSshArw/llU+YR5bnto1mysQvxl5mJMAJBakYnJGqY7X1rfEv+nxaCpOXj+3De2m\n\t1CBD6cdXG+mNyRVFHdvO1gtoO6WFUulgTov471KPriKkZhzzC+hQQhcItYO/aMtRMXM8\n\t+1HpjvKrEaOPuxi6LIwQxqS6IpM1zivpZ/Uf4o9IVBqWrYRUlqrMTGNSlY7zMQgARBI4\n\tCES5MGl2Ca+i84DYWIGRG3jwioO9UrUV6AGuV2UDo3e88Q5I8eDuyiJ5D0h5wQ+wOSun\n\ti1Lg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:from:to:cc:subject:date:message-id\n\t:in-reply-to:references;\n\tbh=gNoL7p2VnH4JVaTvL7iDB2qZwC2K1RqGCtzSftDiMew=;\n\tb=htFvPZIJCu8Fpn75aSPXd1IfcCmXV1EfO01QNqpSnQMnEnpM/w7gr0ptizjIPpyCSF\n\tCNPYusNk5X+F7UOduzVFqwADyVtMbpwtHTC8PURpcf818yrnxArN9RN2X2j91aT6eu0r\n\tBDLmMvvF25It6dU+xxNzUYLcTTdjiK6v2t/ufciyUuu5sWQpg8KStm2kwNRPiiLz3GGP\n\t7ANH5Z8vQqeoyz0Zj6+T+DM2DEkDE+u9tli8BrvhNSpMUnEPkBOghmLxmS0tw8wwNixw\n\tVnKIUH5s0q3HqUeA0WQqIN4+bTOcJBtRNvzTzaMFqMJVuqs7xQ5SnjiUaCBDDrGRnrrz\n\tj2LA==","X-Gm-Message-State":"AHYfb5joJjvhJ5k4AbYmwZdrrt5U0nmZ7YlhKn4U4R6MiTQiWUlanFfY\n\tbH+gvs3k/xCjkyvL","X-Received":"by 10.202.236.3 with SMTP id k3mr3972792oih.20.1501969566406;\n\tSat, 05 Aug 2017 14:46:06 -0700 (PDT)","From":"Simon Glass <sjg@chromium.org>","To":"U-Boot Mailing List <u-boot@lists.denx.de>","Date":"Sat,  5 Aug 2017 15:45:54 -0600","Message-Id":"<20170805214555.75567-2-sjg@chromium.org>","X-Mailer":"git-send-email 2.14.0.rc1.383.gd1ce394fe2-goog","In-Reply-To":"<20170805214555.75567-1-sjg@chromium.org>","References":"<20170805214555.75567-1-sjg@chromium.org>","Cc":"Tom Rini <trini@konsulko.com>, Albert Aribaud <albert.u.boot@aribaud.net>,\n\tTom Warren <twarren@nvidia.com>","Subject":"[U-Boot] [PATCH 2/3] dm: core: Add ofnode_for_each_subnode()","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"},"content":"Add a convenience macro to iterate over subnodes of a node. Make use of\nthis where appropriate in the code.\n\nSigned-off-by: Simon Glass <sjg@chromium.org>\n---\n\n arch/arm/mach-tegra/xusb-padctl-common.c |  8 ++------\n drivers/core/ofnode.c                    |  9 +++++----\n drivers/misc/cros_ec.c                   |  3 +--\n drivers/power/pmic/pmic-uclass.c         |  4 +---\n include/dm/ofnode.h                      | 24 ++++++++++++++++++++++++\n 5 files changed, 33 insertions(+), 15 deletions(-)","diff":"diff --git a/arch/arm/mach-tegra/xusb-padctl-common.c b/arch/arm/mach-tegra/xusb-padctl-common.c\nindex 37b5b8fb5b..abc18c03a5 100644\n--- a/arch/arm/mach-tegra/xusb-padctl-common.c\n+++ b/arch/arm/mach-tegra/xusb-padctl-common.c\n@@ -224,9 +224,7 @@ tegra_xusb_padctl_config_parse_dt(struct tegra_xusb_padctl *padctl,\n \n \tconfig->name = ofnode_get_name(node);\n \n-\tfor (subnode = ofnode_first_subnode(node);\n-\t     ofnode_valid(subnode);\n-\t     subnode = ofnode_next_subnode(subnode)) {\n+\tofnode_for_each_subnode(subnode, node) {\n \t\tstruct tegra_xusb_padctl_group *group;\n \t\tint err;\n \n@@ -256,9 +254,7 @@ static int tegra_xusb_padctl_parse_dt(struct tegra_xusb_padctl *padctl,\n \t\treturn err;\n \t}\n \n-\tfor (subnode = ofnode_first_subnode(node);\n-\t     ofnode_valid(subnode);\n-\t     subnode = ofnode_next_subnode(subnode)) {\n+\tofnode_for_each_subnode(subnode, node) {\n \t\tstruct tegra_xusb_padctl_config *config = &padctl->config;\n \n \t\tdebug(\"%s: subnode=%s\\n\", __func__, ofnode_get_name(subnode));\ndiff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c\nindex c1a2e9f0da..ae7cc833b9 100644\n--- a/drivers/core/ofnode.c\n+++ b/drivers/core/ofnode.c\n@@ -390,10 +390,11 @@ int ofnode_decode_display_timing(ofnode parent, int index,\n \tif (!ofnode_valid(timings))\n \t\treturn -EINVAL;\n \n-\tfor (i = 0, node = ofnode_first_subnode(timings);\n-\t     ofnode_valid(node) && i != index;\n-\t     node = ofnode_first_subnode(node))\n-\t\ti++;\n+\ti = 0;\n+\tofnode_for_each_subnode(node, timings) {\n+\t\tif (i++ == index)\n+\t\t\tbreak;\n+\t}\n \n \tif (!ofnode_valid(node))\n \t\treturn -EINVAL;\ndiff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c\nindex feaa5d8567..eefaaa53ad 100644\n--- a/drivers/misc/cros_ec.c\n+++ b/drivers/misc/cros_ec.c\n@@ -1038,8 +1038,7 @@ int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)\n \n \tconfig->flash_erase_value = ofnode_read_s32_default(flash_node,\n \t\t\t\t\t\t\t    \"erase-value\", -1);\n-\tfor (node = ofnode_first_subnode(flash_node); ofnode_valid(node);\n-\t     node = ofnode_next_subnode(node)) {\n+\tofnode_for_each_subnode(node, flash_node) {\n \t\tconst char *name = ofnode_get_name(node);\n \t\tenum ec_flash_region region;\n \ndiff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c\nindex 953bbe5026..64964e4e96 100644\n--- a/drivers/power/pmic/pmic-uclass.c\n+++ b/drivers/power/pmic/pmic-uclass.c\n@@ -34,9 +34,7 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent,\n \tdebug(\"%s for '%s' at node offset: %d\\n\", __func__, pmic->name,\n \t      dev_of_offset(pmic));\n \n-\tfor (node = ofnode_first_subnode(parent);\n-\t     ofnode_valid(node);\n-\t     node = ofnode_next_subnode(node)) {\n+\tofnode_for_each_subnode(node, parent) {\n \t\tnode_name = ofnode_get_name(node);\n \n \t\tdebug(\"* Found child node: '%s'\\n\", node_name);\ndiff --git a/include/dm/ofnode.h b/include/dm/ofnode.h\nindex 210ddb2e5d..22bece0a60 100644\n--- a/include/dm/ofnode.h\n+++ b/include/dm/ofnode.h\n@@ -626,4 +626,28 @@ bool ofnode_pre_reloc(ofnode node);\n \n int ofnode_read_resource(ofnode node, uint index, struct resource *res);\n \n+/**\n+ * ofnode_for_each_subnode() - iterate over all subnodes of a parent\n+ *\n+ * @node:       child node (ofnode, lvalue)\n+ * @parent:     parent node (ofnode)\n+ *\n+ * This is a wrapper around a for loop and is used like so:\n+ *\n+ *\tofnode node;\n+ *\n+ *\tofnode_for_each_subnode(node, parent) {\n+ *\t\tUse node\n+ *\t\t...\n+ *\t}\n+ *\n+ * Note that this is implemented as a macro and @node is used as\n+ * iterator in the loop. The parent variable can be a constant or even a\n+ * literal.\n+ */\n+#define ofnode_for_each_subnode(node, parent) \\\n+\tfor (node = ofnode_first_subnode(parent); \\\n+\t     ofnode_valid(node); \\\n+\t     node = ofnode_next_subnode(node))\n+\n #endif\n","prefixes":["U-Boot","2/3"]}