From patchwork Tue Jan 13 05:46:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neelesh Gupta X-Patchwork-Id: 428265 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 A88041401B5 for ; Tue, 13 Jan 2015 16:52:18 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 8CA8D1A09F3 for ; Tue, 13 Jan 2015 16:52:18 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e28smtp06.in.ibm.com (e28smtp06.in.ibm.com [122.248.162.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id C32281A0851 for ; Tue, 13 Jan 2015 16:52:13 +1100 (AEDT) Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Jan 2015 11:22:08 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Jan 2015 11:22:06 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id B23EA1258078 for ; Tue, 13 Jan 2015 11:19:02 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0D5m9iK3473686 for ; Tue, 13 Jan 2015 11:18:12 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t0D5m9wT024952 for ; Tue, 13 Jan 2015 11:18:09 +0530 Received: from localhost.localdomain ([9.124.35.100]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t0D5m9sY024860 for ; Tue, 13 Jan 2015 11:18:09 +0530 To: skiboot@lists.ozlabs.org From: Neelesh Gupta Date: Tue, 13 Jan 2015 11:16:11 +0530 Message-ID: <20150113054600.8790.59439.stgit@localhost.localdomain> In-Reply-To: <20150113053756.8790.20914.stgit@localhost.localdomain> References: <20150113053756.8790.20914.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: 15011305-0021-0000-0000-0000034F8C97 Subject: [Skiboot] [PATCH v2 1/2] 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);