[POWERPC] bootwrapper: Refactor ft_get_prop() into internal and external functions.
The property searching part of ft_get_prop is factored out into an internal __ft_get_prop() which does not deal with phandles and does not copy the property data. ft_get_prop() is then a wrapper that does the phandle translation and copying. 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:
committed by
Paul Mackerras
parent
fc58341161
commit
c350038b2b
@@ -765,38 +765,53 @@ void *ft_get_parent(struct ft_cxt *cxt, const void *phandle)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
|
static const void *__ft_get_prop(struct ft_cxt *cxt, void *node,
|
||||||
void *buf, const unsigned int buflen)
|
const char *propname, unsigned int *len)
|
||||||
{
|
{
|
||||||
struct ft_atom atom;
|
struct ft_atom atom;
|
||||||
void *node;
|
int depth = 0;
|
||||||
char *p;
|
|
||||||
int depth;
|
|
||||||
unsigned int size;
|
|
||||||
|
|
||||||
node = ft_node_ph2node(cxt, phandle);
|
while ((node = ft_next(cxt, node, &atom)) != NULL) {
|
||||||
if (node == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
depth = 0;
|
|
||||||
p = (char *)node;
|
|
||||||
|
|
||||||
while ((p = ft_next(cxt, p, &atom)) != NULL) {
|
|
||||||
switch (atom.tag) {
|
switch (atom.tag) {
|
||||||
case OF_DT_BEGIN_NODE:
|
case OF_DT_BEGIN_NODE:
|
||||||
++depth;
|
++depth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OF_DT_PROP:
|
case OF_DT_PROP:
|
||||||
if ((depth != 1) || strcmp(atom.name, propname))
|
if (depth != 1 || strcmp(atom.name, propname))
|
||||||
break;
|
break;
|
||||||
size = min(atom.size, buflen);
|
|
||||||
memcpy(buf, atom.data, size);
|
if (len)
|
||||||
return atom.size;
|
*len = atom.size;
|
||||||
|
|
||||||
|
return atom.data;
|
||||||
|
|
||||||
case OF_DT_END_NODE:
|
case OF_DT_END_NODE:
|
||||||
if (--depth <= 0)
|
if (--depth <= 0)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
|
||||||
|
void *buf, const unsigned int buflen)
|
||||||
|
{
|
||||||
|
const void *data;
|
||||||
|
unsigned int size;
|
||||||
|
|
||||||
|
void *node = ft_node_ph2node(cxt, phandle);
|
||||||
|
if (!node)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
data = __ft_get_prop(cxt, node, propname, &size);
|
||||||
|
if (data) {
|
||||||
|
unsigned int clipped_size = min(size, buflen);
|
||||||
|
memcpy(buf, data, clipped_size);
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user