From patchwork Sun Dec 21 18:30:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neelesh Gupta X-Patchwork-Id: 423193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F17A71400B7 for ; Mon, 22 Dec 2014 05:32:01 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id DE5A81A0198 for ; Mon, 22 Dec 2014 05:32:01 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 6F93E1A0147 for ; Mon, 22 Dec 2014 05:31:59 +1100 (AEDT) Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Dec 2014 04:31:59 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 Dec 2014 04:31:57 +1000 Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id E5C3E2CE8060 for ; Mon, 22 Dec 2014 05:31:56 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBLIVuXW27328572 for ; Mon, 22 Dec 2014 05:31:56 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBLIVuK8023884 for ; Mon, 22 Dec 2014 05:31:56 +1100 Received: from [192.168.1.2] ([9.80.67.85]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sBLIVqBY023699; Mon, 22 Dec 2014 05:31:54 +1100 To: skiboot@lists.ozlabs.org, dipankar@in.ibm.com, ananth@in.ibm.com, benh@kernel.crashing.org From: Neelesh Gupta Date: Mon, 22 Dec 2014 00:00:01 +0530 Message-ID: <20141221182923.7062.17260.stgit@ZyXEL0> In-Reply-To: <20141221182235.7062.868.stgit@ZyXEL0> References: <20141221182235.7062.868.stgit@ZyXEL0> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14122118-0025-0000-0000-000000C99906 Subject: [Skiboot] [PATCH v1 1/3] core/device: Function to return child node using name X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Add a function dt_find_by_name() that returns the child node if matches the given name, otherwise NULL. Signed-off-by: Neelesh Gupta --- core/device.c | 16 ++++++++++++++++ include/device.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/core/device.c b/core/device.c index 51ddbdb..09f76d7 100644 --- a/core/device.c +++ b/core/device.c @@ -250,6 +250,22 @@ struct dt_node *dt_find_by_path(struct dt_node *root, const char *path) return root; } +struct dt_node *dt_find_by_name(struct dt_node *root, const char *name) +{ + struct dt_node *child, *match; + + list_for_each(&root->children, child, list) { + if (!strcmp(child->name, name)) + return child; + + match = dt_find_by_name(child, name); + if (match) + return match; + } + + return NULL; +} + struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle) { struct dt_node *node; diff --git a/include/device.h b/include/device.h index 16c26bb..b301958 100644 --- a/include/device.h +++ b/include/device.h @@ -167,6 +167,9 @@ char *dt_get_path(const struct dt_node *node); /* Find a node by path */ struct dt_node *dt_find_by_path(struct dt_node *root, const char *path); +/* Find a child node by name */ +struct dt_node *dt_find_by_name(struct dt_node *root, const char *name); + /* Find a node by phandle */ struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle);