From: Andres Salomon <dilinger@queued.net>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Daniel Drake <dsd@laptop.org>,
linux-kernel@vger.kernel.org,
devicetree-discuss@lists.ozlabs.org,
"David S. Miller" <davem@davemloft.net>,
sparclinux@vger.kernel.org
Subject: [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v4)
Date: Wed, 23 Feb 2011 22:38:22 -0800 [thread overview]
Message-ID: <20110223223822.48718b63@queued.net> (raw)
In-Reply-To: <20110224053814.GA6046@angua.secretlab.ca>
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
Signed-off-by: Andres Salomon <dilinger@queued.net>
---
drivers/of/pdt.c | 50 ++++++++++++++++++++++----------------------------
1 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index 28295d0..61f6308 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -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;
}
--
1.7.2.3
next prev parent reply other threads:[~2011-02-24 6:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-23 23:03 [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
2011-02-23 23:28 ` Grant Likely
2011-02-24 0:16 ` Andres Salomon
2011-02-24 4:06 ` Grant Likely
2011-02-24 4:36 ` Andres Salomon
2011-02-24 5:38 ` Grant Likely
2011-02-24 6:38 ` Andres Salomon [this message]
2011-02-24 0:34 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Andres Salomon
2011-02-24 2:47 ` Grant Likely
2011-02-24 2:51 ` Andres Salomon
2011-02-24 3:25 ` Grant Likely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110223223822.48718b63@queued.net \
--to=dilinger@queued.net \
--cc=davem@davemloft.net \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=dsd@laptop.org \
--cc=grant.likely@secretlab.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox