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: 5956611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 33A1CBF440 for ; Fri, 6 Mar 2015 16:58:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 429522037E for ; Fri, 6 Mar 2015 16:58:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56B9B20123 for ; Fri, 6 Mar 2015 16:58:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTvXe-0000UR-Pu; Fri, 06 Mar 2015 16:56:02 +0000 Received: from mail-we0-f171.google.com ([74.125.82.171]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTvV5-0005pN-4u for linux-arm-kernel@lists.infradead.org; Fri, 06 Mar 2015 16:53:24 +0000 Received: by wevm14 with SMTP id m14so60617203wev.13 for ; Fri, 06 Mar 2015 08:52:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=ILLPqm7SgkObkDr0kZopTxd+hVjjC3MIN3l4d0/PPO4=; b=ViuYoS1d+v1HbrsEFTnQmmRRg9cHX2nHbJNl//HKWMZAKwc6pw35g3fAHyuK40DjKO gJWL23rOBmv6gAzMVS4++bKRDsBxfp6qJziLbE1qLL0ZSQNFC6YLjKj8CQijfD244rYh dJ7lVrqonobEo350FyxRnNdPRrTylcZxUvyges6NZxG5TIQJaCk2w0HB39kY5IeZqsa1 s8pmSHUeQGdnsSrRpQjB4p8MoP+cyXM83BVME2xu239E9MST7a1tl0/0Hi6Id1CSXpBT n+0m/bkSilBnOhQ/3MS130jz9tLuN+E0DQuWSeQL+0Q6jUMw/5BwUNXCGb066U1R8pVK grNw== X-Gm-Message-State: ALoCoQk5ydzBQsSbUocb12EKlPvpshOu+t/O3O/pT7KIYOWy6g8Vsx7PTb193wC/5CilnRBKoC9T 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150306_085323_391295_090ABA76 X-CRM114-Status: GOOD ( 19.54 ) X-Spam-Score: -0.7 (/) Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, andrew@lunn.ch, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ijc@debian.org, grant.likely@linaro.org, plagnioj@jcrosoft.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;