Skip to contentSkip to conversation

of: find also nodes by mixture of alias and path

PATCH Superseded Jan Weitzel 2 participants 8 messages Dec 19, 2013 – Jan 10, 2014 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: find also nodes by mixture of alias and path

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +21 -1
index ea2d879..dc3d459 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *ret;
+	char *slash, *alias;
+	size_t len = 0;
+
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');
+
+	if (!slash)
 		return of_find_node_by_alias(root, str);
 
+	len = slash - str + 1;
+	alias = xmalloc(len);
+	strlcpy(alias, str, len);
+
+	ret = of_find_node_by_alias(root, alias);
+
+	if (!ret)
+		goto out;
+
+	ret = of_find_node_by_path_from(ret, slash);
+out:
+	free(alias);
+	return ret;
 }
 EXPORT_SYMBOL(of_find_node_by_path_or_alias);
 
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v2 1/1 of: find also nodes by mixture of alias and path

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node

 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +21 -1
index ea2d879..5b5272d 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	char *slash, *alias;
+	size_t len = 0;
+
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');
+
+	if (!slash)
 		return of_find_node_by_alias(root, str);
 
+	len = slash - str + 1;
+	alias = xmalloc(len);
+	strlcpy(alias, str, len);
+
+	node = of_find_node_by_alias(root, alias);
+
+	if (!node)
+		goto out;
+
+	node = of_find_node_by_path_from(node, slash);
+out:
+	free(alias);
+	return node;
 }
 EXPORT_SYMBOL(of_find_node_by_path_or_alias);
 
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Hi Jan,

Quoted 17 lines · Jan Weitzel

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node

 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +0 -0
index ea2d879..5b5272d 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)

drivers/of/base.c EXPORT_SYMBOL(of_find_node_by_path); · line 1388

Quoted 10 lines
drivers/of/base.c +6 -1
 {
+	struct device_node *node;
+	char *slash, *alias;
+	size_t len = 0;
+
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');

You should use regular strchr, not _strchr. Or is there any reason to do it differently here?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Am Montag, den 06.01.2014, 10:32 +0100 schrieb Sascha Hauer:

Quoted 25 lines

Hi Jan,

Quoted 22 lines · Jan Weitzel

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node

 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +4 -0
index ea2d879..5b5272d 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	char *slash, *alias;
+	size_t len = 0;
+
Quoted 8 lines

drivers/of/base.c EXPORT_SYMBOL(of_find_node_by_path); · line 1388

Quoted 5 lines
drivers/of/base.c +2 -1
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');

You should use regular strchr, not _strchr. Or is there any reason to do it differently here?

I got this from the strchr wrapper:

drivers/of/base.c: In function 'of_find_node_by_path_or_alias':
drivers/of/base.c:1388:8: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]

Is there a cleaner way?

Jan

Quoted 3 lines

Sascha

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
Quoted 34 lines · Jan Weitzel

Am Montag, den 06.01.2014, 10:32 +0100 schrieb Sascha Hauer:

Quoted 25 lines

Hi Jan,

Quoted 22 lines · Jan Weitzel

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node

 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +4 -0
index ea2d879..5b5272d 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	char *slash, *alias;
+	size_t len = 0;
+
Quoted 8 lines

drivers/of/base.c EXPORT_SYMBOL(of_find_node_by_path); · line 1388

Quoted 5 lines
drivers/of/base.c +2 -1
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');

You should use regular strchr, not _strchr. Or is there any reason to do it differently here?

Quoted 7 lines

I got this from the strchr wrapper:

drivers/of/base.c: In function 'of_find_node_by_path_or_alias':
drivers/of/base.c:1388:8: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]

Is there a cleaner way?

Try making 'slash' const.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v3 1/1 of: find also nodes by mixture of alias and path

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node
v3: use strchr

 drivers/of/base.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
drivers/of/base.c +22 -1
index ea2d879..6e5e7d6 100644
@@ -1378,11 +1378,32 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	const char *slash;
+	char *alias;
+	size_t len = 0;
+
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = strchr(str, '/');
+
+	if (!slash)
 		return of_find_node_by_alias(root, str);
 
+	len = slash - str + 1;
+	alias = xmalloc(len);
+	strlcpy(alias, str, len);
+
+	node = of_find_node_by_alias(root, alias);
+
+	if (!node)
+		goto out;
+
+	node = of_find_node_by_path_from(node, slash);
+out:
+	free(alias);
+	return node;
 }
 EXPORT_SYMBOL(of_find_node_by_path_or_alias);
 
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#6 lore raw
Quoted 4 lines · Jan Weitzel

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

Applied, thanks

Sascha

Quoted 53 lines

---
v2: rename ret to node
v3: use strchr

 drivers/of/base.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
drivers/of/base.c +22 -1
index ea2d879..6e5e7d6 100644
@@ -1378,11 +1378,32 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	const char *slash;
+	char *alias;
+	size_t len = 0;
+
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = strchr(str, '/');
+
+	if (!slash)
 		return of_find_node_by_alias(root, str);
 
+	len = slash - str + 1;
+	alias = xmalloc(len);
+	strlcpy(alias, str, len);
+
+	node = of_find_node_by_alias(root, alias);
+
+	if (!node)
+		goto out;
+
+	node = of_find_node_by_path_from(node, slash);
+out:
+	free(alias);
+	return node;
 }
 EXPORT_SYMBOL(of_find_node_by_path_or_alias);
 
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw
In reply to Sascha Hauer

Am Montag, den 06.01.2014, 11:50 +0100 schrieb Sascha Hauer:

Quoted 37 lines · Jan Weitzel
Quoted 36 lines

Am Montag, den 06.01.2014, 10:32 +0100 schrieb Sascha Hauer:

Quoted 25 lines

Hi Jan,

Quoted 22 lines · Jan Weitzel

Let of_find_node_by_path_or_alias also find a node starting with an alias followed by a path like "i2c0/tps@24"

---
v2: rename ret to node

 drivers/of/base.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
drivers/of/base.c +4 -0
index ea2d879..5b5272d 100644
@@ -1378,11 +1378,31 @@ EXPORT_SYMBOL(of_find_node_by_path);
 struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
 		const char *str)
 {
+	struct device_node *node;
+	char *slash, *alias;
+	size_t len = 0;
+
Quoted 8 lines

drivers/of/base.c EXPORT_SYMBOL(of_find_node_by_path); · line 1388

Quoted 5 lines
drivers/of/base.c +2 -1
 	if (*str ==  '/')
 		return of_find_node_by_path_from(root, str);
-	else
+
+	slash = _strchr(str, '/');

You should use regular strchr, not _strchr. Or is there any reason to do it differently here?

I got this from the strchr wrapper:

Quoted 7 lines
Quoted 5 lines

drivers/of/base.c: In function 'of_find_node_by_path_or_alias':
drivers/of/base.c:1388:8: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]

Is there a cleaner way?

Try making 'slash' const.

Arghh not *str ...
Thanks Jan

Quoted 3 lines

Sascha

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox