From patchwork Tue May 13 14:58:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 30058 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5FFF520369 for ; Tue, 13 May 2014 14:59:10 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf2091466iec.10 for ; Tue, 13 May 2014 07:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=/JXrSKYPznyvAEPqFXqzUpfyPD2xVLRjT7oaqXB2qfk=; b=S/sTGZGxp5q2sJHGPuuKoWMETfHPD1eSwBZz/w2gYALOokTpK7Qesdt8qz8Pooi+mi deEs8ddE9My2AqwsV1KMFhHHgYM9dMe+la82x2mBzt5UgDznV2xRl9h6cP4VL/z61KbM iivSvUNqarMent73+Pc0paNjG+N9zvWeUrcNqe1mBcAxOAIIwulA6GSkHBSd0hf+HPP5 vyWp0d4hMjZrdYOBnZLRAH25wurcjzfn1D7kPawFEu4BKev2LmnRDATmG6ewaZJ0NHYn rY5X+f/o4kR/b3VvKOol8BSlzouMi2dIvzDcpqd389Am1CX/N7lwYIkGvjIOC4OczTER k9vw== X-Gm-Message-State: ALoCoQnYI9JCWH+B+t4GePBXYaeZaNg2Ct4tShVcXospemQHjhpFliKki2RRQKqhZU6I/k7a8rWW X-Received: by 10.182.58.71 with SMTP id o7mr17222640obq.3.1399993149614; Tue, 13 May 2014 07:59:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.44.36 with SMTP id f33ls1877726qga.19.gmail; Tue, 13 May 2014 07:59:09 -0700 (PDT) X-Received: by 10.52.229.197 with SMTP id ss5mr201452vdc.83.1399993149484; Tue, 13 May 2014 07:59:09 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id xo2si2690572vec.116.2014.05.13.07.59.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 07:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id oy12so581100veb.24 for ; Tue, 13 May 2014 07:59:09 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr29537743vcb.0.1399993149364; Tue, 13 May 2014 07:59:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp157827vcb; Tue, 13 May 2014 07:59:08 -0700 (PDT) X-Received: by 10.66.148.98 with SMTP id tr2mr64833621pab.33.1399993148276; Tue, 13 May 2014 07:59:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rw8si8115105pbc.276.2014.05.13.07.59.07; Tue, 13 May 2014 07:59:07 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964988AbaEMO6u (ORCPT + 27 others); Tue, 13 May 2014 10:58:50 -0400 Received: from mail-ee0-f48.google.com ([74.125.83.48]:58186 "EHLO mail-ee0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964973AbaEMO6p (ORCPT ); Tue, 13 May 2014 10:58:45 -0400 Received: by mail-ee0-f48.google.com with SMTP id e49so505883eek.35 for ; Tue, 13 May 2014 07:58:44 -0700 (PDT) X-Received: by 10.14.225.73 with SMTP id y49mr41972037eep.43.1399993124698; Tue, 13 May 2014 07:58:44 -0700 (PDT) Received: from trevor.secretlab.ca (host109-150-134-147.range109-150.btcentralplus.com. [109.150.134.147]) by mx.google.com with ESMTPSA id v47sm13937025eel.22.2014.05.13.07.58.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 07:58:43 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 46610C40A49; Tue, 13 May 2014 15:58:41 +0100 (BST) From: Grant Likely To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Grant Likely , David Daney , Pantelis Antoniou Subject: [PATCH 2/3] of: Make of_find_node_by_path() handle /aliases Date: Tue, 13 May 2014 15:58:34 +0100 Message-Id: <1399993115-21552-3-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399993115-21552-1-git-send-email-grant.likely@linaro.org> References: <1399993115-21552-1-git-send-email-grant.likely@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Make of_find_node_by_path() handle aliases as prefixes. To make this work the name search is refactored to search by path component instead of by full string. This should be a more efficient search, and it makes it possible to start a search at a subnode of a tree. Signed-off-by: David Daney Signed-off-by: Pantelis Antoniou [grant.likely: Rework to not require allocating at runtime] Acked-by: Rob Herring Signed-off-by: Grant Likely --- drivers/of/base.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 6e240698353b..60089b9a3014 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -771,9 +771,38 @@ struct device_node *of_get_child_by_name(const struct device_node *node, } EXPORT_SYMBOL(of_get_child_by_name); +static struct device_node *__of_find_node_by_path(struct device_node *parent, + const char *path) +{ + struct device_node *child; + int len = strchrnul(path, '/') - path; + + if (!len) + return parent; + + for_each_child_of_node(parent, child) { + const char *name = strrchr(child->full_name, '/'); + if (WARN(!name, "malformed device_node %s\n", child->full_name)) + continue; + name++; + if (strncmp(path, name, len) == 0 && (strlen(name) == len)) + return child; + } + return NULL; +} + /** * of_find_node_by_path - Find a node matching a full OF path * @path: The full path to match + * @path: Either the full path to match, or if the path does not + * start with '/', the name of a property of the /aliases + * node (an alias). In the case of an alias, the node + * matching the alias' value will be returned. + * + * Valid paths: + * /foo/bar Full path + * foo Valid alias + * foo/bar Valid alias + relative path * * Returns a node pointer with refcount incremented, use * of_node_put() on it when done. @@ -781,13 +810,36 @@ EXPORT_SYMBOL(of_get_child_by_name); struct device_node *of_find_node_by_path(const char *path) { struct device_node *np = of_allnodes; + struct property *pp; unsigned long flags; + /* The path could begin with an alias */ + if (*path != '/') { + char *p = strchrnul(path, '/'); + int len = p - path; + + /* of_aliases must not be NULL */ + if (!of_aliases) + return NULL; + + np = NULL; + for_each_property_of_node(of_aliases, pp) { + if (strlen(pp->name) == len && !strncmp(pp->name, path, len)) { + np = of_find_node_by_path(pp->value); + break; + } + } + if (!np) + return NULL; + path = p; + } + + /* Step down the tree matching path components */ raw_spin_lock_irqsave(&devtree_lock, flags); - for (; np; np = np->allnext) { - if (np->full_name && (of_node_cmp(np->full_name, path) == 0) - && of_node_get(np)) - break; + while (np && *path == '/') { + path++; /* Increment past '/' delimiter */ + np = __of_find_node_by_path(np, path); + path = strchrnul(path, '/'); } raw_spin_unlock_irqrestore(&devtree_lock, flags); return np;