From patchwork Tue Sep 18 07:10:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas KANDAGATLA X-Patchwork-Id: 184636 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 900F02C05D8 for ; Tue, 18 Sep 2012 17:15:35 +1000 (EST) Received: from eu1sys200aog115.obsmtp.com (eu1sys200aog115.obsmtp.com [207.126.144.139]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B7ABF2C0192; Tue, 18 Sep 2012 17:14:09 +1000 (EST) Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob115.postini.com ([207.126.147.11]) with SMTP ID DSNKUFgfOTOdO9lAXwYMlkoUGG9sYcxz6sIY@postini.com; Tue, 18 Sep 2012 07:14:17 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 38186208; Tue, 18 Sep 2012 07:14:00 +0000 (GMT) Received: from mail7.sgp.st.com (mail7.sgp.st.com [164.129.223.81]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DB4FA23CA; Tue, 18 Sep 2012 07:13:59 +0000 (GMT) Received: from localhost (king.bri.st.com [10.65.51.147]) by mail7.sgp.st.com (MOS 4.3.3-GA) with ESMTP id ANO05616 (AUTH srinivak); Tue, 18 Sep 2012 09:13:59 +0200 From: Srinivas KANDAGATLA To: robherring2@gmail.com, bergner@us.ibm.com, devicetree-discuss@lists.ozlabs.org Subject: [PATCH v4 1/5] dt: introduce of_get_child_by_name to get child node by name Date: Tue, 18 Sep 2012 08:10:28 +0100 Message-Id: <1347952228-24568-1-git-send-email-srinivas.kandagatla@st.com> X-Mailer: git-send-email 1.7.0.4 Cc: kgene.kim@samsung.com, srinivas.kandagatla@st.com, broonie@opensource.wolfsonmicro.com, afleming@freescale.com, ben-linux@fluff.org, linuxppc-dev@lists.ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Srinivas Kandagatla This patch introduces of_get_child_by_name function to get a child node by its name in a given parent node. Without this patch each driver code has to iterate the parent and do a string compare, However having of_get_child_by_name libary function would avoid code duplication, errors and is more convenient. Signed-off-by: Srinivas Kandagatla --- drivers/of/base.c | 23 +++++++++++++++++++++++ include/linux/of.h | 2 ++ 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index d4a1c9a..af3b22a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -391,6 +391,29 @@ struct device_node *of_get_next_available_child(const struct device_node *node, EXPORT_SYMBOL(of_get_next_available_child); /** + * of_get_child_by_name - Find the child node by name for a given parent + * @node: parent node + * @name: child name to look for. + * + * This function looks for child node for given matching name + * + * Returns a node pointer if found, with refcount incremented, use + * of_node_put() on it when done. + * Returns NULL if node is not found. + */ +struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name) +{ + struct device_node *child; + + for_each_child_of_node(node, child) + if (child->name && (of_node_cmp(child->name, name) == 0)) + break; + return child; +} +EXPORT_SYMBOL(of_get_child_by_name); + +/** * of_find_node_by_path - Find a node matching a full OF path * @path: The full path to match * diff --git a/include/linux/of.h b/include/linux/of.h index 1b11632..7b8e3cd 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -192,6 +192,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev); extern struct device_node *of_get_next_available_child( const struct device_node *node, struct device_node *prev); +extern struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name); #define for_each_child_of_node(parent, child) \ for (child = of_get_next_child(parent, NULL); child != NULL; \