Skip to contentSkip to conversation

For fdt_find_node_by_path(), handle the root path properly.

PATCH In review Jerry Van Baren 2 participants 2 messages Jul 5, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 11/17 For fdt_find_node_by_path(), handle the root path properly.

Also removes the special case root path detection in cmd_fdt.c since it is no longer necessary.

---
 common/cmd_fdt.c |   35 ++++++++++++-----------------------
 libfdt/fdt_ro.c  |    4 ++++
 2 files changed, 16 insertions(+), 23 deletions(-)
common/cmd_fdt.c +12 -23
index 5a2c3fd..aa65297 100644
@@ -52,25 +52,6 @@ static int fdt_parse_prop(char *pathp, char *prop, char *newval,
 	char *data, int *len);
 static int fdt_print(char *pathp, char *prop, int depth);
 
-static int findnodeoffset(const char *pathp)
-{
-	int  nodeoffset;
-
-	if (strcmp(pathp, "/") == 0) {
-		nodeoffset = 0;
-	} else {
-		nodeoffset = fdt_find_node_by_path (fdt, pathp);
-		if (nodeoffset < 0) {
-			/*
-			 * Not found or something else bad happened.
-			 */
-			printf ("findnodeoffset() libfdt: %s\n",
-				fdt_strerror(nodeoffset));
-		}
-	}
-	return nodeoffset;
-}
-
 /*
  * Flattened Device Tree command, see the help for parameter definitions.
  */
@@ -187,11 +168,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		pathp = argv[2];
 		nodep = argv[3];
 
-		nodeoffset = findnodeoffset(pathp);
+		nodeoffset = fdt_find_node_by_path (fdt, pathp);
 		if (nodeoffset < 0) {
 			/*
 			 * Not found or something else bad happened.
 			 */
+			printf ("libfdt fdt_find_node_by_path() returned %s\n",
+				fdt_strerror(nodeoffset));
 			return 1;
 		}
 		err = fdt_add_subnode(fdt, nodeoffset, nodep);
@@ -225,11 +208,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		prop   = argv[3];
 		newval = argv[4];
 
-		nodeoffset = findnodeoffset(pathp);
+		nodeoffset = fdt_find_node_by_path (fdt, pathp);
 		if (nodeoffset < 0) {
 			/*
 			 * Not found or something else bad happened.
 			 */
+			printf ("libfdt fdt_find_node_by_path() returned %s\n",
+				fdt_strerror(nodeoffset));
 			return 1;
 		}
 		ret = fdt_parse_prop(pathp, prop, newval, data, &len);
@@ -283,11 +268,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		 * Get the path.  The root node is an oddball, the offset
 		 * is zero and has no name.
 		 */
-		nodeoffset = findnodeoffset(argv[2]);
+		nodeoffset = fdt_find_node_by_path (fdt, argv[2]);
 		if (nodeoffset < 0) {
 			/*
 			 * Not found or something else bad happened.
 			 */
+			printf ("libfdt fdt_find_node_by_path() returned %s\n",
+				fdt_strerror(nodeoffset));
 			return 1;
 		}
 		/*
@@ -584,11 +571,13 @@ static int fdt_print(char *pathp, char *prop, int depth)
 	int  len;		/* length of the property */
 	int  level = 0;		/* keep track of nesting level */
 
-	nodeoffset = findnodeoffset(pathp);
+	nodeoffset = fdt_find_node_by_path (fdt, pathp);
 	if (nodeoffset < 0) {
 		/*
 		 * Not found or something else bad happened.
 		 */
+		printf ("libfdt fdt_find_node_by_path() returned %s\n",
+			fdt_strerror(nodeoffset));
 		return 1;
 	}
 	/*
libfdt/fdt_ro.c +4 -0
index 923c389..ffd9209 100644
@@ -283,6 +283,10 @@ int fdt_find_node_by_path(const void *fdt, const char *path)
 	if (*path != '/')
 		return -FDT_ERR_BADPATH;
 
+	/* Handle the root path: root offset is 0 */
+	if (strcmp(path, "/") == 0)
+		return 0;
+
 	while (*p) {
 		const char *q;
 
Signature · 1 line
1.4.4.4
#1 lore raw

PATCH 11/17 For fdt_find_node_by_path(), handle the root path properly.

Quoted 4 lines · Jerry Van Baren

Also removes the special case root path detection in cmd_fdt.c since it is no longer necessary.

Quoted 124 lines
---
 common/cmd_fdt.c |   35 ++++++++++++-----------------------
 libfdt/fdt_ro.c  |    4 ++++
 2 files changed, 16 insertions(+), 23 deletions(-)
common/cmd_fdt.c +12 -23
index 5a2c3fd..aa65297 100644
@@ -52,25 +52,6 @@ static int fdt_parse_prop(char *pathp, char *prop, char *newval,
        char *data, int *len);
 static int fdt_print(char *pathp, char *prop, int depth);
 
-static int findnodeoffset(const char *pathp)
-{
-       int  nodeoffset;
-
-       if (strcmp(pathp, "/") == 0) {
-               nodeoffset = 0;
-       } else {
-               nodeoffset = fdt_find_node_by_path (fdt, pathp);
-               if (nodeoffset < 0) {
-                       /*
-                        * Not found or something else bad happened.
-                        */
-                       printf ("findnodeoffset() libfdt: %s\n",
-                               fdt_strerror(nodeoffset));
-               }
-       }
-       return nodeoffset;
-}
-
 /*
  * Flattened Device Tree command, see the help for parameter definitions.
  */
@@ -187,11 +168,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
                pathp = argv[2];
                nodep = argv[3];
 
-               nodeoffset = findnodeoffset(pathp);
+               nodeoffset = fdt_find_node_by_path (fdt, pathp);
                if (nodeoffset < 0) {
                        /*
                         * Not found or something else bad happened.
                         */
+                       printf ("libfdt fdt_find_node_by_path() returned %s\n",
+                               fdt_strerror(nodeoffset));
                        return 1;
                }
                err = fdt_add_subnode(fdt, nodeoffset, nodep);
@@ -225,11 +208,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
                prop   = argv[3];
                newval = argv[4];
 
-               nodeoffset = findnodeoffset(pathp);
+               nodeoffset = fdt_find_node_by_path (fdt, pathp);
                if (nodeoffset < 0) {
                        /*
                         * Not found or something else bad happened.
                         */
+                       printf ("libfdt fdt_find_node_by_path() returned %s\n",
+                               fdt_strerror(nodeoffset));
                        return 1;
                }
                ret = fdt_parse_prop(pathp, prop, newval, data, &len);
@@ -283,11 +268,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
                 * Get the path.  The root node is an oddball, the offset
                 * is zero and has no name.
                 */
-               nodeoffset = findnodeoffset(argv[2]);
+               nodeoffset = fdt_find_node_by_path (fdt, argv[2]);
                if (nodeoffset < 0) {
                        /*
                         * Not found or something else bad happened.
                         */
+                       printf ("libfdt fdt_find_node_by_path() returned %s\n",
+                               fdt_strerror(nodeoffset));
                        return 1;
                }
                /*
@@ -584,11 +571,13 @@ static int fdt_print(char *pathp, char *prop, int depth)
        int  len;               /* length of the property */
        int  level = 0;         /* keep track of nesting level */
 
-       nodeoffset = findnodeoffset(pathp);
+       nodeoffset = fdt_find_node_by_path (fdt, pathp);
        if (nodeoffset < 0) {
                /*
                 * Not found or something else bad happened.
                 */
+               printf ("libfdt fdt_find_node_by_path() returned %s\n",
+                       fdt_strerror(nodeoffset));
                return 1;
        }
        /*
libfdt/fdt_ro.c +4 -1
index 923c389..ffd9209 100644
@@ -283,6 +283,10 @@ int fdt_find_node_by_path(const void *fdt, const char *path)
        if (*path != '/')
                return -FDT_ERR_BADPATH;
 
+       /* Handle the root path: root offset is 0 */
+       if (strcmp(path, "/") == 0)
+               return 0;
+
        while (*p) {
                const char *q;
 
--

1.4.4.4

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
U-Boot-Users mailing list
U-Boot-Users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely at secretlab.ca
(403) 399-0195