lkml.org 
[lkml]   [2014]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] of: Make of_find_node_by_path() handle /aliases
On Tue, Mar 18, 2014 at 9:52 PM, Pantelis Antoniou
<pantelis.antoniou@konsulko.com> wrote:
> Make of_find_node_by_path() handle aliases as prefixes.
>
> Originally by David Daney <ddaney@caviumnetworks.com>, but
> reworked according to remark by Grant Likely.
>
> Handles all cases without allocating memory as requested by
> Grant Likely <grant.likely@linaro.org>
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>

I posted a patch that does the same thing with a different method just
a few days ago:

http://www.spinics.net/lists/devicetree/msg26336.html

The above patch also has the advantage of being a more efficient search.

g.

> ---
> drivers/of/base.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 65 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 7083fad..19bcdb4 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -773,22 +773,83 @@ EXPORT_SYMBOL(of_get_child_by_name);
> /**
> * of_find_node_by_path - Find a node matching a full OF path
> * @path: The full path to match
> + * @path: Either the full path to match, or if the path does not
> + * start with '/', the name of a property of the /aliases
> + * node (an alias). In the case of an alias, the node
> + * matching the alias' value will be returned.
> + *
> + * Valid paths:
> + * /foo/bar Full path
> + * foo Valid alias
> + * foo/bar Valid alias + relative path
> *
> * Returns a node pointer with refcount incremented, use
> * of_node_put() on it when done.
> */
> struct device_node *of_find_node_by_path(const char *path)
> {
> - struct device_node *np = of_allnodes;
> + struct device_node *np = NULL;
> + int len;
> + const char *p = NULL;
> + struct property *prop;
> unsigned long flags;
>
> + /* under lock (not very nice) */
> raw_spin_lock_irqsave(&devtree_lock, flags);
> - for (; np; np = np->allnext) {
> - if (np->full_name && (of_node_cmp(np->full_name, path) == 0)
> - && of_node_get(np))
> +
> + len = strlen(path);
> +
> + /* path begins with an alias */
> + if (path[0] != '/') {
> +
> + /* now find the relative path (if any)*/
> + p = strchr(path, '/');
> + if (p != NULL)
> + len = p - path;
> +
> + /* of_aliases must not be NULL */
> + if (!of_aliases)
> + goto out;
> +
> + /* find matching alias */
> + for_each_property_of_node(of_aliases, prop)
> + if (strlen(prop->name) == len &&
> + strncmp(prop->name, path, len) == 0)
> + break;
> +
> + /* not found; bail */
> + if (prop == NULL)
> + goto out;
> +
> + path = prop->value;
> + }
> +
> + /* path lookup */
> + for_each_of_allnodes(np) {
> +
> + if (!np->full_name)
> + continue;
> +
> + if (p == NULL) {
> + /* full component */
> + if (strcasecmp(np->full_name, path) != 0)
> + continue;
> + } else {
> + /* last component (including '/') */
> + if (strncasecmp(np->full_name, path, len) != 0)
> + continue;
> +
> + if (strcasecmp(np->full_name + len, p) != 0)
> + continue;
> + }
> +
> + if (of_node_get(np))
> break;
> }
> +
> +out:
> raw_spin_unlock_irqrestore(&devtree_lock, flags);
> +
> return np;
> }
> EXPORT_SYMBOL(of_find_node_by_path);
> --
> 1.7.12
>


\
 
 \ /
  Last update: 2014-03-19 22:41    [W:0.046 / U:13.320 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site