]> git.sur5r.net Git - u-boot/blobdiff - libfdt/fdt_ro.c
Merge branch 'master' of git://git.denx.de/u-boot-ppc4xx
[u-boot] / libfdt / fdt_ro.c
index f559eeda06a9b600dfb7281e2f22c784e3b8fb95..fdc9c29d2f1be93bda4de8679ab04f73d9ac4074 100644 (file)
@@ -112,12 +112,12 @@ int fdt_num_mem_rsv(const void *fdt)
 int fdt_subnode_offset_namelen(const void *fdt, int offset,
                               const char *name, int namelen)
 {
-       int depth;
+       int depth = 0;
 
        FDT_CHECK_HEADER(fdt);
 
-       for (depth = 0;
-            offset >= 0;
+       for (depth = 0, offset = fdt_next_node(fdt, offset, &depth);
+            (offset >= 0) && (depth > 0);
             offset = fdt_next_node(fdt, offset, &depth)) {
                if (depth < 0)
                        return -FDT_ERR_NOTFOUND;
@@ -126,7 +126,10 @@ int fdt_subnode_offset_namelen(const void *fdt, int offset,
                        return offset;
        }
 
-       return offset; /* error */
+       if (offset < 0)
+               return offset; /* error */
+       else
+               return -FDT_ERR_NOTFOUND;
 }
 
 int fdt_subnode_offset(const void *fdt, int parentoffset,
@@ -145,17 +148,12 @@ int fdt_path_offset(const void *fdt, const char *path)
 
        /* see if we have an alias */
        if (*path != '/') {
-               const char *q;
-               int aliasoffset = fdt_path_offset(fdt, "/aliases");
+               const char *q = strchr(path, '/');
 
-               if (aliasoffset < 0)
-                       return -FDT_ERR_BADPATH;
-
-               q = strchr(path, '/');
                if (!q)
                        q = end;
 
-               p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
+               p = fdt_get_alias_namelen(fdt, p, q - p);
                if (!p)
                        return -FDT_ERR_BADPATH;
                offset = fdt_path_offset(fdt, p);
@@ -306,6 +304,23 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
        return fdt32_to_cpu(*php);
 }
 
+const char *fdt_get_alias_namelen(const void *fdt,
+                                 const char *name, int namelen)
+{
+       int aliasoffset;
+
+       aliasoffset = fdt_path_offset(fdt, "/aliases");
+       if (aliasoffset < 0)
+               return NULL;
+
+       return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
+}
+
+const char *fdt_get_alias(const void *fdt, const char *name)
+{
+       return fdt_get_alias_namelen(fdt, name, strlen(name));
+}
+
 int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
 {
        int pdepth = 0, p = 0;