Skip to contentSkip to conversation

net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()

PATCH Applied Liang He 3 participants 3 messages Sep 21, 2022 – Sep 22, 2022

Subsystems (3)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()

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 52323ef75414 ("net: marvell: prestera: add phylink support")

---
it will be safe to call of_node_put() at the end of the function as
the of_node_put() can handle NULL.

 drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_main.c +2 -0
index ede3e53b9790..a895862b4821 100644
@@ -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) {
@@ -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;
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Liang He

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'.

Quoted 9 lines
Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")

---
it will be safe to call of_node_put() at the end of the function as
the of_node_put() can handle NULL.

 drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 ++
 1 file changed, 2 insertions(+)
#2 lore raw
In reply to Liang He
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 21 Sep 2022 21:32:45 +0800 you wrote:

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'.

[...]

Here is the summary with links:
- net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()

    https://git.kernel.org/netdev/net/c/3aac7ada64d8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html