summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-02-07 09:27:59 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-02-07 09:35:41 +0100
commitcfa1e13fba762f3be4d193523ddcc7ea76018c53 (patch)
treebdfce3b8707526a2572ec1a4fc78af1e0bb0b0b4 /drivers
parent616ff0948058b96c258caa95c93b2b61ec746ca7 (diff)
downloadbarebox-cfa1e13fba762f3be4d193523ddcc7ea76018c53.tar.gz
barebox-cfa1e13fba762f3be4d193523ddcc7ea76018c53.tar.xz
of: report whether of_diff found differences in return code
Tests may want to leverage of_diff to verify that fixups proceeded as expected. of_diff lends itself nicely to that by being silent in case of success and just reporting diff on error. Add a return code to make it usable in follow-up tests. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220207082801.1052894-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/base.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 80465d6d50..99be242542 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2077,15 +2077,16 @@ static void of_print_close(struct device_node *node, int *printed)
* This function compares two device trees against each other and prints
* a diff-like result.
*/
-void of_diff(struct device_node *a, struct device_node *b, int indent)
+int of_diff(struct device_node *a, struct device_node *b, int indent)
{
struct property *ap, *bp;
struct device_node *ca, *cb;
- int printed = 0;
+ int printed = 0, diff = 0;
list_for_each_entry(ap, &a->properties, list) {
bp = of_find_property(b, ap->name, NULL);
if (!bp) {
+ diff++;
of_print_parents(a, &printed);
printf("- ");
__of_print_property(ap, indent);
@@ -2093,6 +2094,7 @@ void of_diff(struct device_node *a, struct device_node *b, int indent)
}
if (ap->length != bp->length || memcmp(of_property_get_value(ap), of_property_get_value(bp), bp->length)) {
+ diff++;
of_print_parents(a, &printed);
printf("- ");
__of_print_property(ap, indent);
@@ -2104,6 +2106,7 @@ void of_diff(struct device_node *a, struct device_node *b, int indent)
list_for_each_entry(bp, &b->properties, list) {
ap = of_find_property(a, bp->name, NULL);
if (!ap) {
+ diff++;
of_print_parents(a, &printed);
printf("+ ");
__of_print_property(bp, indent);
@@ -2113,8 +2116,9 @@ void of_diff(struct device_node *a, struct device_node *b, int indent)
for_each_child_of_node(a, ca) {
cb = of_get_child_by_name(b, ca->name);
if (cb) {
- of_diff(ca, cb, indent + 1);
+ diff += of_diff(ca, cb, indent + 1);
} else {
+ diff++;
of_print_parents(a, &printed);
__of_print_nodes(ca, indent, "- ");
}
@@ -2122,12 +2126,15 @@ void of_diff(struct device_node *a, struct device_node *b, int indent)
for_each_child_of_node(b, cb) {
if (!of_get_child_by_name(a, cb->name)) {
+ diff++;
of_print_parents(a, &printed);
__of_print_nodes(cb, indent, "+ ");
}
}
of_print_close(a, &printed);
+
+ return diff;
}
struct device_node *of_new_node(struct device_node *parent, const char *name)