Commit 106937e8 authored by Leif Lindholm's avatar Leif Lindholm Committed by Rob Herring

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: 7914a7c5 ("of: support passing console options with stdout-path")
Reported-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarLeif Lindholm <leif.lindholm@linaro.org>
Cc: <stable@vger.kernel.org> # 3.19
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent 649022e0
...@@ -714,16 +714,17 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, ...@@ -714,16 +714,17 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent,
const char *path) const char *path)
{ {
struct device_node *child; struct device_node *child;
int len = strchrnul(path, '/') - path; int len;
int term; const char *end;
end = strchr(path, ':');
if (!end)
end = strchrnul(path, '/');
len = end - path;
if (!len) if (!len)
return NULL; return NULL;
term = strchrnul(path, ':') - path;
if (term < len)
len = term;
__for_each_child_of_node(parent, child) { __for_each_child_of_node(parent, child) {
const char *name = strrchr(child->full_name, '/'); const char *name = strrchr(child->full_name, '/');
if (WARN(!name, "malformed device_node %s\n", 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 ...@@ -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 */ /* The path could begin with an alias */
if (*path != '/') { if (*path != '/') {
char *p = strchrnul(path, '/'); int len;
int len = separator ? separator - path : p - path; const char *p = separator;
if (!p)
p = strchrnul(path, '/');
len = p - path;
/* of_aliases must not be NULL */ /* of_aliases must not be NULL */
if (!of_aliases) if (!of_aliases)
...@@ -794,6 +799,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt ...@@ -794,6 +799,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
path++; /* Increment past '/' delimiter */ path++; /* Increment past '/' delimiter */
np = __of_find_node_by_path(np, path); np = __of_find_node_by_path(np, path);
path = strchrnul(path, '/'); path = strchrnul(path, '/');
if (separator && separator < path)
break;
} }
raw_spin_unlock_irqrestore(&devtree_lock, flags); raw_spin_unlock_irqrestore(&devtree_lock, flags);
return np; return np;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment