From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] of: base: factor out duplication for property formatting
Date: Mon, 8 Aug 2022 08:56:38 +0200 [thread overview]
Message-ID: <20220808065639.453483-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2022-08-08 6:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 6:56 Ahmad Fatoum [this message]
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
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=20220808065639.453483-1-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