From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] of: fdt: justify fdt_machine_is_compatible parsing only the root node
Date: Wed, 13 Mar 2024 10:31:45 +0100 [thread overview]
Message-ID: <20240313093145.3349370-1-a.fatoum@pengutronix.de> (raw)
fdt_machine_is_compatible() is a lightweight way to check the top-level
compatible without unflattening the DT or pulling in libfdt.
The lightness is due to parsing only the root node and looking for the
compatible right away. This assumes that no child nodes of the root node
precede the compatible property. This is mandated by the specification
and dtc throws a syntax error when attempting to violate this.
Add a comment referencing the specification to tell future readers why
it should be ok for us to assume this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/fdt.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 2f3b0763999d..8dca41990c87 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -730,6 +730,17 @@ int fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, con
dt_struct = dt_struct_advance(&f, dt_struct,
sizeof(struct fdt_node_header) + 1);
+ /*
+ * Quoting Device Tree Specification v0.4 §5.4.2:
+ *
+ * [T]his process requires that all property definitions for
+ * a particular node precede any subnode definitions for that
+ * node. Although the structure would not be ambiguous if
+ * properties and subnodes were intermingled, the code needed
+ * to process a flat tree is simplified by this requirement.
+ *
+ * So let's make use of this simplification.
+ */
expect = FDT_PROP;
break;
--
2.39.2
next reply other threads:[~2024-03-13 9:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 9:31 Ahmad Fatoum [this message]
2024-03-13 10:52 ` 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=20240313093145.3349370-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