69,7 → 69,8 |
* |
* Transfer entire information from the OpenFirmware device tree 'current' node to |
* its memory representation in 'current_node'. This function recursively processes |
* all node's peers and children. |
* all node's children. Node's peers are processed iteratively in order to prevent |
* stack from overflowing. |
* |
* @param current_node Pointer to uninitialized ofw_tree_node structure that will |
* become the memory represenation of 'current'. |
83,10 → 84,10 |
static char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
phandle peer; |
phandle child; |
unsigned properties = 0; |
size_t len; |
int i; |
|
while (current_node) { |
/* |
* Initialize node. |
*/ |
111,7 → 112,9 |
i++; /* do not include '/' */ |
|
len -= i; |
current_node->da_name = ofw_tree_space_alloc(len + 1); /* add space for trailing '\0' */ |
|
/* add space for trailing '\0' */ |
current_node->da_name = ofw_tree_space_alloc(len + 1); |
if (!current_node->da_name) |
return; |
|
118,20 → 121,7 |
memcpy(current_node->da_name, &path[i], len); |
current_node->da_name[len] = '\0'; |
|
/* |
* Recursively process the potential peer node. |
*/ |
peer = ofw_get_peer_node(current); |
if (peer != 0 && peer != -1) { |
ofw_tree_node_t *peer_node; |
|
peer_node = ofw_tree_node_alloc(); |
if (peer_node) { |
ofw_tree_node_process(peer_node, parent_node, peer); |
current_node->peer = peer_node; |
} |
} |
|
/* |
* Recursively process the potential child node. |
*/ |
170,7 → 160,8 |
if (i == current_node->properties) |
break; |
|
memcpy(current_node->property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN); |
memcpy(current_node->property[i].name, name, |
OFW_TREE_PROPERTY_MAX_NAMELEN); |
current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0'; |
|
size = ofw_get_proplen(current, name); |
191,7 → 182,35 |
} |
|
current_node->properties = i; /* Just in case we ran out of memory. */ |
|
/* |
* Iteratively process the next peer node. |
* Note that recursion is a bad idea here. |
* Due to the topology of the OpenFirmware device tree, |
* the nesting of peer nodes could be to wide and the |
* risk of overflowing the stack is too real. |
*/ |
peer = ofw_get_peer_node(current); |
if (peer != 0 && peer != -1) { |
ofw_tree_node_t *peer_node; |
|
peer_node = ofw_tree_node_alloc(); |
if (peer_node) { |
current_node->peer = peer_node; |
current_node = peer_node; |
current = peer; |
/* |
* Process the peer in next iteration. |
*/ |
continue; |
} |
} |
/* |
* No more peers on this level. |
*/ |
break; |
} |
} |
|
/** Construct memory representation of OpenFirmware device tree. |
* |