mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] of: fdt: reserve properties and nodes starting with $ for barebox use
@ 2024-12-19 11:16 Ahmad Fatoum
  2024-12-19 11:16 ` [PATCH 2/3] of: fdt: rename /memreserve special node to /$memreserve Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2024-12-19 11:16 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have at least two places, where we associate extra information with a
device tree, either to consult this information later or to make sure
that an extra allocated buffer is free'd along with the device tree is
tacked onto.

For robustness, we will move such extra nodes and properties into their
own namespace by prefixing them with a '$'. This character is disallowed
by the device tree specification and we have no DTs making use of it.

Nodes and properties starting with '$' will be an error on unflattening
and skipped on flattening, ensuring that only barebox can make use of
them.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/fdt.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 69c041cb8902..6f10094143cd 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -56,6 +56,12 @@ static inline const char *dt_string(struct fdt_header *f, const char *strstart,
 	return string_is_terminated(str, f->size_dt_strings - ofs) ? str : NULL;
 }
 
+static inline bool is_reserved_name(const char *name)
+{
+	/* We use the $ prefix for properties internal to barebox */
+	return *name == '$';
+}
+
 static int of_reservemap_num_entries(const struct fdt_header *fdt)
 {
 	/*
@@ -230,7 +236,7 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
 				node = root;
 			} else {
 				/* Only the root node may have an empty name */
-				if (!*pathp) {
+				if (!*pathp || is_reserved_name(pathp)) {
 					ret = -EINVAL;
 					goto err;
 				}
@@ -266,7 +272,7 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
 			nodep = fdt_prop->data;
 
 			name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
-			if (!name || !node) {
+			if (!name || !node || is_reserved_name(name)) {
 				ret = -ESPIPE;
 				goto err;
 			}
@@ -475,6 +481,9 @@ static int __of_flatten_dtb(struct fdt *fdt, struct device_node *node, int is_ro
 	list_for_each_entry(p, &node->properties, list) {
 		struct fdt_property *fp;
 
+		if (is_reserved_name(p->name))
+			continue;
+
 		if (fdt_ensure_space(fdt, p->length) < 0)
 			return -ENOMEM;
 
@@ -489,6 +498,8 @@ static int __of_flatten_dtb(struct fdt *fdt, struct device_node *node, int is_ro
 	}
 
 	list_for_each_entry(n, &node->children, parent_list) {
+		if (is_reserved_name(n->name))
+			continue;
 		if (is_root && !strcmp(n->name, "memreserve"))
 			continue;
 
-- 
2.39.5




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

end of thread, other threads:[~2024-12-20  8:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-19 11:16 [PATCH 1/3] of: fdt: reserve properties and nodes starting with $ for barebox use Ahmad Fatoum
2024-12-19 11:16 ` [PATCH 2/3] of: fdt: rename /memreserve special node to /$memreserve Ahmad Fatoum
2024-12-19 11:16 ` [PATCH 3/3] FIT: cache uncompressed data Ahmad Fatoum
2024-12-20  8:19 ` [PATCH 1/3] of: fdt: reserve properties and nodes starting with $ for barebox use Sascha Hauer

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