mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de
Subject: [PATCH v2 1/2] of: base: add helper to rename a node
Date: Tue, 12 Feb 2019 16:10:40 +0100	[thread overview]
Message-ID: <20190212151041.17507-1-m.felsch@pengutronix.de> (raw)

Sometimes it can be necessary to rename a node, e.g. a upstream node was
renamed and the whole board logic depends on the old naming scheme.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Note:
In my v1 this patch was required for the followed, but now it isn't. So
feel free to add or drop it. IMHO it can be a useful helper in the
future.

Changelog:
v2:
 - const name parameter
 - free names before adding new ones
 - drop unnecessary else-path
 - adapt commit message

 drivers/of/base.c | 18 ++++++++++++++++++
 include/of.h      |  5 +++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index b082f0c656..48f1270baa 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2094,6 +2094,24 @@ void of_delete_node(struct device_node *node)
 		of_set_root_node(NULL);
 }
 
+void of_rename_node(struct device_node *node, const char *name)
+{
+	struct device_node *parent;
+
+	if (!node)
+		return;
+
+	parent = node->parent;
+	if (parent) {
+		/* only child nodes have names */
+		free(node->name);
+		free(node->full_name);
+
+		node->name = xstrdup(name);
+		node->full_name = basprintf("%s/%s", parent->full_name, name);
+	}
+}
+
 int of_device_is_stdout_path(struct device_d *dev)
 {
 	struct device_node *dn;
diff --git a/include/of.h b/include/of.h
index 184acb4741..f829690865 100644
--- a/include/of.h
+++ b/include/of.h
@@ -158,6 +158,7 @@ extern struct device_node *of_create_node(struct device_node *root,
 extern struct device_node *of_copy_node(struct device_node *parent,
 				const struct device_node *other);
 extern void of_delete_node(struct device_node *node);
+extern void of_rename_node(struct device_node *node, const char *name);
 
 extern const char *of_get_machine_compatible(void);
 extern int of_machine_is_compatible(const char *compat);
@@ -605,6 +606,10 @@ static inline void of_delete_node(struct device_node *node)
 {
 }
 
+static inline void of_rename_node(struct device_node *node, const char *name)
+{
+}
+
 static inline int of_machine_is_compatible(const char *compat)
 {
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2019-02-12 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 15:10 Marco Felsch [this message]
2019-02-12 15:10 ` [PATCH v2 2/2] memory: of_fixup: adapt to new memory layout Marco Felsch
2019-02-12 20:23 ` [PATCH v2 1/2] of: base: add helper to rename a node 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=20190212151041.17507-1-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mfe@pengutronix.de \
    /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