From patchwork Thu May 22 03:13:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 30554 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 71AD120675 for ; Thu, 22 May 2014 03:38:24 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id w7sf8917950qcr.4 for ; Wed, 21 May 2014 20:38:24 -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:subject:to:cc :in-reply-to:references:date:message-id:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=tSmDPbqkzulktR7VlKV5obPvNvk8Kyrk/sSmfnQRVNo=; b=gZGXy4cIysT0IfclPe/tbG7L3l8ZlAyb9Y8XIvP4ZW+QeA+B2Hbj4KaLiq1fT6pkRh UbzDvQ19PvmzK6YjQ3cOugaUMpaQOa6UPFuaCg2CeCz1ymjDezOtvFn2YFGs2kXwBxI2 NEVE5yx1MKkteCXgDG8vgHu4MTGmreL10zPwI6iqGpNHqzsGzvJ6XxvHjMGQhUGvbPEH gzQcPRSLkWZmMW8npzrjsx+KlwY6j3IqyGoLTWFPGsJsN+PGsvNw77JWmRZgepl+4q4g xggWBzDfvKUVrsjKPqxolTJP+63DEES4m+eC8VygC1l6nhoXNW/Rg/X83klkUUxEi87R r9NA== X-Gm-Message-State: ALoCoQm80hClkXhwIdjmjfqVAIXHBDGo1faJ0kDu2GR2z3ri3s3l+40qTfbTVRdSbpPVuHc9E0Zn X-Received: by 10.236.231.52 with SMTP id k50mr10202215yhq.52.1400729904012; Wed, 21 May 2014 20:38:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.97 with SMTP id g88ls1135798qgf.40.gmail; Wed, 21 May 2014 20:38:23 -0700 (PDT) X-Received: by 10.58.126.4 with SMTP id mu4mr47717962veb.0.1400729903905; Wed, 21 May 2014 20:38:23 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id d9si4159074vcq.66.2014.05.21.20.38.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 May 2014 20:38:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jw12so3618791veb.5 for ; Wed, 21 May 2014 20:38:23 -0700 (PDT) X-Received: by 10.58.198.107 with SMTP id jb11mr47655203vec.10.1400729903795; Wed, 21 May 2014 20:38:23 -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 ib8csp164078vcb; Wed, 21 May 2014 20:38:23 -0700 (PDT) X-Received: by 10.68.138.227 with SMTP id qt3mr64284095pbb.6.1400729902809; Wed, 21 May 2014 20:38:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kq7si8772040pbc.143.2014.05.21.20.38.22; Wed, 21 May 2014 20:38:22 -0700 (PDT) Received-SPF: none (google.com: devicetree-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 S1750924AbaEVDiT (ORCPT + 8 others); Wed, 21 May 2014 23:38:19 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:55981 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbaEVDiS (ORCPT ); Wed, 21 May 2014 23:38:18 -0400 Received: by mail-pa0-f43.google.com with SMTP id hz1so2040911pad.2 for ; Wed, 21 May 2014 20:38:18 -0700 (PDT) X-Received: by 10.68.130.6 with SMTP id oa6mr63006490pbb.102.1400729898093; Wed, 21 May 2014 20:38:18 -0700 (PDT) Received: from trevor.secretlab.ca ([61.215.197.74]) by mx.google.com with ESMTPSA id jd5sm10496322pbb.18.2014.05.21.20.38.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 May 2014 20:38:17 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id DD6B7C41847; Thu, 22 May 2014 12:13:06 +0900 (JST) From: Grant Likely Subject: Re: [PATCH 2/3] of: Make of_find_node_by_path() handle /aliases To: frowand.list@gmail.com Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, David Daney , Pantelis Antoniou In-Reply-To: <537C137B.2000007@gmail.com> References: <1399993115-21552-1-git-send-email-grant.likely@linaro.org> <1399993115-21552-3-git-send-email-grant.likely@linaro.org> <53757D25.1060005@gmail.com> <20140516105444.C1DB7C42277@trevor.secretlab.ca> <20140518092730.109AAC40B8A@trevor.secretlab.ca> <537C1252.3090900@gmail.com> <537C137B.2000007@gmail.com> Date: Thu, 22 May 2014 12:13:06 +0900 Message-Id: <20140522031306.DD6B7C41847@trevor.secretlab.ca> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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.174 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: , On Tue, 20 May 2014 19:46:19 -0700, Frank Rowand wrote: > On 5/20/2014 7:41 PM, Frank Rowand wrote: > < snip > > > I will reply to this email with an additional patch that restores the > > original behavior. > < snip > > From: Frank Rowand > > If __of_find_node_by_path() returns parent when the remaining portion of the > path is "/" then the behavior of of_find_node_by_path() has changed. > > Previously, adding an extraneous "/" on the end of a path would result > in of_find_node_by_path() not finding a match. > > Signed-off-by: Frank Rowand > --- > drivers/of/base.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > Index: b/drivers/of/base.c > =================================================================== > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -778,7 +778,7 @@ static struct device_node *__of_find_nod > int len = strchrnul(path, '/') - path; > > if (!len) > - return parent; > + return NULL; > > for_each_child_of_node(parent, child) { > const char *name = strrchr(child->full_name, '/'); > @@ -813,6 +813,17 @@ struct device_node *of_find_node_by_path > struct property *pp; > unsigned long flags; > > + if (strcmp(path, "/") == 0) { > + 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; > + } > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > + return np; > + } > + Special case for the root node? Could use a comment, and of_allnodes will already point to the root node so this could simply be: if (strcmp(path, "/") == 0) return of_node_get(np); Here's a complete patch: commit adc96db6c39ef7b895e75d30dbc69781f6443f1d Author: Grant Likely Date: Thu May 22 11:55:31 2014 +0900 fix trailing '/' case --- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/of/base.c b/drivers/of/base.c index c05a143b6a70..45ac44c8dfea 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -790,7 +790,7 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, int len = strchrnul(path, '/') - path; if (!len) - return parent; + return NULL; __for_each_child_of_node(parent, child) { const char *name = strrchr(child->full_name, '/'); @@ -820,10 +820,13 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, */ struct device_node *of_find_node_by_path(const char *path) { - struct device_node *np = of_allnodes; + struct device_node *np = NULL; struct property *pp; unsigned long flags; + if (strcmp(path, "/") == 0) + return of_node_get(of_allnodes); + /* The path could begin with an alias */ if (*path != '/') { char *p = strchrnul(path, '/'); @@ -833,7 +836,6 @@ struct device_node *of_find_node_by_path(const char *path) 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); @@ -847,6 +849,8 @@ struct device_node *of_find_node_by_path(const char *path) /* Step down the tree matching path components */ raw_spin_lock_irqsave(&devtree_lock, flags); + if (!np) + np = of_node_get(of_allnodes); while (np && *path == '/') { path++; /* Increment past '/' delimiter */ np = __of_find_node_by_path(np, path); diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 10900b18fc06..aeb0b5c8b21d 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -42,9 +42,7 @@ static void __init of_selftest_find_node_by_name(void) /* Test if trailing '/' works */ np = of_find_node_by_path("/testcase-data/"); - selftest(np && !strcmp("/testcase-data", np->full_name), - "find /testcase-data/ failed\n"); - of_node_put(np); + selftest(!np, "trailing '/' on /testcase-data/ should fail\n"); np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), @@ -58,9 +56,7 @@ static void __init of_selftest_find_node_by_name(void) /* Test if trailing '/' works on aliases */ np = of_find_node_by_path("testcase-alias/"); - selftest(np && !strcmp("/testcase-data", np->full_name), - "find testcase-alias/ failed\n"); - of_node_put(np); + selftest(!np, "trailing '/' on testcase-alias/ should fail\n"); np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),