[POWERPC] bootwrapper: Make ft_get_parent() return a phandle, and NULL if already top-level.

Most of ft_get_parent() is factored out into __ft_get_parent(), which
deals only in internal node pointers.  The ft_get_parent() wrapper
handles phandle conversion in both directions (previously,
ft_get_parent() did not convert its return value).

It also now returns NULL as the parent of the toplevel node, rather than
just returning the toplevel node again (which made it rather useless in
loops).

Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
Scott Wood 2007-03-12 14:41:56 -06:00 коммит произвёл Paul Mackerras
Родитель c350038b2b
Коммит a9ec7669fc
2 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -728,20 +728,15 @@ void *ft_find_descendent(struct ft_cxt *cxt, void *top, const char *srch_path)
return NULL; return NULL;
} }
void *ft_get_parent(struct ft_cxt *cxt, const void *phandle) void *__ft_get_parent(struct ft_cxt *cxt, void *node)
{ {
void *node;
int d; int d;
struct ft_atom atom; struct ft_atom atom;
char *p; char *p;
node = ft_node_ph2node(cxt, phandle);
if (node == NULL)
return NULL;
for (d = 0; cxt->genealogy[d] != NULL; ++d) for (d = 0; cxt->genealogy[d] != NULL; ++d)
if (cxt->genealogy[d] == node) if (cxt->genealogy[d] == node)
return cxt->genealogy[d > 0 ? d - 1 : 0]; return d > 0 ? cxt->genealogy[d - 1] : NULL;
/* have to do it the hard way... */ /* have to do it the hard way... */
p = ft_root_node(cxt); p = ft_root_node(cxt);
@ -753,7 +748,7 @@ void *ft_get_parent(struct ft_cxt *cxt, const void *phandle)
if (node == atom.data) { if (node == atom.data) {
/* found it */ /* found it */
cxt->genealogy[d + 1] = NULL; cxt->genealogy[d + 1] = NULL;
return d > 0 ? cxt->genealogy[d - 1] : node; return d > 0 ? cxt->genealogy[d - 1] : NULL;
} }
++d; ++d;
break; break;
@ -765,6 +760,16 @@ void *ft_get_parent(struct ft_cxt *cxt, const void *phandle)
return NULL; return NULL;
} }
void *ft_get_parent(struct ft_cxt *cxt, const void *phandle)
{
void *node = ft_node_ph2node(cxt, phandle);
if (node == NULL)
return NULL;
node = __ft_get_parent(cxt, node);
return ft_get_phandle(cxt, node);
}
static const void *__ft_get_prop(struct ft_cxt *cxt, void *node, static const void *__ft_get_prop(struct ft_cxt *cxt, void *node,
const char *propname, unsigned int *len) const char *propname, unsigned int *len)
{ {

Просмотреть файл

@ -104,5 +104,6 @@ int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
void *buf, const unsigned int buflen); void *buf, const unsigned int buflen);
int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname, int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
const void *buf, const unsigned int buflen); const void *buf, const unsigned int buflen);
void *ft_get_parent(struct ft_cxt *cxt, const void *phandle);
#endif /* FLATDEVTREE_H */ #endif /* FLATDEVTREE_H */