mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] of: fdt: reserve properties and nodes starting with $ for barebox use
Date: Thu, 19 Dec 2024 12:16:01 +0100	[thread overview]
Message-ID: <20241219111603.1020442-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2024-12-19 11:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19 11:16 Ahmad Fatoum [this message]
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

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=20241219111603.1020442-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