net: marvell: Fix refcounting bugs in prestera_port_sfp_bind()
Subsystems (3)
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'.
---
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
@@ -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
Quoted 7 lines · Liang He
In
prestera_port_sfp_bind(), there are two refcounting bugs:
(1) we should callof_node_get()beforeof_find_node_by_name()as it will automaitcally decrease the refcount of 'from' argument;
(2) we should callof_node_put()for the break of the iterationfor_each_child_of_node()as it will automatically increase and decrease the 'child'.
Quoted 9 lines
Fixes 52323ef75414 ("net: marvell: prestera: add phylink support")Signed-off-by Liang He <[email protected]>---
it will be safe to callof_node_put()at the end of the function as
theof_node_put()can handle NULL.drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 ++ 1 file changed, 2 insertions(+)
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 callof_node_get()beforeof_find_node_by_name()as it will automaitcally decrease the refcount of 'from' argument;
(2) we should callof_node_put()for the break of the iterationfor_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