summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-13 10:31:45 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-13 11:51:55 +0100
commit3c8d123593cc7ad4070dc9f0631bd30d1d733225 (patch)
treea37c805b64cd5b9787252f0a4487042535117343
parent041702182a2776677a6da894933555967741ee0d (diff)
downloadbarebox-3c8d123593cc7ad4070dc9f0631bd30d1d733225.tar.gz
barebox-3c8d123593cc7ad4070dc9f0631bd30d1d733225.tar.xz
of: fdt: justify fdt_machine_is_compatible parsing only the root node
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> Link: https://lore.barebox.org/20240313093145.3349370-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/of/fdt.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 2f3b076399..8dca41990c 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;