From patchwork Wed Jun 14 20:30:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 105579 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp471809qgd; Wed, 14 Jun 2017 13:30:41 -0700 (PDT) X-Received: by 10.99.121.13 with SMTP id u13mr1730006pgc.147.1497472240899; Wed, 14 Jun 2017 13:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497472240; cv=none; d=google.com; s=arc-20160816; b=ZHA+puX7mfV087IAalVpZm7uzxW/6uWgaW2SH1FqWPTc5/txs06qRHNriMWQ05gzCp qHL0XhhehNNfRPepClwNd53apNjHOd38yK7W1JQIY7rKQuBO6WgBP5xuyq/bgtX6Rr04 Z9Q84o8MyKnHsBbq1uImtLCdPTMCRFLMU0Sdr1W3xQXRX6YTdoHb9Mzp4mwxsT7yY0Z3 lfiR/Y7/pWqVu5EjXjBX+47LTeQDXFTavw+dCHyzFtFNIjzov04jKdvIAHBAiD7VKZ1q w85hlOf9uzWJesVMbogTCOzrC9Oq8zqenAZdGJ0iUgrQTz8APx77opKywjx0+VP6oKrb BPnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TQiXFrEtI2VsVLFvB9pEct/S2y/XE4c6xAV3sHwE+iU=; b=iFRYelAHKEGs/cDftDz/8UX1EProcRkFyJJ1AAcbBZccNMfcGCEKjLr01xmIugsDRd kgzFOAb4Vf2jCkP+y750EgFus2x0Q9GGdWhfE/LF0jxVaxAn7a2skR7ulGw7di8YqFxO c1J6qeRtuBELC2UELLlXiuDKuGjAYS0bwyDCbXOqwkI7GYa3Z5FfIb1tD8wrhcYyndLM G1ro3Lvziqxy5kvjorysMS3bp7ZulCnnHMx1NC7FC1W0NVbcj4fnfyz8gdKsdleiQnJy PgmcaOa+397o04/6bRv3T0G2ejSgMyVtqOYtcV0LzT3G2O16vKDtsIN6PuCxgSXGu++p K+PA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si678968pgn.171.2017.06.14.13.30.40; Wed, 14 Jun 2017 13:30:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752429AbdFNUae (ORCPT + 25 others); Wed, 14 Jun 2017 16:30:34 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:35564 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752359AbdFNUab (ORCPT ); Wed, 14 Jun 2017 16:30:31 -0400 Received: by mail-oi0-f65.google.com with SMTP id v74so944300oie.2; Wed, 14 Jun 2017 13:30:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TQiXFrEtI2VsVLFvB9pEct/S2y/XE4c6xAV3sHwE+iU=; b=kFv3H3Px9f6uTrya0R91qL7Tqh5aU57G+acwJbs9QYh8X2MdyLKD4de2J79iP5OfG5 TQYHO4sLaTdEwLfPH3DLdQZ2AvnJw+zhkXiovvMjMWUZB8iyFkGmU5fq4aeL2afLvmn3 jlHT80zNVguaHbPw+iy38TxRpKp4hIxCy/LxA8WWHVJXaeSBI+dpIKrfJLpX8cLuPwAS tRcmrh/yHhSL578IXkvkAlp6QtjFm03QWnCNYaQETnZjefEvhVZp2NwIPvsJ0UGRdDNH 9ODktLS+Nf/8Ljca1qgYKpeINQWqrkLkyoo2ZHkM1zrUistganhcGTC9qyw290p6f1R7 55Lw== X-Gm-Message-State: AKS2vOxUwNV2BtcK+njHZd0aqLJUt34MjwAt0KTj33fNigCLPX6D8zCw dfHjXu3TH5bWxQ== X-Received: by 10.202.88.214 with SMTP id m205mr1298087oib.173.1497472230868; Wed, 14 Jun 2017 13:30:30 -0700 (PDT) Received: from localhost.localdomain (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id w104sm586861ota.19.2017.06.14.13.30.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jun 2017 13:30:30 -0700 (PDT) From: Rob Herring To: Frank Rowand , Mark Rutland Cc: Pantelis Antoniou , Joe Perches , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] of: find_node_by_full_name rewrite to compare each level Date: Wed, 14 Jun 2017 15:30:23 -0500 Message-Id: <20170614203025.7581-3-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170614203025.7581-1-robh@kernel.org> References: <20170614203025.7581-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org find_node_by_full_name() does the same thing as of_find_node_by_path(), but takes no locks and doesn't work on aliases. Refactor of_find_node_opts_by_path() into __of_find_node_by_full_path() and replace find_node_by_full_name() with it. Signed-off-by: Rob Herring --- drivers/of/base.c | 29 +++++++++++++++++++---------- drivers/of/of_private.h | 3 +++ drivers/of/resolver.c | 30 +++--------------------------- 3 files changed, 25 insertions(+), 37 deletions(-) -- 2.11.0 diff --git a/drivers/of/base.c b/drivers/of/base.c index 054159ccd5f8..02be991a29c5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -780,6 +780,24 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, return NULL; } +struct device_node *__of_find_node_by_full_path(struct device_node *node, + const char *path) +{ + const char *separator = strchr(path, ':'); + + while (node && *path == '/') { + struct device_node *tmp = node; + + path++; /* Increment past '/' delimiter */ + node = __of_find_node_by_path(node, path); + of_node_put(tmp); + path = strchrnul(path, '/'); + if (separator && separator < path) + break; + } + return node; +} + /** * of_find_node_opts_by_path - Find a node matching a full OF path * @path: Either the full path to match, or if the path does not @@ -839,16 +857,7 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt raw_spin_lock_irqsave(&devtree_lock, flags); if (!np) np = of_node_get(of_root); - while (np && *path == '/') { - struct device_node *tmp = np; - - path++; /* Increment past '/' delimiter */ - np = __of_find_node_by_path(np, path); - of_node_put(tmp); - path = strchrnul(path, '/'); - if (separator && separator < path) - break; - } + np =__of_find_node_by_full_path(np, path); raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 4ebb0149d118..e7bbfa3e9632 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -77,6 +77,9 @@ extern void *__unflatten_device_tree(const void *blob, struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); __printf(2, 3) struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...); +struct device_node *__of_find_node_by_full_path(struct device_node *node, + const char *path); + extern const void *__of_get_property(const struct device_node *np, const char *name, int *lenp); extern int __of_add_property(struct device_node *np, struct property *prop); diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 63626d7d9adb..b3f987c1301b 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c @@ -20,35 +20,11 @@ #include #include +#include "of_private.h" + /* illegal phandle value (set when unresolved) */ #define OF_PHANDLE_ILLEGAL 0xdeadbeef -/** - * Find a node with the give full name by recursively following any of - * the child node links. - */ -static struct device_node *find_node_by_full_name(struct device_node *node, - const char *full_name) -{ - struct device_node *child, *found; - - if (!node) - return NULL; - - if (!of_node_cmp(node->full_name, full_name)) - return of_node_get(node); - - for_each_child_of_node(node, child) { - found = find_node_by_full_name(child, full_name); - if (found != NULL) { - of_node_put(child); - return found; - } - } - - return NULL; -} - static phandle live_tree_max_phandle(void) { struct device_node *node; @@ -138,7 +114,7 @@ static int update_usages_of_a_phandle_reference(struct device_node *overlay, if (err) goto err_fail; - refnode = find_node_by_full_name(overlay, node_path); + refnode = __of_find_node_by_full_path(overlay, node_path); if (!refnode) continue;