* [PATCH] of: Make of_find_node_by_path() handle /aliases
@ 2014-03-18 21:52 Pantelis Antoniou
[not found] ` <1395179549-31345-1-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2014-03-19 21:00 ` Grant Likely
0 siblings, 2 replies; 3+ messages in thread
From: Pantelis Antoniou @ 2014-03-18 21:52 UTC (permalink / raw)
To: Grant Likely
Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi,
Alison Chaiken, Dinh Nguyen, Jan Lubbe, Alexander Sverdlin,
Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull,
Sascha Hauer, Michael Bohan, Ionut Nicu, Michal Simek,
Matt Ranostay, devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete Popov, Dan Malek,
Georgi Vlaev, Pantelis Antoniou
Make of_find_node_by_path() handle aliases as prefixes.
Originally by David Daney <ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>, but
reworked according to remark by Grant Likely.
Handles all cases without allocating memory as requested by
Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
---
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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] of: Make of_find_node_by_path() handle /aliases
[not found] ` <1395179549-31345-1-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
@ 2014-03-19 19:28 ` Stephen Warren
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Warren @ 2014-03-19 19:28 UTC (permalink / raw)
To: Pantelis Antoniou, Grant Likely
Cc: Rob Herring, Matt Porter, Koen Kooi, Alison Chaiken, Dinh Nguyen,
Jan Lubbe, Alexander Sverdlin, Michael Stickel, Guenter Roeck,
Dirk Behme, Alan Tull, Sascha Hauer, Michael Bohan, Ionut Nicu,
Michal Simek, Matt Ranostay, devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Pete Popov, Dan Malek,
Georgi Vlaev
On 03/18/2014 03:52 PM, Pantelis Antoniou wrote:
> Make of_find_node_by_path() handle aliases as prefixes.
>
> Originally by David Daney <ddaney-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org>, but
> reworked according to remark by Grant Likely.
>
> Handles all cases without allocating memory as requested by
> Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Why not just introduce a new function of_find_node_by_alias()? A single
unified function would make sense if the function did something like:
(1) find my path, and return if found (2) if not found, fall back to
searching /aliases. However, since this modified function takes 2
separate formats of input path based on whether it should search for an
alias or not, it seems like 2 separate functions would be a better API.
Perhaps the new API should simply be a wrapper around
of_find_node_by_path, once the alias has been found?
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] of: Make of_find_node_by_path() handle /aliases
2014-03-18 21:52 [PATCH] of: Make of_find_node_by_path() handle /aliases Pantelis Antoniou
[not found] ` <1395179549-31345-1-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
@ 2014-03-19 21:00 ` Grant Likely
1 sibling, 0 replies; 3+ messages in thread
From: Grant Likely @ 2014-03-19 21:00 UTC (permalink / raw)
To: Pantelis Antoniou
Cc: Rob Herring, Stephen Warren, Matt Porter, Koen Kooi,
Alison Chaiken, Dinh Nguyen, Jan Lubbe, Alexander Sverdlin,
Michael Stickel, Guenter Roeck, Dirk Behme, Alan Tull,
Sascha Hauer, Michael Bohan, Ionut Nicu, Michal Simek,
Matt Ranostay, devicetree@vger.kernel.org,
Linux Kernel Mailing List, Pete Popov, Dan Malek, Georgi Vlaev
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-19 21:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18 21:52 [PATCH] of: Make of_find_node_by_path() handle /aliases Pantelis Antoniou
[not found] ` <1395179549-31345-1-git-send-email-pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2014-03-19 19:28 ` Stephen Warren
2014-03-19 21:00 ` Grant Likely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).