From patchwork Fri Nov 28 16:38:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 5405001 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8AAEC9F301 for ; Fri, 28 Nov 2014 16:41:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3A1320149 for ; Fri, 28 Nov 2014 16:41:15 +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 BD5C12013A for ; Fri, 28 Nov 2014 16:41:14 +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 1XuOZ3-0001T5-HI; Fri, 28 Nov 2014 16:38:37 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XuOYy-0001AT-LD for linux-arm-kernel@lists.infradead.org; Fri, 28 Nov 2014 16:38:33 +0000 Received: by mail-wi0-f169.google.com with SMTP id r20so21609627wiv.0 for ; Fri, 28 Nov 2014 08:38:11 -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=JDFFTWBIbm/qiCdJIt0bTFoAw/uHYKP6SHM2rV49IBQ=; b=MAP6i1StgP2wwNYTvBR0Ph/jg5M7RPEmxg3fxNKiquVUiRWNKpsmegaZS6KXNe+Yxw BM42vE+pknuRvtEYKtACCTPrzVbszsNvNNOOPVlGc2BKEdHE23knNrpDDKlyRqObOkrk x4PwH0j0j8ixB/xjuG2GZppVhSL3hO1feaZHJ9i7eEHmkTJYusYjxvPfS/nNgILxcTIf p9BIDeWffKct/XMtbFa6qefwByzdIdiWq5mfm7bFNerlH6WHs3HQvD5o1teoZ1qewBOR d95tuZ/d/D/iojIhC1gjEBrHkm27uScPUlupcBF+KYZ7FE9UQmneMOf46exLrbWlTeN7 huag== X-Gm-Message-State: ALoCoQlUEzd+kLJneeokibNgqiCLqZrTOC4QOxMChGZybT70HHydddf1NhJjSS6kkyZcCLsiGIrl X-Received: by 10.180.78.225 with SMTP id e1mr41788608wix.32.1417192690882; Fri, 28 Nov 2014 08:38:10 -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 pu3sm15670451wjc.14.2014.11.28.08.38.09 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Nov 2014 08:38:10 -0800 (PST) Date: Fri, 28 Nov 2014 16:38:07 +0000 From: Leif Lindholm To: Grant Likely Subject: Re: [PATCH v3 2/3] of: add optional options parameter to? of_find_node_by_path() Message-ID: <20141128163807.GN2361@bivouac.eciton.net> References: <1417110967-16284-1-git-send-email-leif.lindholm@linaro.org> <1417110967-16284-3-git-send-email-leif.lindholm@linaro.org> <20141128004403.08D90C40A7F@trevor.secretlab.ca> <20141128113428.GM2361@bivouac.eciton.net> <20141128152512.2152EC40884@trevor.secretlab.ca> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141128152512.2152EC40884@trevor.secretlab.ca> 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-20141128_083832_874392_D1590A48 X-CRM114-Status: GOOD ( 26.29 ) 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, 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 On Fri, Nov 28, 2014 at 03:25:12PM +0000, Grant Likely wrote: > On Fri, 28 Nov 2014 11:34:28 +0000 > , Leif Lindholm > wrote: > > On Fri, Nov 28, 2014 at 12:44:03AM +0000, Grant Likely wrote: > > > > + separator = strchr(path, ':'); > > > > + if (separator && opts) > > > > + *opts = separator + 1; > > > > + > > > > > > What about when there are no opts? Do we require the caller to make sure > > > opts is NULL before calling the function (which sounds like a good > > > source of bugs) or do we clear it on successful return? > > > > > > I think if opts is passed in, but there are no options, then it should > > > set *opts = NULL. > > > > Yeah, oops. > > > > > There should be test cases for this also. Must set opts to NULL on > > > successful return, and (I think) should leave opts alone on an > > > unsuccessful search. > > > > I would actually argue for always nuking the opts - since that could > > (theoretically) prevent something working by accident in spite of > > error conditions. > > > > How about the below? > > Perfect, applied with one fixup below... Thanks! And since it's Friday... *cough* From 5c469dad81961164c444da7d6c4e1c5b1c097aab Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Fri, 28 Nov 2014 16:27:25 +0000 Subject: [PATCH] of: fix options clearing when path is "/" The addition of the optional options extraction on of_find_node_opts_by_path failed to clear incoming options pointer if the specified path was "/". Resolve this case, and add a test to detect it. Signed-off-by: Leif Lindholm --- drivers/of/base.c | 11 ++++++----- drivers/of/selftest.c | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 5e16c6b..32664d1 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -743,15 +743,16 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt struct device_node *np = NULL; struct property *pp; unsigned long flags; - char *separator; + char *separator = NULL; + + if (opts) { + separator = strchr(path, ':'); + *opts = separator ? separator + 1 : NULL; + } if (strcmp(path, "/") == 0) return of_node_get(of_allnodes); - separator = strchr(path, ':'); - if (opts) - *opts = separator ? separator + 1 : NULL; - /* The path could begin with an alias */ if (*path != '/') { char *p = strchrnul(path, '/'); diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 721b2a4..914f0ae 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -100,6 +100,11 @@ static void __init of_selftest_find_node_by_name(void) np = of_find_node_opts_by_path("testcase-alias", &options); selftest(np && !options, "option clearing test failed\n"); of_node_put(np); + + options = "testoption"; + np = of_find_node_opts_by_path("/", &options); + selftest(np && !options, "option clearing root node test failed\n"); + of_node_put(np); } static void __init of_selftest_dynamic(void)