From patchwork Tue Mar 17 16:14: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: 45886 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E5FB62153C for ; Tue, 17 Mar 2015 16:14:08 +0000 (UTC) Received: by wggy19 with SMTP id y19sf2652270wgg.2 for ; Tue, 17 Mar 2015 09:14:08 -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=tRBDpI8JR+7HZ9gyIgnnE6ExVcwXrH0HI+O2tUt4eJY=; b=BIdPjNA1Gz3XX3osskJ4uziC2NIVJSLtBHtkKLE3I2l/RoAZe3xpn3uwRO9YAu+j0l C4DFvD5WLF6pzAG0SGH059392AZ1kJSr2q/fYJTaZsvXxDFyaxW6p6T+Y/bdzapFLbdu h82TyH5Un8Sk2Vp5+SQ2u20pzWF2jdcEykOobrmH3vMf3+Sj1LcBcVYDKmGqt2l6zJDI K/32KaLeoUnw+cPOAPk3ErrDPVHfdYA+nh4lL+80BSDRTV0bT2/3bJ25l4UMwBNp6QFv PSTJBIqh7gyB/KBjW0Yf75Up2qbqeDoW+6IpkVWsVV/ZUfJRw37NFz4Q/xeQgwKkMcQX KV2g== X-Gm-Message-State: ALoCoQnFs4+VzwmL+zl/Y5IdAjPfRf4nbjgUsQP2ZimWq0ziBEJqfIE3/2B/NK3glmzoqf9WwpcQ X-Received: by 10.194.11.70 with SMTP id o6mr10265484wjb.6.1426608848216; Tue, 17 Mar 2015 09:14:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.8 with SMTP id j8ls66489lae.7.gmail; Tue, 17 Mar 2015 09:14:07 -0700 (PDT) X-Received: by 10.112.44.132 with SMTP id e4mr60380735lbm.66.1426608847913; Tue, 17 Mar 2015 09:14:07 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id pl9si5849841lbb.70.2015.03.17.09.14.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2015 09:14:07 -0700 (PDT) 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 lamx15 with SMTP id x15so12985021lam.3 for ; Tue, 17 Mar 2015 09:14:07 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr41718903lbc.36.1426608847467; Tue, 17 Mar 2015 09:14:07 -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.112.35.133 with SMTP id h5csp612385lbj; Tue, 17 Mar 2015 09:14:06 -0700 (PDT) X-Received: by 10.66.62.201 with SMTP id a9mr151662669pas.101.1426608845523; Tue, 17 Mar 2015 09:14:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kl7si30156768pdb.199.2015.03.17.09.14.04; Tue, 17 Mar 2015 09:14:05 -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 S1754309AbbCQQOE (ORCPT + 5 others); Tue, 17 Mar 2015 12:14:04 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:35517 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754115AbbCQQOD (ORCPT ); Tue, 17 Mar 2015 12:14:03 -0400 Received: by wibdy8 with SMTP id dy8so67387597wib.0 for ; Tue, 17 Mar 2015 09:14:01 -0700 (PDT) X-Received: by 10.194.239.65 with SMTP id vq1mr130013043wjc.98.1426608840836; Tue, 17 Mar 2015 09:14:00 -0700 (PDT) Received: from mohikan.mushroom.smurfnet.nu (cpc4-cmbg17-2-0-cust71.5-4.cable.virginm.net. [86.14.224.72]) by mx.google.com with ESMTPSA id dx11sm20554900wjb.23.2015.03.17.09.13.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Mar 2015 09:14:00 -0700 (PDT) From: Leif Lindholm To: devicetree@vger.kernel.org Cc: robh@kernel.org, hdegoede@redhat.com, peter@hurleysoftware.com, grant.likely@linaro.org Subject: [PATCH 2/2] of: fix handling of '/' in paths with options Date: Tue, 17 Mar 2015 16:14:53 +0000 Message-Id: <1426608893-3739-3-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426608893-3739-1-git-send-email-leif.lindholm@linaro.org> References: <1426608893-3739-1-git-send-email-leif.lindholm@linaro.org> 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: , 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 Tested-by: Hans de Goede Signed-off-by: Leif Lindholm --- drivers/of/base.c | 21 +++++++++++++-------- drivers/of/unittest.c | 5 +++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 3b1aa08..2ee7265 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -714,16 +714,15 @@ 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 *p1, *p2; + p1 = strchrnul(path, ':'); + p2 = strchrnul(path, '/'); + len = (p1 < p2 ? p1 : p2) - 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 +767,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 +797,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; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index aba8946..8d94349 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -97,6 +97,11 @@ static void __init of_selftest_find_node_by_name(void) "option path test, subcase #1 failed\n"); of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data/phandle-tests:test/option", &options); + selftest(np && !strcmp("test/option", options), + "option path test, subcase #2 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);