aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4557a142c752..f72d19b7e5d2 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2196,64 +2196,65 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
2196 struct device_node *prev) 2196 struct device_node *prev)
2197{ 2197{
2198 struct device_node *endpoint; 2198 struct device_node *endpoint;
2199 struct device_node *port = NULL; 2199 struct device_node *port;
2200 2200
2201 if (!parent) 2201 if (!parent)
2202 return NULL; 2202 return NULL;
2203 2203
2204 /*
2205 * Start by locating the port node. If no previous endpoint is specified
2206 * search for the first port node, otherwise get the previous endpoint
2207 * parent port node.
2208 */
2204 if (!prev) { 2209 if (!prev) {
2205 struct device_node *node; 2210 struct device_node *node;
2206 /* 2211
2207 * It's the first call, we have to find a port subnode
2208 * within this node or within an optional 'ports' node.
2209 */
2210 node = of_get_child_by_name(parent, "ports"); 2212 node = of_get_child_by_name(parent, "ports");
2211 if (node) 2213 if (node)
2212 parent = node; 2214 parent = node;
2213 2215
2214 port = of_get_child_by_name(parent, "port"); 2216 port = of_get_child_by_name(parent, "port");
2215
2216 if (port) {
2217 /* Found a port, get an endpoint. */
2218 endpoint = of_get_next_child(port, NULL);
2219 of_node_put(port);
2220 } else {
2221 endpoint = NULL;
2222 }
2223
2224 if (!endpoint)
2225 pr_err("%s(): no endpoint nodes specified for %s\n",
2226 __func__, parent->full_name);
2227 of_node_put(node); 2217 of_node_put(node);
2228 2218
2229 return endpoint; 2219 if (!port) {
2230 } 2220 pr_err("%s(): no port node found in %s\n",
2231 2221 __func__, parent->full_name);
2232 port = of_get_parent(prev); 2222 return NULL;
2233 if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n", 2223 }
2234 __func__, prev->full_name)) 2224 } else {
2235 return NULL; 2225 port = of_get_parent(prev);
2226 if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
2227 __func__, prev->full_name))
2228 return NULL;
2236 2229
2237 /* Avoid dropping prev node refcount to 0. */ 2230 /*
2238 of_node_get(prev); 2231 * Avoid dropping prev node refcount to 0 when getting the next
2239 endpoint = of_get_next_child(port, prev); 2232 * child below.
2240 if (endpoint) { 2233 */
2241 of_node_put(port); 2234 of_node_get(prev);
2242 return endpoint;
2243 } 2235 }
2244 2236
2245 /* No more endpoints under this port, try the next one. */ 2237 while (1) {
2246 do { 2238 /*
2247 port = of_get_next_child(parent, port); 2239 * Now that we have a port node, get the next endpoint by
2248 if (!port) 2240 * getting the next child. If the previous endpoint is NULL this
2249 return NULL; 2241 * will return the first child.
2250 } while (of_node_cmp(port->name, "port")); 2242 */
2243 endpoint = of_get_next_child(port, prev);
2244 if (endpoint) {
2245 of_node_put(port);
2246 return endpoint;
2247 }
2251 2248
2252 /* Pick up the first endpoint in this port. */ 2249 /* No more endpoints under this port, try the next one. */
2253 endpoint = of_get_next_child(port, NULL); 2250 prev = NULL;
2254 of_node_put(port);
2255 2251
2256 return endpoint; 2252 do {
2253 port = of_get_next_child(parent, port);
2254 if (!port)
2255 return NULL;
2256 } while (of_node_cmp(port->name, "port"));
2257 }
2257} 2258}
2258EXPORT_SYMBOL(of_graph_get_next_endpoint); 2259EXPORT_SYMBOL(of_graph_get_next_endpoint);
2259 2260