* [PATCH] of: fdt: justify fdt_machine_is_compatible parsing only the root node
@ 2024-03-13 9:31 Ahmad Fatoum
2024-03-13 10:52 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-03-13 9:31 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] of: fdt: justify fdt_machine_is_compatible parsing only the root node
2024-03-13 9:31 [PATCH] of: fdt: justify fdt_machine_is_compatible parsing only the root node Ahmad Fatoum
@ 2024-03-13 10:52 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-03-13 10:52 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Wed, 13 Mar 2024 10:31:45 +0100, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] of: fdt: justify fdt_machine_is_compatible parsing only the root node
https://git.pengutronix.de/cgit/barebox/commit/?id=3c8d123593cc (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-13 10:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-13 9:31 [PATCH] of: fdt: justify fdt_machine_is_compatible parsing only the root node Ahmad Fatoum
2024-03-13 10:52 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox