Julius Werner has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/85988?usp=email )
Change subject: commonlib/device_tree: Initialize cells to default values on find() ......................................................................
commonlib/device_tree: Initialize cells to default values on find()
This patch wraps `dt_find_node()` in a function that initializes the addr_cells and size_cells values to the defaults provided in the FDT specification before potentially updating them from found values, so that we always return the correct result and remove the burden of correctly initializing them from the caller.
Change-Id: I39ba2c82d3a0d0b39a2ed5eba2420a04fbccb2f7 Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/device_tree.c 1 file changed, 31 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/88/85988/1
diff --git a/src/commonlib/device_tree.c b/src/commonlib/device_tree.c index c73e258..2ee0316 100644 --- a/src/commonlib/device_tree.c +++ b/src/commonlib/device_tree.c @@ -1039,23 +1039,9 @@ } }
-/* - * Find a node from a device tree path, relative to a parent node. - * - * @param parent The node from which to start the relative path lookup. - * @param path An array of path component strings that will be looked - * up in order to find the node. Must be terminated with - * a NULL pointer. Example: {'firmware', 'coreboot', NULL} - * @param addrcp Pointer that will be updated with any #address-cells - * value found in the path. May be NULL to ignore. - * @param sizecp Pointer that will be updated with any #size-cells - * value found in the path. May be NULL to ignore. - * @param create 1: Create node(s) if not found. 0: Return NULL instead. - * @return The found/created node, or NULL. - */ -struct device_tree_node *dt_find_node(struct device_tree_node *parent, - const char **path, u32 *addrcp, - u32 *sizecp, int create) +static struct device_tree_node *_dt_find_node(struct device_tree_node *parent, + const char **path, u32 *addrcp, + u32 *sizecp, int create) { struct device_tree_node *node, *found = NULL;
@@ -1091,6 +1077,34 @@ }
/* + * Find a node from a device tree path, relative to a parent node. + * + * @param parent The node from which to start the relative path lookup. + * @param path An array of path component strings that will be looked + * up in order to find the node. Must be terminated with + * a NULL pointer. Example: {'firmware', 'coreboot', NULL} + * @param addrcp Pointer that will be updated with any #address-cells + * value found in the path. May be NULL to ignore. + * @param sizecp Pointer that will be updated with any #size-cells + * value found in the path. May be NULL to ignore. + * @param create 1: Create node(s) if not found. 0: Return NULL instead. + * @return The found/created node, or NULL. + */ +struct device_tree_node *dt_find_node(struct device_tree_node *parent, + const char **path, u32 *addrcp, + u32 *sizecp, int create) +{ + /* Initialize cells to default values according to FDT spec. */ + if (addrcp) + *addrcp = 2; + + if (sizecp) + *sizecp = 1; + + return _dt_find_node(parent, path, addrcp, sizecp, create); +} + +/* * Find a node in the tree from a string device tree path. * * @param tree The device tree to search.