Skip to content

Commit

Permalink
net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()
Browse files Browse the repository at this point in the history
In prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should call of_node_get() before of_find_node_by_name() as
it will automaitcally decrease the refcount of 'from' argument;
(2) we should call of_node_put() for the break of the iteration
for_each_child_of_node() as it will automatically increase and
decrease the 'child'.

Fixes: 52323ef ("net: marvell: prestera: add phylink support")
Signed-off-by: Liang He <[email protected]>
Reviewed-by: Yevhen Orlov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
windhl authored and kuba-moo committed Sep 22, 2022
1 parent c2e1cfe commit 3aac7ad
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/net/ethernet/marvell/prestera/prestera_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)
if (!sw->np)
return 0;

of_node_get(sw->np);
ports = of_find_node_by_name(sw->np, "ports");

for_each_child_of_node(ports, node) {
Expand Down Expand Up @@ -417,6 +418,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)
}

out:
of_node_put(node);
of_node_put(ports);
return err;
}
Expand Down

0 comments on commit 3aac7ad

Please sign in to comment.