From patchwork Fri Mar 6 16:52:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 45492 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73057214A0 for ; Fri, 6 Mar 2015 16:53:04 +0000 (UTC) Received: by widex7 with SMTP id ex7sf144810wid.2 for ; Fri, 06 Mar 2015 08:53:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=ApXhsA26GnOm65jmPuafaAQvU9+g2rhSqHRMzY2uTpk=; b=fTQLKloVegoKNHMAFCbYBPEDDvaLxxcAKTnfNAOd00pf5KzjpYepWHfZ8wX/8nk9OC kk0RqpAmDUS5DrS5QXBHvR8rR2OYPGC4kw3DzIV2b4mQBiImCDLOSSfdICexkT0DNqKh dtRYlpLo+1wJK9SFEZ4JY0lzNbgpfASgEO5bvvKligMdIMxJwwj/s6SAmecgSvTvyM30 F6Ep0E8SHqvEMmwRRVMoD6NQp5fSuaKB87Wol4RDFKLmxGCikn0uS9+4oIkmvcQ4vj3M gBr8F+6FlOEVdJdizXe7A/MOwzZon8GOvY8PYaPu930X8EfEdKhgRchkp6LB2TWCrGw5 C+Iw== X-Gm-Message-State: ALoCoQmhH+ZQ9ZlNX/RWym/nyP8A0Id/u1MLszc3PmftwucHzRB8OH7TlTFQWxzFeQP+Xasy2GZN X-Received: by 10.112.159.227 with SMTP id xf3mr2508800lbb.11.1425660783733; Fri, 06 Mar 2015 08:53:03 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.199 with SMTP id s7ls82411laj.57.gmail; Fri, 06 Mar 2015 08:53:03 -0800 (PST) X-Received: by 10.152.19.9 with SMTP id a9mr13998802lae.80.1425660783582; Fri, 06 Mar 2015 08:53:03 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id h4si7513686lag.103.2015.03.06.08.53.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 08:53:03 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lamq1 with SMTP id q1so35731813lam.9 for ; Fri, 06 Mar 2015 08:53:03 -0800 (PST) X-Received: by 10.112.130.195 with SMTP id og3mr13561571lbb.112.1425660783481; Fri, 06 Mar 2015 08:53:03 -0800 (PST) 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.112.35.133 with SMTP id h5csp18126lbj; Fri, 6 Mar 2015 08:53:02 -0800 (PST) X-Received: by 10.66.138.109 with SMTP id qp13mr27476318pab.155.1425660781588; Fri, 06 Mar 2015 08:53:01 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si15690148pbt.67.2015.03.06.08.53.00; Fri, 06 Mar 2015 08:53:01 -0800 (PST) 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 S1754096AbbCFQw7 (ORCPT + 5 others); Fri, 6 Mar 2015 11:52:59 -0500 Received: from mail-we0-f174.google.com ([74.125.82.174]:45154 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbbCFQw7 (ORCPT ); Fri, 6 Mar 2015 11:52:59 -0500 Received: by wesp10 with SMTP id p10so58430941wes.12 for ; Fri, 06 Mar 2015 08:52:58 -0800 (PST) X-Received: by 10.180.211.206 with SMTP id ne14mr76589073wic.79.1425660777880; Fri, 06 Mar 2015 08:52:57 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by mx.google.com with ESMTPSA id g5sm15701001wjr.19.2015.03.06.08.52.55 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Mar 2015 08:52:55 -0800 (PST) Date: Fri, 6 Mar 2015 16:52:53 +0000 From: Leif Lindholm To: Peter Hurley Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, grant.likely@linaro.org, robh+dt@kernel.org, plagnioj@jcrosoft.com, ijc@debian.org, andrew@lunn.ch, s.hauer@pengutronix.de Subject: Re: [PATCH v3 2/3] of: add optional options parameter to of_find_node_by_path() Message-ID: <20150306165253.GJ4278@bivouac.eciton.net> References: <1417110967-16284-1-git-send-email-leif.lindholm@linaro.org> <1417110967-16284-3-git-send-email-leif.lindholm@linaro.org> <54F7287E.6060302@hurleysoftware.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <54F7287E.6060302@hurleysoftware.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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: leif.lindholm@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.215.47 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: , Hi Peter, On Wed, Mar 04, 2015 at 10:45:02AM -0500, Peter Hurley wrote: > The path parsing gets lost if the string after ':' contains '/'. Doh! Thanks for reporting (and sorry for slow response). > The selftests below fail with: > [ 1.365528] ### dt-test ### FAIL of_selftest_find_node_by_name():99 option path test failed > [ 1.365610] ### dt-test ### FAIL of_selftest_find_node_by_name():115 option alias path test failed > > Regards, > Peter Hurley > > > --- >% --- > diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c > index 41a4a13..07ba5aa 100644 > --- a/drivers/of/unittest.c > +++ b/drivers/of/unittest.c > @@ -94,6 +94,11 @@ static void __init of_selftest_find_node_by_name(void) > "option path test failed\n"); > of_node_put(np); > > + np = of_find_node_opts_by_path("/testcase-data:test/option", &options); > + selftest(np && !strcmp("test/option", options), > + "option path test failed\n"); > + of_node_put(np); > + > np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); > selftest(np, "NULL option path test failed\n"); > of_node_put(np); > @@ -104,6 +109,12 @@ static void __init of_selftest_find_node_by_name(void) > "option alias path test failed\n"); > of_node_put(np); > > + np = of_find_node_opts_by_path("testcase-alias:test/alias/option", > + &options); > + selftest(np && !strcmp("test/alias/option", options), > + "option alias path test failed\n"); > + of_node_put(np); > + > np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL); > selftest(np, "NULL option alias path test failed\n"); > of_node_put(np); Could you give the below a spin, and if it works for you, send me the above tests as a full patch so that I can post both as a series? Regards, Leif >From bf4ab0b2e33902ba88809a3c4a2cdf07efd02dde Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Fri, 6 Mar 2015 16:38:54 +0000 Subject: [PATCH] of: fix handling of '/' in options for of_find_node_by_path() Ensure proper handling of paths with appended options (after ':'), where those options may contain a '/'. Fixes: 7914a7c5651a ("of: support passing console options with stdout-path") Reported-by: Peter Hurley Signed-off-by: Leif Lindholm --- drivers/of/base.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 0a8aeb8..8b904e5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -714,16 +714,17 @@ 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; - int term; + int len; + const char *end; + end = strchr(path, ':'); + if (!end) + end = strchrnul(path, '/'); + + len = end - path; if (!len) return NULL; - term = strchrnul(path, ':') - path; - if (term < len) - len = term; - __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)) @@ -768,8 +769,12 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt /* The path could begin with an alias */ if (*path != '/') { - char *p = strchrnul(path, '/'); - int len = separator ? separator - path : p - path; + int len; + const char *p = separator; + + if (!p) + p = strchrnul(path, '/'); + len = p - path; /* of_aliases must not be NULL */ if (!of_aliases) @@ -794,6 +799,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt path++; /* Increment past '/' delimiter */ np = __of_find_node_by_path(np, path); path = strchrnul(path, '/'); + if (separator && separator < path) + break; } raw_spin_unlock_irqrestore(&devtree_lock, flags); return np;