]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/of/base.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivi...
[linux.git] / drivers / of / base.c
index ce1d3d8a0cd844bd918c2a465fc665e126158327..aab9728271fdbfe27b199a9325bfed84063b928d 100644 (file)
@@ -1828,17 +1828,17 @@ int of_update_property(struct device_node *np, struct property *newprop)
                next = &(*next)->next;
        }
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
-       if (rc)
-               return rc;
+       if (!found)
+               return -ENODEV;
+
+       /* At early boot, bail out and defer setup to of_init() */
+       if (!of_kset)
+               return found ? 0 : -ENODEV;
 
        /* Update the sysfs attribute */
-       if (oldprop)
-               sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
+       sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
        __of_add_property_sysfs(np, newprop);
 
-       if (!found)
-               return -ENODEV;
-
        return 0;
 }
 
@@ -2196,64 +2196,65 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
                                        struct device_node *prev)
 {
        struct device_node *endpoint;
-       struct device_node *port = NULL;
+       struct device_node *port;
 
        if (!parent)
                return NULL;
 
+       /*
+        * Start by locating the port node. If no previous endpoint is specified
+        * search for the first port node, otherwise get the previous endpoint
+        * parent port node.
+        */
        if (!prev) {
                struct device_node *node;
-               /*
-                * It's the first call, we have to find a port subnode
-                * within this node or within an optional 'ports' node.
-                */
+
                node = of_get_child_by_name(parent, "ports");
                if (node)
                        parent = node;
 
                port = of_get_child_by_name(parent, "port");
-
-               if (port) {
-                       /* Found a port, get an endpoint. */
-                       endpoint = of_get_next_child(port, NULL);
-                       of_node_put(port);
-               } else {
-                       endpoint = NULL;
-               }
-
-               if (!endpoint)
-                       pr_err("%s(): no endpoint nodes specified for %s\n",
-                              __func__, parent->full_name);
                of_node_put(node);
 
-               return endpoint;
-       }
-
-       port = of_get_parent(prev);
-       if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
-                     __func__, prev->full_name))
-               return NULL;
+               if (!port) {
+                       pr_err("%s(): no port node found in %s\n",
+                              __func__, parent->full_name);
+                       return NULL;
+               }
+       } else {
+               port = of_get_parent(prev);
+               if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
+                             __func__, prev->full_name))
+                       return NULL;
 
-       /* Avoid dropping prev node refcount to 0. */
-       of_node_get(prev);
-       endpoint = of_get_next_child(port, prev);
-       if (endpoint) {
-               of_node_put(port);
-               return endpoint;
+               /*
+                * Avoid dropping prev node refcount to 0 when getting the next
+                * child below.
+                */
+               of_node_get(prev);
        }
 
-       /* No more endpoints under this port, try the next one. */
-       do {
-               port = of_get_next_child(parent, port);
-               if (!port)
-                       return NULL;
-       } while (of_node_cmp(port->name, "port"));
+       while (1) {
+               /*
+                * Now that we have a port node, get the next endpoint by
+                * getting the next child. If the previous endpoint is NULL this
+                * will return the first child.
+                */
+               endpoint = of_get_next_child(port, prev);
+               if (endpoint) {
+                       of_node_put(port);
+                       return endpoint;
+               }
 
-       /* Pick up the first endpoint in this port. */
-       endpoint = of_get_next_child(port, NULL);
-       of_node_put(port);
+               /* No more endpoints under this port, try the next one. */
+               prev = NULL;
 
-       return endpoint;
+               do {
+                       port = of_get_next_child(parent, port);
+                       if (!port)
+                               return NULL;
+               } while (of_node_cmp(port->name, "port"));
+       }
 }
 EXPORT_SYMBOL(of_graph_get_next_endpoint);