Skip to content

Commit 106937e

Browse files
Leif Lindholmrobherring
authored andcommitted
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: 7914a7c ("of: support passing console options with stdout-path") Reported-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> Cc: <stable@vger.kernel.org> # 3.19 Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 649022e commit 106937e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

drivers/of/base.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,17 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent,
714714
const char *path)
715715
{
716716
struct device_node *child;
717-
int len = strchrnul(path, '/') - path;
718-
int term;
717+
int len;
718+
const char *end;
719719

720+
end = strchr(path, ':');
721+
if (!end)
722+
end = strchrnul(path, '/');
723+
724+
len = end - path;
720725
if (!len)
721726
return NULL;
722727

723-
term = strchrnul(path, ':') - path;
724-
if (term < len)
725-
len = term;
726-
727728
__for_each_child_of_node(parent, child) {
728729
const char *name = strrchr(child->full_name, '/');
729730
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
768769

769770
/* The path could begin with an alias */
770771
if (*path != '/') {
771-
char *p = strchrnul(path, '/');
772-
int len = separator ? separator - path : p - path;
772+
int len;
773+
const char *p = separator;
774+
775+
if (!p)
776+
p = strchrnul(path, '/');
777+
len = p - path;
773778

774779
/* of_aliases must not be NULL */
775780
if (!of_aliases)
@@ -794,6 +799,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
794799
path++; /* Increment past '/' delimiter */
795800
np = __of_find_node_by_path(np, path);
796801
path = strchrnul(path, '/');
802+
if (separator && separator < path)
803+
break;
797804
}
798805
raw_spin_unlock_irqrestore(&devtree_lock, flags);
799806
return np;

0 commit comments

Comments
 (0)