mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
[media] v4l: of: Support empty port nodes
Empty port nodes are allowed but currently unsupported as the v4l2_of_get_next_endpoint() function assumes that all port nodes have at least an endpoint. Fix this. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
This commit is contained in:
parent
bb60fcb29b
commit
b9db140c1e
@ -166,43 +166,51 @@ struct device_node *v4l2_of_get_next_endpoint(const struct device_node *parent,
|
|||||||
struct device_node *prev)
|
struct device_node *prev)
|
||||||
{
|
{
|
||||||
struct device_node *endpoint;
|
struct device_node *endpoint;
|
||||||
struct device_node *port = NULL;
|
struct device_node *port;
|
||||||
|
|
||||||
if (!parent)
|
if (!parent)
|
||||||
return NULL;
|
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) {
|
if (!prev) {
|
||||||
struct device_node *node;
|
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");
|
node = of_get_child_by_name(parent, "ports");
|
||||||
if (node)
|
if (node)
|
||||||
parent = node;
|
parent = node;
|
||||||
|
|
||||||
port = of_get_child_by_name(parent, "port");
|
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);
|
of_node_put(node);
|
||||||
|
|
||||||
|
if (!port) {
|
||||||
|
pr_err("%s(): no port node found in %s\n",
|
||||||
|
__func__, parent->full_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
port = of_get_parent(prev);
|
port = of_get_parent(prev);
|
||||||
if (!port)
|
if (!port) {
|
||||||
/* Hm, has someone given us the root node ?... */
|
/* Hm, has someone given us the root node ?... */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Avoid dropping prev node refcount to 0. */
|
/*
|
||||||
|
* Avoid dropping prev node refcount to 0 when getting the next
|
||||||
|
* child below.
|
||||||
|
*/
|
||||||
of_node_get(prev);
|
of_node_get(prev);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
endpoint = of_get_next_child(port, prev);
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
of_node_put(port);
|
of_node_put(port);
|
||||||
@ -210,18 +218,14 @@ struct device_node *v4l2_of_get_next_endpoint(const struct device_node *parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No more endpoints under this port, try the next one. */
|
/* No more endpoints under this port, try the next one. */
|
||||||
|
prev = NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
port = of_get_next_child(parent, port);
|
port = of_get_next_child(parent, port);
|
||||||
if (!port)
|
if (!port)
|
||||||
return NULL;
|
return NULL;
|
||||||
} while (of_node_cmp(port->name, "port"));
|
} while (of_node_cmp(port->name, "port"));
|
||||||
|
|
||||||
/* Pick up the first endpoint in this port. */
|
|
||||||
endpoint = of_get_next_child(port, NULL);
|
|
||||||
of_node_put(port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return endpoint;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(v4l2_of_get_next_endpoint);
|
EXPORT_SYMBOL(v4l2_of_get_next_endpoint);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user