[PATCH 08/29] of_node command: use of_create_node

Sascha Hauer s.hauer at pengutronix.de
Tue Feb 26 15:18:35 EST 2013


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/of_node.c |   27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/commands/of_node.c b/commands/of_node.c
index a370e26..bf9799c 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -39,6 +39,7 @@ static int do_of_node(int argc, char *argv[])
 	int create = 0;
 	char *path = NULL;
 	struct device_node *node = NULL;
+	struct device_node *root;
 
 	while ((opt = getopt(argc, argv, "cd")) > 0) {
 		switch (opt) {
@@ -57,27 +58,19 @@ static int do_of_node(int argc, char *argv[])
 		path = argv[optind];
 	}
 
-	if (create) {
-		char *name;
+	root = of_get_root_node();
+	if (!root) {
+		printf("root node not set\n");
+		return -ENOENT;
+	}
 
+	if (create) {
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		name = xstrdup(basename(path));
-		path = dirname(path);
-
-		node = of_find_node_by_path(path);
-		if (!node) {
-			printf("Cannot find nodepath %s\n", path);
-			free(name);
-			return -ENOENT;
-		}
-
-		debug("create node \"%s\" \"%s\"\n", path, name);
-
-		of_new_node(node, name);
-
-		free(name);
+		node = of_create_node(root, path);
+		if (!node)
+			return -EINVAL;
 
 		return 0;
 	}
-- 
1.7.10.4




More information about the barebox mailing list