* [PATCH] libfdt: Add support for using aliases in fdt_path_offset()
@ 2008-08-14 3:52 Kumar Gala
2008-08-14 4:15 ` David Gibson
0 siblings, 1 reply; 3+ messages in thread
From: Kumar Gala @ 2008-08-14 3:52 UTC (permalink / raw)
To: devicetree-discuss; +Cc: linuxppc-dev, Jon Loeliger, David Gibson
If the path doesn't start with '/' check to see if it matches some alias
under "/aliases" and substitute the matching alias value in the path
and retry the lookup.
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
libfdt/fdt_ro.c | 25 +++++++++++++++++++++++--
1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index ebd1260..74b8153 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -139,8 +139,29 @@ int fdt_path_offset(const void *fdt, const char *path)
FDT_CHECK_HEADER(fdt);
- if (*path != '/')
- return -FDT_ERR_BADPATH;
+ /* see if we have an alias */
+ if (*path != '/') {
+ const char *q;
+ int aliasoffset = fdt_path_offset(fdt, "/aliases");
+
+ if (aliasoffset < 0)
+ return -FDT_ERR_BADPATH;
+
+ q = strchr(path, '/');
+ if (!q)
+ q = end;
+
+ p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
+ if (!p)
+ return -FDT_ERR_BADPATH;
+
+ aliasoffset = fdt_path_offset(fdt, p);
+ if (*q == '\0')
+ return aliasoffset;
+
+ q++;
+ return fdt_subnode_offset(fdt, aliasoffset, q);
+ }
while (*p) {
const char *q;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libfdt: Add support for using aliases in fdt_path_offset()
2008-08-14 3:52 [PATCH] libfdt: Add support for using aliases in fdt_path_offset() Kumar Gala
@ 2008-08-14 4:15 ` David Gibson
2008-08-14 12:02 ` Kumar Gala
0 siblings, 1 reply; 3+ messages in thread
From: David Gibson @ 2008-08-14 4:15 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Jon Loeliger, devicetree-discuss
On Wed, Aug 13, 2008 at 10:52:26PM -0500, Kumar Gala wrote:
> If the path doesn't start with '/' check to see if it matches some alias
> under "/aliases" and substitute the matching alias value in the path
> and retry the lookup.
Kumar, this is broken. If you match an alias you only follow the path
one level down from there. i.e. you will correctly resolve
'somealias' and 'somealias/foo', but not 'somealias/foo/bar'.
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index ebd1260..74b8153 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -139,8 +139,29 @@ int fdt_path_offset(const void *fdt, const char *path)
>
> FDT_CHECK_HEADER(fdt);
>
> - if (*path != '/')
> - return -FDT_ERR_BADPATH;
> + /* see if we have an alias */
> + if (*path != '/') {
> + const char *q;
> + int aliasoffset = fdt_path_offset(fdt, "/aliases");
> +
> + if (aliasoffset < 0)
> + return -FDT_ERR_BADPATH;
> +
> + q = strchr(path, '/');
> + if (!q)
> + q = end;
> +
> + p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
> + if (!p)
> + return -FDT_ERR_BADPATH;
> +
> + aliasoffset = fdt_path_offset(fdt, p);
You should set 'offset' here instead of 'aliasoffset'..
> + if (*q == '\0')
> + return aliasoffset;
> +
> + q++;
> + return fdt_subnode_offset(fdt, aliasoffset, q);
> + }
..drop the rest of this if block..
>
> while (*p) {
> const char *q;
..and then the loop that's already here will follow the remaining path
components starting from the node that's the target of the alias.
Plus you need a testcase or three.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libfdt: Add support for using aliases in fdt_path_offset()
2008-08-14 4:15 ` David Gibson
@ 2008-08-14 12:02 ` Kumar Gala
0 siblings, 0 replies; 3+ messages in thread
From: Kumar Gala @ 2008-08-14 12:02 UTC (permalink / raw)
To: David Gibson; +Cc: linuxppc-dev, Jon Loeliger, devicetree-discuss
On Aug 13, 2008, at 11:15 PM, David Gibson wrote:
> On Wed, Aug 13, 2008 at 10:52:26PM -0500, Kumar Gala wrote:
>> If the path doesn't start with '/' check to see if it matches some
>> alias
>> under "/aliases" and substitute the matching alias value in the path
>> and retry the lookup.
>
> Kumar, this is broken. If you match an alias you only follow the path
> one level down from there. i.e. you will correctly resolve
> 'somealias' and 'somealias/foo', but not 'somealias/foo/bar'.
I'm not clear on what cases you are suggesting fail.
- k
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-08-14 12:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-14 3:52 [PATCH] libfdt: Add support for using aliases in fdt_path_offset() Kumar Gala
2008-08-14 4:15 ` David Gibson
2008-08-14 12:02 ` Kumar Gala
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox