Elyes Haouas has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/84911?usp=email )
Change subject: commonlib/device_tree: Use boolean instead of int ......................................................................
commonlib/device_tree: Use boolean instead of int
Moderne C provides boolean, use it instead of old style 0, -1.
Change-Id: Icf938c24d067c9d15faf45b6072e150f0aedfe08 Signed-off-by: Elyes Haouas ehaouas@noos.fr --- M src/commonlib/device_tree.c M src/commonlib/include/commonlib/device_tree.h 2 files changed, 43 insertions(+), 43 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/11/84911/1
diff --git a/src/commonlib/device_tree.c b/src/commonlib/device_tree.c index cb7a596..49c6dee 100644 --- a/src/commonlib/device_tree.c +++ b/src/commonlib/device_tree.c @@ -1679,9 +1679,9 @@ * @param node Root node of the /__local_fixup__ subtree. * @param base Adjustment that was added to phandles in the overlay. * - * @return 0 on success, -1 on error. + * @return true on success, false on error. */ -static int dt_fixup_locals(struct device_tree_node *node, +static bool dt_fixup_locals(struct device_tree_node *node, struct device_tree_node *fixup, uint32_t base) { struct device_tree_property *prop; @@ -1708,12 +1708,12 @@ /* We should always find a corresponding base prop for a fixup, and fixup props contain a list of 32-bit fixup offsets. */ if (!base_prop || fixup_prop->prop.size % sizeof(uint32_t)) - return -1; + return false;
for (i = 0; i < fixup_prop->prop.size; i += sizeof(uint32_t)) if (!dt_adjust_phandle(base_prop, base, be32dec( fixup_prop->prop.data + i))) - return -1; + return false; }
/* Now recursively descend both the base tree and the /__local_fixups__ @@ -1728,13 +1728,13 @@
/* All fixup nodes should have a corresponding base node. */ if (!base_child) - return -1; + return false;
- if (dt_fixup_locals(base_child, fixup_child, base) < 0) - return -1; + if (!dt_fixup_locals(base_child, fixup_child, base)) + return false; }
- return 0; + return true; }
/* @@ -1778,9 +1778,9 @@ * @params base_path Path to the base DT node that the fixup points to. * @params overlay_symbols /__symbols__ node of the overlay. * - * @return 0 on success, -1 on error. + * @return true on success, false on error. */ -static int dt_fixup_external(struct device_tree *overlay, +static bool dt_fixup_external(struct device_tree *overlay, struct device_tree_property *fixup, uint32_t phandle, const char *base_path, struct device_tree_node *overlay_symbols) @@ -1794,19 +1794,19 @@ char *node_path = entry; entry = strchr(node_path, ':'); if (!entry) - return -1; + return false; *entry++ = '\0';
char *prop_name = entry; entry = strchr(prop_name, ':'); if (!entry) - return -1; + return false; *entry++ = '\0';
struct device_tree_node *ovl_node = dt_find_node_by_path( overlay, node_path, NULL, NULL, 0); if (!ovl_node || !isdigit(*entry)) - return -1; + return false;
struct device_tree_property *ovl_prop = NULL; list_for_each(prop, ovl_node->properties, list_node) @@ -1818,7 +1818,7 @@ /* Move entry to first char after number, must be a '\0'. */ uint32_t offset = skip_atoi(&entry); if (!ovl_prop || offset + 4 > ovl_prop->prop.size || entry[0]) - return -1; + return false; entry++; /* jump over '\0' to potential next fixup */
be32enc(ovl_prop->prop.data + offset, phandle); @@ -1830,7 +1830,7 @@ dt_fix_symbols(overlay_symbols, ovl_node, base_path); }
- return 0; + return true; }
/* @@ -1843,9 +1843,9 @@ * @params fixups /__fixup__ node in the overlay. * @params overlay_symbols /__symbols__ node of the overlay. * - * @return 0 on success, -1 on error. + * @return true on success, false on error. */ -static int dt_fixup_all_externals(struct device_tree *tree, +static bool dt_fixup_all_externals(struct device_tree *tree, struct device_tree_node *symbols, struct device_tree *overlay, struct device_tree_node *fixups, @@ -1855,7 +1855,7 @@
/* If we have any external fixups, base tree must have /__symbols__. */ if (!symbols) - return -1; + return false;
/* * Unlike /__local_fixups__, /__fixups__ is not a whole subtree that @@ -1867,21 +1867,21 @@ a property to phandle-reference. Look up in /__symbols__. */ const char *path = dt_find_string_prop(symbols, fix->prop.name); if (!path) - return -1; + return false;
/* Find node the label pointed to figure out its phandle. */ struct device_tree_node *node = dt_find_node_by_path(tree, path, NULL, NULL, 0); if (!node) - return -1; + return false;
/* Write into the overlay property(s) pointing to that node. */ - if (dt_fixup_external(overlay, fix, node->phandle, - path, overlay_symbols) < 0) - return -1; + if (!dt_fixup_external(overlay, fix, node->phandle, + path, overlay_symbols)) + return false; }
- return 0; + return true; }
/* @@ -1956,9 +1956,9 @@ * @param fragment /fragment@X node. * @params overlay_symbols /__symbols__ node of the overlay. * - * @return 0 on success, -1 on error. + * @return true on success, false on error. */ -static int dt_import_fragment(struct device_tree *tree, +static bool dt_import_fragment(struct device_tree *tree, struct device_tree_node *fragment, struct device_tree_node *overlay_symbols) { @@ -1969,7 +1969,7 @@
/* If it doesn't have an __overlay__ child, it's not a fragment. */ if (!overlay) - return 0; + return true;
/* Target node of the fragment can be given by path or by phandle. */ struct device_tree_property *prop; @@ -1987,7 +1987,7 @@ struct device_tree_node *target = NULL; if (phandle) { if (phandle->prop.size != sizeof(uint32_t)) - return -1; + return false; target = dt_find_node_by_phandle(tree->root, be32dec(phandle->prop.data)); /* Symbols already updated as part of dt_fixup_external(). */ @@ -1997,10 +1997,10 @@ dt_fix_symbols(overlay_symbols, fragment, path->prop.data); } if (!target) - return -1; + return false;
dt_copy_subtree(target, overlay, 1); - return 0; + return true; }
/* @@ -2011,9 +2011,9 @@ * @param tree Unflattened base device tree to add the overlay into. * @param overlay Unflattened overlay device tree to apply to the base. * - * @return 0 on success, -1 on error. + * @return true on success, false on error. */ -int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay) +bool dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay) { /* * First, we need to make sure phandles inside the overlay don't clash @@ -2025,7 +2025,7 @@ uint32_t new_max = dt_adjust_all_phandles(overlay->root, phandle_base); if (!new_max) { printk(BIOS_ERR, "invalid phandles in overlay\n"); - return -1; + return false; } tree->max_phandle = new_max;
@@ -2033,10 +2033,10 @@ nodes referring to them. Those are listed in /__local_fixups__. */ struct device_tree_node *local_fixups = dt_find_node_by_path(overlay, "/__local_fixups__", NULL, NULL, 0); - if (local_fixups && dt_fixup_locals(overlay->root, local_fixups, - phandle_base) < 0) { + if (local_fixups && !dt_fixup_locals(overlay->root, local_fixups, + phandle_base)) { printk(BIOS_ERR, "invalid local fixups in overlay\n"); - return -1; + return false; }
/* @@ -2057,20 +2057,20 @@ "/__fixups__", NULL, NULL, 0); struct device_tree_node *overlay_symbols = dt_find_node_by_path(overlay, "/__symbols__", NULL, NULL, 0); - if (fixups && dt_fixup_all_externals(tree, symbols, overlay, - fixups, overlay_symbols) < 0) { + if (fixups && !dt_fixup_all_externals(tree, symbols, overlay, + fixups, overlay_symbols)) { printk(BIOS_ERR, "cannot match external fixups from overlay\n"); - return -1; + return false; }
/* After all this fixing up, we can finally merge overlay into the tree (one fragment at a time, because for some reason it's split up). */ struct device_tree_node *fragment; list_for_each(fragment, overlay->root->children, list_node) - if (dt_import_fragment(tree, fragment, overlay_symbols) < 0) { + if (!dt_import_fragment(tree, fragment, overlay_symbols)) { printk(BIOS_ERR, "bad DT fragment '%s'\n", fragment->name); - return -1; + return false; }
/* @@ -2088,5 +2088,5 @@ &tree->root->children); }
- return 0; + return true; } diff --git a/src/commonlib/include/commonlib/device_tree.h b/src/commonlib/include/commonlib/device_tree.h index c15d7ae..a2a5009 100644 --- a/src/commonlib/include/commonlib/device_tree.h +++ b/src/commonlib/include/commonlib/device_tree.h @@ -198,7 +198,7 @@
/* Apply an overlay to a base device tree. Ownership of the overlay data passes to the newly combined base tree -- do not free() or access it afterwards! */ -int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay); +bool dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay);
/* * Fixups to apply to a kernel's device tree before booting it.