Skip to contentSkip to conversation

of/pdt: allow DT device matching by fixing 'name' brokenness (v2)

PATCH In review Andres Salomon 2 participants 11 messages Feb 23, 2011 – Feb 24, 2011 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/pdt: allow DT device matching by fixing 'name' brokenness (v2)

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Note that this affects sparc by reverting dp->name back to what sparc was originally doing (looking at the name property).

v2: combine two patches and revert of_pdt_node_name to original version.

---
 drivers/of/pdt.c |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)
drivers/of/pdt.c +15 -27
index 28295d0..a7aa85e 100644
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path; if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
 	return buf;
 }
 
@@ -187,7 +164,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
 	kref_init(&dp->kref);
 
-	dp->name = of_pdt_build_name(node);
+	dp->name = of_pdt_get_one_property(node, "name");
 	dp->type = of_pdt_get_one_property(node, "device_type");
 	dp->phandle = node;
 
@@ -198,11 +175,22 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 	return dp;
 }
 
-static char * __init of_pdt_build_full_name(struct device_node *dp)
+static char * __init of_pdt_build_full_name(struct device_node *dp,
+		phandle node)
 {
 	int len, ourlen, plen;
 	char *n;
 
+	/*
+	 * When fetching the full name we want the name we see with
+	 * package-to-path (ie, '/foo/bar/battery@0') rather than what
+	 * we see with the name property (ie, 'battery').
+	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older method for determining full name */
 	plen = strlen(dp->parent->full_name);
 	ourlen = strlen(of_pdt_node_name(dp));
 	len = ourlen + plen + 2;
@@ -243,7 +231,7 @@ static struct device_node * __init of_pdt_build_tree(struct device_node *parent,
 #if defined(CONFIG_SPARC)
 		dp->path_component_name = build_path_component(dp);
 #endif
-		dp->full_name = of_pdt_build_full_name(dp);
+		dp->full_name = of_pdt_build_full_name(dp, node);
 
 		dp->child = of_pdt_build_tree(dp,
 				of_pdt_prom_ops->getchild(node), nextp);
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 17 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Quoted 6 lines

Note that this affects sparc by reverting dp->name back to what sparc was originally doing (looking at the name property).

v2: combine two patches and revert of_pdt_node_name to original version.

Hi Andres, comments below.

g.

Quoted 37 lines
---
 drivers/of/pdt.c |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)
drivers/of/pdt.c +1 -17
index 28295d0..a7aa85e 100644
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path; if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */
-static char * __init of_pdt_build_name(phandle node)

drivers/of/pdt.c static char * __init of_pdt_try_pkg2path(phandle node) · line 152

Quoted 10 lines
drivers/of/pdt.c +0 -7
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
 	return buf;
 }
 

It seems to me that of_pdt_build_full_name will still be missing the '@<addr>' component on non-sparc non-olpc builds because it uses the broken of_pdt_node_name(). That needs to be fixed too, even if there are no current users (or removed).

Quoted 10 lines
drivers/of/pdt.c +1 -1
@@ -187,7 +164,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
 	kref_init(&dp->kref);
 
-	dp->name = of_pdt_build_name(node);
+	dp->name = of_pdt_get_one_property(node, "name");
 	dp->type = of_pdt_get_one_property(node, "device_type");
 	dp->phandle = node;
 

drivers/of/pdt.c static struct device_node * __init of_pdt_create_node(phandle node, · line 179

Quoted 6 lines
drivers/of/pdt.c +2 -1
@@ -198,11 +175,22 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 	return dp;
 }
 
-static char * __init of_pdt_build_full_name(struct device_node *dp)
+static char * __init of_pdt_build_full_name(struct device_node *dp,
+		phandle node)

Is dp->phandle not suitable here?

Quoted 18 lines
drivers/of/pdt.c +10 -0
 {
 	int len, ourlen, plen;
 	char *n;
 
+	/*
+	 * When fetching the full name we want the name we see with
+	 * package-to-path (ie, '/foo/bar/battery@0') rather than what
+	 * we see with the name property (ie, 'battery').
+	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older method for determining full name */
 	plen = strlen(dp->parent->full_name);
 	ourlen = strlen(of_pdt_node_name(dp));
 	len = ourlen + plen + 2;

drivers/of/pdt.c static struct device_node * __init of_pdt_build_tree(struct device_node *parent, · line 233

Quoted 3 lines
drivers/of/pdt.c +0 -0
@@ -243,7 +231,7 @@ static struct device_node * __init of_pdt_build_tree(struct device_node *parent,
 #if defined(CONFIG_SPARC)
 		dp->path_component_name = build_path_component(dp);
 #endif

I still think it would be useful to remove the #if defined(CONFIG_SPARC) from path_component_name, and it might be the best way to solve my comment about broken of_pdt_node_name above.

Quoted 8 lines
drivers/of/pdt.c +1 -1
-		dp->full_name = of_pdt_build_full_name(dp);
+		dp->full_name = of_pdt_build_full_name(dp, node);
 
 		dp->child = of_pdt_build_tree(dp,
 				of_pdt_prom_ops->getchild(node), nextp);
Signature · 1 line
1.7.2.3
#2 lore raw
Quoted 78 lines · On Wed, 23 Feb 2011 16:28:15 -0700 Grant Likely <[email protected]>…
Quoted 17 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Quoted 7 lines

Note that this affects sparc by reverting dp->name back to what sparc was originally doing (looking at the name property).

v2: combine two patches and revert of_pdt_node_name to original version.

Hi Andres, comments below.

g.

Quoted 48 lines
---
 drivers/of/pdt.c |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)
drivers/of/pdt.c +1 -1
index 28295d0..a7aa85e 100644
@@ -134,7 +134,7 @@ static char * __init
 of_pdt_get_one_property(phandle node, const char *name) 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init

of_pdt_try_pkg2path(phandle node) pr_err("%s: package-to-path failed\n", __func__); return NULL;

drivers/of/pdt.c +0 -4
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__,

buf);

drivers/of/pdt.c +0 -7
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path;

if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */

drivers/of/pdt.c +0 -8
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
Quoted 8 lines
Quoted 3 lines

return buf;
}

It seems to me that of_pdt_build_full_name will still be missing the '@<addr>' component on non-sparc non-olpc builds because it uses the broken of_pdt_node_name(). That needs to be fixed too, even if there are no current users (or removed).

The intent if for them to use the pkg2path hook. If
they can't use that, they'll need an architecture-specific way to figure out the @<addr> component. It may even be possible for sparc to use package-to-path; but either way, if an architecture doesn't have package-to-path (OLPC and powerpc have it; I don't know about sparc), and can't fake it, it'll need to do something special.

If the pkg2path hook isn't set and we're not sparc, we fall back to dp->name. That sucks, but I don't know of a better way to do things.

Quoted 38 lines
Quoted 11 lines
drivers/of/pdt.c +1 -1
@@ -187,7 +164,7 @@ static struct device_node * __init
 of_pdt_create_node(phandle node, 
 	kref_init(&dp->kref);
 
-	dp->name = of_pdt_build_name(node);
+	dp->name = of_pdt_get_one_property(node, "name");
 	dp->type = of_pdt_get_one_property(node, "device_type");
 	dp->phandle = node;
 

drivers/of/pdt.c static struct device_node * __init · line 179

Quoted 6 lines
drivers/of/pdt.c +2 -1
@@ -198,11 +175,22 @@ static struct device_node * __init
 of_pdt_create_node(phandle node, return dp;
 }
 
-static char * __init of_pdt_build_full_name(struct device_node *dp)
+static char * __init of_pdt_build_full_name(struct device_node *dp,
+		phandle node)

Is dp->phandle not suitable here?

Quoted 18 lines
drivers/of/pdt.c +3 -0
 {
 	int len, ourlen, plen;
 	char *n;
 
+	/*
+	 * When fetching the full name we want the name we see with
+	 * package-to-path (ie, '/foo/bar/battery@0') rather than

what

drivers/of/pdt.c +7 -0
+	 * we see with the name property (ie, 'battery').
+	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older method for determining full name */
 	plen = strlen(dp->parent->full_name);
 	ourlen = strlen(of_pdt_node_name(dp));
 	len = ourlen + plen + 2;
Quoted 9 lines
Quoted 4 lines
drivers/of/pdt.c +0 -0
@@ -243,7 +231,7 @@ static struct device_node * __init

of_pdt_build_tree(struct device_node *parent, #if
defined(CONFIG_SPARC) dp->path_component_name =
build_path_component(dp); #endif

I still think it would be useful to remove the #if defined(CONFIG_SPARC) from path_component_name, and it might be the best way to solve my comment about broken of_pdt_node_name above.

path_component_name is filled in by build_path_component() in sparc-land. It's very sparc-specific, and having path_component_name around doesn't help us on other architectures if we don't know how to fill it in.

Quoted 8 lines
Quoted 8 lines
drivers/of/pdt.c +1 -1
-		dp->full_name = of_pdt_build_full_name(dp);
+		dp->full_name = of_pdt_build_full_name(dp, node);
 
 		dp->child = of_pdt_build_tree(dp,
 				of_pdt_prom_ops->getchild(node),

nextp); --
1.7.2.3

#3 lore raw
Quoted 98 lines · Andres Salomon
Quoted 78 lines · On Wed, 23 Feb 2011 16:28:15 -0700 Grant Likely <[email protected]>…
Quoted 17 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Quoted 7 lines

Note that this affects sparc by reverting dp->name back to what sparc was originally doing (looking at the name property).

v2: combine two patches and revert of_pdt_node_name to original version.

Hi Andres, comments below.

g.

Quoted 48 lines
---
 drivers/of/pdt.c |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)
drivers/of/pdt.c +1 -1
index 28295d0..a7aa85e 100644
@@ -134,7 +134,7 @@ static char * __init
 of_pdt_get_one_property(phandle node, const char *name) 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init

of_pdt_try_pkg2path(phandle node) pr_err("%s: package-to-path failed\n", __func__); return NULL;

drivers/of/pdt.c +0 -4
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__,

buf);

drivers/of/pdt.c +0 -7
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path;

if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */

drivers/of/pdt.c +0 -8
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
Quoted 8 lines
Quoted 3 lines

return buf;
}

It seems to me that of_pdt_build_full_name will still be missing the '@<addr>' component on non-sparc non-olpc builds because it uses the broken of_pdt_node_name(). That needs to be fixed too, even if there are no current users (or removed).

The intent if for them to use the pkg2path hook. If
they can't use that, they'll need an architecture-specific way to figure out the @<addr> component. It may even be possible for sparc to use package-to-path; but either way, if an architecture doesn't have package-to-path (OLPC and powerpc have it; I don't know about sparc), and can't fake it, it'll need to do something special.

Quoted 2 lines

If the pkg2path hook isn't set and we're not sparc, we fall back to dp->name. That sucks, but I don't know of a better way to do things.

More that sucks, it is just plain *wrong*. :-)

so, to sum up, of_pdt_build_tree goes through the following process:

1) dp = of_pdt_create_node
- dp->name = of_pdt_get_one_property(node, "name"); /* name w/o addr */

2) (SPARC) dp->path_component_name = build_path_component(dp);
- format <node name>@<address>
- uses dp->name value
- not on OLPC

3) dp->full_name = of_pdt_build_full_name(dp)
- (SPARC) use dp->path_component_name
- (OLPC) depend on value from of_pdt_try_pkg2path(node);
- (others) fake it with an incorrect value?

Am I correct?

Faking it is clearly not acceptable. The solution is to *force* all platforms to implement a method for obtaining the full path. That means BUG() or WARN() if pkg2path is not populated, or if it returns NULL. It also means no mucking about with of_pdt_try_pkg2path(). Call ops->pkg2path directly and complain loudly when it does not work.

I see two choices:
1) implement ops->pkg2path for SPARC, but back it with build_path_component() instead of a call to OF
2) #ifdef of_pdt_build_full_name() to use the current behaviour for SPARC, but call pkg2path for everyone else.

Actually, I'd like to see build_path_component() refactored to return the full_name instead. It is trivial to get the path component from the full name at any time, but it is not trivial to go the other direction.... but that is probably more surgery than should be done in this immediate bug-fix. I'm assuming a fix is necessary before 2.6.38 is finalized?

g.

#4 lore raw
Quoted 109 lines · On Wed, 23 Feb 2011 21:06:38 -0700 Grant Likely…
Quoted 100 lines · Andres Salomon
Quoted 80 lines · On Wed, 23 Feb 2011 16:28:15 -0700 Grant Likely…
Quoted 18 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Quoted 7 lines

Note that this affects sparc by reverting dp->name back to what sparc was originally doing (looking at the name property).

v2: combine two patches and revert of_pdt_node_name to original version.

Hi Andres, comments below.

g.

Quoted 49 lines
---
 drivers/of/pdt.c |   42

+++++++++++++++--------------------------- 1 files changed, 15 insertions(+), 27 deletions(-)

drivers/of/pdt.c +1 -1
index 28295d0..a7aa85e 100644
@@ -134,7 +134,7 @@ static char * __init
 of_pdt_get_one_property(phandle node, const char *name) 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init

of_pdt_try_pkg2path(phandle node) pr_err("%s: package-to-path failed\n", __func__); return NULL;

drivers/of/pdt.c +0 -4
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__,

buf);

drivers/of/pdt.c +0 -7
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using

package-to-path; if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */

drivers/of/pdt.c +0 -8
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
Quoted 8 lines
Quoted 3 lines

return buf;
}

It seems to me that of_pdt_build_full_name will still be missing the '@<addr>' component on non-sparc non-olpc builds because it uses the broken of_pdt_node_name(). That needs to be fixed too, even if there are no current users (or removed).

The intent if for them to use the pkg2path hook. If
they can't use that, they'll need an architecture-specific way to figure out the @<addr> component. It may even be possible for sparc to use package-to-path; but either way, if an architecture doesn't have package-to-path (OLPC and powerpc have it; I don't know about sparc), and can't fake it, it'll need to do something special.

Quoted 3 lines

If the pkg2path hook isn't set and we're not sparc, we fall back to dp->name. That sucks, but I don't know of a better way to do things.

More that sucks, it is just plain *wrong*. :-)

so, to sum up, of_pdt_build_tree goes through the following process:

Quoted 8 lines

1) dp = of_pdt_create_node
- dp->name = of_pdt_get_one_property(node, "name"); /* name w/o
addr */

2) (SPARC) dp->path_component_name = build_path_component(dp);
- format <node name>@<address>
- uses dp->name value
- not on OLPC

Also:
- returns only the node name, not the full path
- implemented differently depending upon bus type (see pci_path_component/sbus_path_component/ebus_path_component/ambapp_path_component)
- sparc32 implemented differently versus sparc64

Quoted 7 lines

3) dp->full_name = of_pdt_build_full_name(dp)
- (SPARC) use dp->path_component_name
- (OLPC) depend on value from of_pdt_try_pkg2path(node);
- (others) fake it with an incorrect value?

Am I correct?

No.

(others) use of_pdt_try_pkg2path

The reason why we fall back to dp->name is because I don't know what other architectures out there might not have package-to-path. I'm perfectly fine with falling back to a WARN or BUG.

Quoted 7 lines

Faking it is clearly not acceptable. The solution is to *force* all platforms to implement a method for obtaining the full path. That means BUG() or WARN() if pkg2path is not populated, or if it returns NULL. It also means no mucking about with of_pdt_try_pkg2path(). Call ops->pkg2path directly and complain loudly when it does not work.

Quoted 5 lines

I see two choices:
1) implement ops->pkg2path for SPARC, but back it with build_path_component() instead of a call to OF
2) #ifdef of_pdt_build_full_name() to use the current behaviour for SPARC, but call pkg2path for everyone else.

Either of these are fine, but I don't think they should be within the scope of the proposed patch. I'd like to hear from Davem about whether #1 is doable. Also note that ops are different for sparc32 and sparc64.

Quoted 3 lines

Actually, I'd like to see build_path_component() refactored to return the full_name instead. It is trivial to get the path component from

Again, this is Davem-land; I don't have a sparc machine to test any of this with. The proposed patch is a bug fix that I'd like to see go in; I'm perfectly happy to refactor the APIs after that.

Quoted 4 lines

the full name at any time, but it is not trivial to go the other direction.... but that is probably more surgery than should be done in this immediate bug-fix. I'm assuming a fix is necessary before 2.6.38 is finalized?

Well, a fix only affects Daniel's work. It does, however, fix a bug in sparc code. I don't know if that breaks anything in practice.

#5 lore raw
Quoted 32 lines · Andres Salomon
Quoted 8 lines · On Wed, 23 Feb 2011 21:06:38 -0700 Grant Likely <[email protected]>…
Quoted 3 lines

If the pkg2path hook isn't set and we're not sparc, we fall back to dp->name. That sucks, but I don't know of a better way to do things.

More that sucks, it is just plain *wrong*. :-)

so, to sum up, of_pdt_build_tree goes through the following process:

Quoted 8 lines

1) dp = of_pdt_create_node
- dp->name = of_pdt_get_one_property(node, "name"); /* name w/o
addr */

2) (SPARC) dp->path_component_name = build_path_component(dp);
- format <node name>@<address>
- uses dp->name value
- not on OLPC

Also:
- returns only the node name, not the full path
- implemented differently depending upon bus type (see pci_path_component/sbus_path_component/ebus_path_component/ambapp_path_component)
- sparc32 implemented differently versus sparc64

Quoted 6 lines

3) dp->full_name = of_pdt_build_full_name(dp)
- (SPARC) use dp->path_component_name
- (OLPC) depend on value from of_pdt_try_pkg2path(node);
- (others) fake it with an incorrect value?

Quoted 5 lines
Quoted 1 line

Am I correct?

No.

(others) use of_pdt_try_pkg2path

Regardless, in all cases the semantics are absolutely clear; all platforms *must* have a reliable way of obtaining the full path and the path_component_name. It it doesn't then it is fundamentally broken.

Quoted 3 lines

The reason why we fall back to dp->name is because I don't know what other architectures out there might not have package-to-path. I'm perfectly fine with falling back to a WARN or BUG.

Respin to fallback on WARN() and bail out. I'd be okay with merging a patch that does that. Falling back to dp->name is absolutely incorrect.

I agree that API refinements can be deferred to 2.6.39.

g.

#6 lore raw

PATCH 1/1 of/pdt: allow DT device matching by fixing 'name' brokenness (v4)

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

v2: combine two patches and revert of_pdt_node_name to original version
v3: use dp->phandle instead of passing around node
v4: warn/bail out for non-sparc archs if pkg2path is not set

---
 drivers/of/pdt.c |   50 ++++++++++++++++++++++----------------------------
 1 files changed, 22 insertions(+), 28 deletions(-)
drivers/of/pdt.c +22 -28
index 28295d0..61f6308 100644
@@ -48,7 +48,9 @@ static inline void irq_trans_init(struct device_node *dp) { }
 
 static inline const char *of_pdt_node_name(struct device_node *dp)
 {
-	return dp->name;
+	/* non-sparc archs should be setting a pkg2path hook */
+	WARN_ON(1);
+	return NULL;
 }
 
 #endif /* !CONFIG_SPARC */
@@ -134,7 +136,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +149,6 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path; if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
 	return buf;
 }
 
@@ -187,7 +166,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
 	kref_init(&dp->kref);
 
-	dp->name = of_pdt_build_name(node);
+	dp->name = of_pdt_get_one_property(node, "name");
 	dp->type = of_pdt_get_one_property(node, "device_type");
 	dp->phandle = node;
 
@@ -201,10 +180,25 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 static char * __init of_pdt_build_full_name(struct device_node *dp)
 {
 	int len, ourlen, plen;
+	const char *name;
 	char *n;
 
+	/*
+	 * When fetching the full name we want the name we see with
+	 * package-to-path (ie, '/foo/bar/battery@0') rather than what
+	 * we see with the name property (ie, 'battery').
+	 */
+	n = of_pdt_try_pkg2path(dp->phandle);
+	if (n)
+		return n;
+
+	name = of_pdt_node_name(dp);
+	if (!name)
+		return NULL;
+
+	/* Older method for determining full name */
 	plen = strlen(dp->parent->full_name);
-	ourlen = strlen(of_pdt_node_name(dp));
+	ourlen = strlen(name);
 	len = ourlen + plen + 2;
 
 	n = prom_early_alloc(len);
@@ -213,7 +207,7 @@ static char * __init of_pdt_build_full_name(struct device_node *dp)
 		strcpy(n + plen, "/");
 		plen++;
 	}
-	strcpy(n + plen, of_pdt_node_name(dp));
+	strcpy(n + plen, name);
 
 	return n;
 }
Signature · 1 line
1.7.2.3
#7 lore raw

PATCH 1/1 of/pdt: allow DT device matching by fixing 'name' brokenness (v3)

In reply to Grant Likely

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

v2: combine two patches and revert of_pdt_node_name to original version
v3: use dp->phandle instead of passing around node

---
 drivers/of/pdt.c |   37 ++++++++++++-------------------------
 1 files changed, 12 insertions(+), 25 deletions(-)
drivers/of/pdt.c +12 -25
index 28295d0..c4cadeb 100644
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,29 +147,6 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
-}
-
-/*
- * When fetching the node's name, first try using package-to-path; if
- * that fails (either because the arch hasn't supplied a PROM callback,
- * or some other random failure), fall back to just looking at the node's
- * 'name' property.
- */
-static char * __init of_pdt_build_name(phandle node)
-{
-	char *buf;
-
-	buf = of_pdt_try_pkg2path(node);
-	if (!buf)
-		buf = of_pdt_get_one_property(node, "name");
-
 	return buf;
 }
 
@@ -187,7 +164,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
 	kref_init(&dp->kref);
 
-	dp->name = of_pdt_build_name(node);
+	dp->name = of_pdt_get_one_property(node, "name");
 	dp->type = of_pdt_get_one_property(node, "device_type");
 	dp->phandle = node;
 
@@ -203,6 +180,16 @@ static char * __init of_pdt_build_full_name(struct device_node *dp)
 	int len, ourlen, plen;
 	char *n;
 
+	/*
+	 * When fetching the full name we want the name we see with
+	 * package-to-path (ie, '/foo/bar/battery@0') rather than what
+	 * we see with the name property (ie, 'battery').
+	 */
+	n = of_pdt_try_pkg2path(dp->phandle);
+	if (n)
+		return n;
+
+	/* Older method for determining full name */
 	plen = strlen(dp->parent->full_name);
 	ourlen = strlen(of_pdt_node_name(dp));
 	len = ourlen + plen + 2;
Signature · 1 line
1.7.2.3
#8 lore raw

Re: [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3)

Quoted 17 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

Quoted 4 lines

v2: combine two patches and revert of_pdt_node_name to original version
v3: use dp->phandle instead of passing around node

This addresses one of my comments on v2; but it doesn't address the comment that the broken implementation of of_pdt_node_name for non-sparc still remains, or am I missing something?

g.

#9 lore raw

Re: [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3)

Quoted 21 lines · On Wed, 23 Feb 2011 19:47:08 -0700 Grant Likely <[email protected]>…
Quoted 20 lines · Andres Salomon

Commit e2f2a93b changed dp->name from using the 'name' property to using package-to-path. This fixed /proc/device-tree creation by eliminating conflicts between names (the 'name' property provides names like 'battery', whereas package-to-path provides names like '/foo/bar/battery@0', which we stripped to 'battery@0'). However, it also breaks of_device_id table matching.

The fix that we _really_ wanted was to keep dp->name based upon the name property ('battery'), but based dp->full_name upon package-to-path ('battery@0'). This patch does just that.

This also changes OLPC behavior to use the full result from package-to-path for full_name, rather than stripping the directory out. In practice, the strings end up being exactly the same; this change saves time, code, and memory.

v2: combine two patches and revert of_pdt_node_name to original version v3: use dp->phandle instead of passing around node

Quoted 8 lines
Quoted 1 line

This addresses one of my comments on v2; but it doesn't address the comment that the broken implementation of of_pdt_node_name for non-sparc still remains, or am I missing something?

g.

I responded to that -
http://www.spinics.net/lists/sparclinux/msg08058.html

#10 lore raw

Re: [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3)

Quoted 6 lines · Andres Salomon
Quoted 4 lines · On Wed, 23 Feb 2011 19:47:08 -0700 Grant Likely <[email protected]>…

This addresses one of my comments on v2; but it doesn't address the comment that the broken implementation of of_pdt_node_name for non-sparc still remains, or am I missing something?

Quoted 6 lines
Quoted 2 lines

g.

I responded to that -
http://www.spinics.net/lists/sparclinux/msg08058.html

Weird; that reply didn't show up in my inbox (but my mailer did receive it, so it is definitely a problem on my end). I'll reply now...

g.