Author: kevans
Date: Wed Mar 14 03:50:12 2018
New Revision: 330907
URL: https://svnweb.freebsd.org/changeset/base/330907

Log:
  MFC r330019: ofw_fdt: Simplify parts with new libfdt methods
  
  libfdt now provides methods to iterate through subnodes and properties in a
  convenient fashion.
  
  Replace our ofw_fdt_{peer,child} searches with calls to their corresponding
  libfdt methods. Rework ofw_fdt_nextprop to use the
  fdt_for_each_property_offset macro, making it even more obvious what it's
  doing.
  
  No functional change intended.

Modified:
  stable/11/sys/dev/ofw/ofw_fdt.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/ofw/ofw_fdt.c
==============================================================================
--- stable/11/sys/dev/ofw/ofw_fdt.c     Wed Mar 14 03:49:15 2018        
(r330906)
+++ stable/11/sys/dev/ofw/ofw_fdt.c     Wed Mar 14 03:50:12 2018        
(r330907)
@@ -153,7 +153,7 @@ fdt_phandle_offset(phandle_t p)
 static phandle_t
 ofw_fdt_peer(ofw_t ofw, phandle_t node)
 {
-       int depth, offset;
+       int offset;
 
        if (node == 0) {
                /* Find root node */
@@ -165,39 +165,21 @@ ofw_fdt_peer(ofw_t ofw, phandle_t node)
        offset = fdt_phandle_offset(node);
        if (offset < 0)
                return (0);
-
-       for (depth = 1, offset = fdt_next_node(fdtp, offset, &depth);
-           offset >= 0;
-           offset = fdt_next_node(fdtp, offset, &depth)) {
-               if (depth < 0)
-                       return (0);
-               if (depth == 1)
-                       return (fdt_offset_phandle(offset));
-       }
-
-       return (0);
+       offset = fdt_next_subnode(fdtp, offset);
+       return (fdt_offset_phandle(offset));
 }
 
 /* Return the first child of this node or 0. */
 static phandle_t
 ofw_fdt_child(ofw_t ofw, phandle_t node)
 {
-       int depth, offset;
+       int offset;
 
        offset = fdt_phandle_offset(node);
        if (offset < 0)
                return (0);
-
-       for (depth = 0, offset = fdt_next_node(fdtp, offset, &depth);
-           (offset >= 0) && (depth > 0);
-           offset = fdt_next_node(fdtp, offset, &depth)) {
-               if (depth < 0)
-                       return (0);
-               if (depth == 1)
-                       return (fdt_offset_phandle(offset));
-       }
-
-       return (0);
+       offset = fdt_first_subnode(fdtp, offset);
+       return (fdt_offset_phandle(offset));
 }
 
 /* Return the parent of this node or 0. */
@@ -320,26 +302,24 @@ ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const c
        if (offset < 0)
                return (-1);
 
-       /* Find the first prop in the node */
-       offset = fdt_first_property_offset(fdtp, offset);
-       if (offset < 0)
-               return (0); /* No properties */
-
-       if (previous != NULL) {
-               while (offset >= 0) {
+       if (previous == NULL)
+               /* Find the first prop in the node */
+               offset = fdt_first_property_offset(fdtp, offset);
+       else {
+               fdt_for_each_property_offset(offset, fdtp, offset) {
                        prop = fdt_getprop_by_offset(fdtp, offset, &name, NULL);
                        if (prop == NULL)
                                return (-1); /* Internal error */
-
+                       /* Skip until we find 'previous', then bail out */
+                       if (strcmp(name, previous) != 0)
+                               continue;
                        offset = fdt_next_property_offset(fdtp, offset);
-                       if (offset < 0)
-                               return (0); /* No more properties */
-
-                       /* Check if the last one was the one we wanted */
-                       if (strcmp(name, previous) == 0)
-                               break;
+                       break;
                }
        }
+
+       if (offset < 0)
+               return (0); /* No properties */
 
        prop = fdt_getprop_by_offset(fdtp, offset, &name, &offset);
        if (prop == NULL)
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to