From patchwork Wed Feb 4 06:59:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neelesh Gupta X-Patchwork-Id: 436161 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 73809140218 for ; Wed, 4 Feb 2015 18:01:41 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 5FF211A09F2 for ; Wed, 4 Feb 2015 18:01:41 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e28smtp02.in.ibm.com (e28smtp02.in.ibm.com [122.248.162.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id C366E1A09D8 for ; Wed, 4 Feb 2015 18:01:37 +1100 (AEDT) Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Feb 2015 12:31:35 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp02.in.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Feb 2015 12:31:33 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 71D58125805A for ; Wed, 4 Feb 2015 12:32:35 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1471U4538338654 for ; Wed, 4 Feb 2015 12:31:30 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1471USA013498 for ; Wed, 4 Feb 2015 12:31:30 +0530 Received: from localhost.localdomain ([9.124.35.239]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t1471UUl013494 for ; Wed, 4 Feb 2015 12:31:30 +0530 To: skiboot@lists.ozlabs.org From: Neelesh Gupta Date: Wed, 04 Feb 2015 12:29:25 +0530 Message-ID: <20150204065842.3278.11609.stgit@localhost.localdomain> In-Reply-To: <20150204065108.3278.92169.stgit@localhost.localdomain> References: <20150204065108.3278.92169.stgit@localhost.localdomain> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15020407-0005-0000-0000-000003AD7068 Subject: [Skiboot] [PATCH v3 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);