mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/5] of: report whether of_diff found differences in return code
Date: Mon,  7 Feb 2022 08:56:19 +0100	[thread overview]
Message-ID: <20220207075621.1014381-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220207075621.1014381-1-a.fatoum@pengutronix.de>

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>
---
 commands/of_diff.c |  4 +---
 drivers/of/base.c  | 13 ++++++++++---
 include/of.h       |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/commands/of_diff.c b/commands/of_diff.c
index fa99fcd641da..fcae367a8105 100644
--- a/commands/of_diff.c
+++ b/commands/of_diff.c
@@ -77,9 +77,7 @@ static int do_of_diff(int argc, char *argv[])
 		goto out;
 	}
 
-	of_diff(a, b, 0);
-
-	ret = 0;
+	ret = of_diff(a, b, 0) ? COMMAND_SUCCESS : COMMAND_ERROR;
 out:
 	if (a && a != root)
 		of_delete_node(a);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 80465d6d5062..99be24254203 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)
diff --git a/include/of.h b/include/of.h
index 216d0ee76368..b449d10ec774 100644
--- a/include/of.h
+++ b/include/of.h
@@ -107,7 +107,7 @@ void of_print_cmdline(struct device_node *root);
 
 void of_print_nodes(struct device_node *node, int indent);
 void of_print_properties(struct device_node *node);
-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);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
 struct device_node *of_unflatten_dtb(const void *fdt, int size);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-02-07  7:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07  7:56 [PATCH 1/5] test: self: printf: log skipped tests Ahmad Fatoum
2022-02-07  7:56 ` [PATCH 2/5] test: self: printf: add tests for %*ph prints Ahmad Fatoum
2022-02-07  7:56 ` Ahmad Fatoum [this message]
2022-02-07  7:56 ` [PATCH 4/5] of: silence of_diff output for negative indents Ahmad Fatoum
2022-02-07  8:17   ` Sascha Hauer
2022-02-07  8:22     ` Sascha Hauer
2022-02-07  8:23       ` Ahmad Fatoum
2022-02-07  7:56 ` [PATCH 5/5] test: self: add device tree manipulation test Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220207075621.1014381-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox