[POWERPC] bootwrapper: Preserve the pp pointer in ft_make_space() when calling ft_reo...
[powerpc.git] / arch / powerpc / boot / flatdevtree.c
index c76c194..0fa4f98 100644 (file)
 
 #define _ALIGN(x, al)  (((x) + (al) - 1) & ~((al) - 1))
 
+static char *ft_root_node(struct ft_cxt *cxt)
+{
+       return cxt->rgn[FT_STRUCT].start;
+}
+
 /* Routines for keeping node ptrs returned by ft_find_device current */
 /* First entry not used b/c it would return 0 and be taken as NULL/error */
-static void *ft_node_add(struct ft_cxt *cxt, char *node)
+static void *ft_get_phandle(struct ft_cxt *cxt, char *node)
 {
        unsigned int i;
 
+       if (!node)
+               return NULL;
+
        for (i = 1; i < cxt->nodes_used; i++)   /* already there? */
                if (cxt->node_tbl[i] == node)
                        return (void *)i;
@@ -253,8 +261,14 @@ static int ft_make_space(struct ft_cxt *cxt, char **pp, enum ft_rgn_id rgn,
        char *str, *next;
        enum ft_rgn_id r;
 
-       if (!cxt->isordered && !ft_reorder(cxt, nextra))
-               return 0;
+       if (!cxt->isordered) {
+               unsigned long rgn_off = *pp - cxt->rgn[rgn].start;
+
+               if (!ft_reorder(cxt, nextra))
+                       return 0;
+
+               *pp = cxt->rgn[rgn].start + rgn_off;
+       }
        if (ft_shuffle(cxt, pp, rgn, nextra))
                return 1;
 
@@ -590,7 +604,7 @@ int ft_add_rsvmap(struct ft_cxt *cxt, u64 physaddr, u64 size)
 
 void ft_begin_tree(struct ft_cxt *cxt)
 {
-       cxt->p = cxt->rgn[FT_STRUCT].start;
+       cxt->p = ft_root_node(cxt);
 }
 
 void ft_end_tree(struct ft_cxt *cxt)
@@ -636,8 +650,8 @@ void *ft_find_device(struct ft_cxt *cxt, const char *srch_path)
        /* require absolute path */
        if (srch_path[0] != '/')
                return NULL;
-       node = ft_find_descendent(cxt, cxt->rgn[FT_STRUCT].start, srch_path);
-       return ft_node_add(cxt, node);
+       node = ft_find_descendent(cxt, ft_root_node(cxt), srch_path);
+       return ft_get_phandle(cxt, node);
 }
 
 void *ft_find_descendent(struct ft_cxt *cxt, void *top, const char *srch_path)
@@ -717,7 +731,7 @@ void *ft_get_parent(struct ft_cxt *cxt, const void *phandle)
                        return cxt->genealogy[d > 0 ? d - 1 : 0];
 
        /* have to do it the hard way... */
-       p = cxt->rgn[FT_STRUCT].start;
+       p = ft_root_node(cxt);
        d = 0;
        while ((p = ft_next(cxt, p, &atom)) != NULL) {
                switch (atom.tag) {
@@ -855,7 +869,7 @@ void *ft_create_node(struct ft_cxt *cxt, const void *parent, const char *path)
        char *p, *next;
        int depth = 0;
 
-       p = cxt->rgn[FT_STRUCT].start;
+       p = ft_root_node(cxt);
        while ((next = ft_next(cxt, p, &atom)) != NULL) {
                switch (atom.tag) {
                case OF_DT_BEGIN_NODE: