mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] of: base: factor out duplication for property formatting
@ 2022-08-08  6:56 Ahmad Fatoum
  2022-08-08  6:56 ` [PATCH 2/2] commands: of_dump: support limiting size of printed properties Ahmad Fatoum
  2022-08-08 11:18 ` [PATCH 1/2] of: base: factor out duplication for property formatting Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-08-08  6:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have the same chunk of code with minuscule difference in both
__of_print_nodes and __of_print_property. Factor it out to simplify
the follow-up commit.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/base.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 101b2f74c74f..ac5a14f49919 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2006,6 +2006,22 @@ int of_property_read_string_helper(const struct device_node *np,
 	return i <= 0 ? -ENODATA : i;
 }
 
+static void __of_print_property_prefixed(const struct property *p, int indent,
+					 const char *prefix)
+{
+	unsigned length;
+
+	printf("%s%*s%s", prefix, indent * 8, "", p->name);
+
+	length = p->length;
+	if (length) {
+		printf(" = ");
+		of_print_property(of_property_get_value(p), length);
+	}
+
+	printf(";\n");
+}
+
 static int __of_print_nodes(struct device_node *node, int indent, const char *prefix)
 {
 	struct device_node *n;
@@ -2020,14 +2036,8 @@ static int __of_print_nodes(struct device_node *node, int indent, const char *pr
 
 	printf("%s%*s%s%s\n", prefix, indent * 8, "", node->name, node->name ? " {" : "{");
 
-	list_for_each_entry(p, &node->properties, list) {
-		printf("%s%*s%s", prefix, (indent + 1) * 8, "", p->name);
-		if (p->length) {
-			printf(" = ");
-			of_print_property(of_property_get_value(p), p->length);
-		}
-		printf(";\n");
-	}
+	list_for_each_entry(p, &node->properties, list)
+		__of_print_property_prefixed(p, indent + 1, prefix);
 
 	if (ctrlc())
 		return -EINTR;
@@ -2049,12 +2059,7 @@ void of_print_nodes(struct device_node *node, int indent)
 
 static void __of_print_property(struct property *p, int indent)
 {
-	printf("%*s%s", indent * 8, "", p->name);
-	if (p->length) {
-		printf(" = ");
-		of_print_property(of_property_get_value(p), p->length);
-	}
-	printf(";\n");
+	__of_print_property_prefixed(p, indent, "");
 }
 
 void of_print_properties(struct device_node *node)
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-08 11:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08  6:56 [PATCH 1/2] of: base: factor out duplication for property formatting Ahmad Fatoum
2022-08-08  6:56 ` [PATCH 2/2] commands: of_dump: support limiting size of printed properties Ahmad Fatoum
2022-08-08 11:18 ` [PATCH 1/2] of: base: factor out duplication for property formatting Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox