Skip to content

Commit 34276bb

Browse files
lynxeye-devrobherring
authored andcommitted
of: fix reference counting in of_graph_get_endpoint_by_regs
The called of_graph_get_next_endpoint() already decrements the refcount of the prev node, so it is wrong to do it again in the calling function. Use the for_each_endpoint_of_node() helper to interate through the endpoint OF nodes, which already does the right thing and simplifies the code a bit. Fixes: 8ccd0d0 (of: add helper for getting endpoint node of specific identifiers) Cc: stable@vger.kernel.org Reported-by: David Jander <david@protonic.nl> Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Acked-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent fc520f8 commit 34276bb

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

drivers/of/base.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,20 +2342,13 @@ struct device_node *of_graph_get_endpoint_by_regs(
23422342
const struct device_node *parent, int port_reg, int reg)
23432343
{
23442344
struct of_endpoint endpoint;
2345-
struct device_node *node, *prev_node = NULL;
2346-
2347-
while (1) {
2348-
node = of_graph_get_next_endpoint(parent, prev_node);
2349-
of_node_put(prev_node);
2350-
if (!node)
2351-
break;
2345+
struct device_node *node = NULL;
23522346

2347+
for_each_endpoint_of_node(parent, node) {
23532348
of_graph_parse_endpoint(node, &endpoint);
23542349
if (((port_reg == -1) || (endpoint.port == port_reg)) &&
23552350
((reg == -1) || (endpoint.id == reg)))
23562351
return node;
2357-
2358-
prev_node = node;
23592352
}
23602353

23612354
return NULL;

0 commit comments

Comments
 (0)