Skip to content

Commit

Permalink
of: fix handling of '/' in options for of_find_node_by_path()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Leif Lindholm <[email protected]>
Cc: <[email protected]> # 3.19
Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
Leif Lindholm authored and robherring committed Mar 10, 2015
1 parent 649022e commit 106937e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 106937e

Please sign in to comment.