[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220921133245.4111672-1-windhl@126.com>
Date: Wed, 21 Sep 2022 21:32:45 +0800
From: Liang He <windhl@....com>
To: tchornyi@...vell.com, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, linux@...linux.org.uk,
netdev@...r.kernel.org
Cc: windhl@....com, yevhen.orlov@...ision.eu,
taras.chornyi@...ision.eu, oleksandr.mazur@...ision.eu
Subject: [PATCH] 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")
Signed-off-by: Liang He <windhl@....com>
---
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(+)
diff --git a/drivers/net/ethernet/marvell/prestera/prestera_main.c b/drivers/net/ethernet/marvell/prestera/prestera_main.c
index ede3e53b9790..a895862b4821 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_main.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_main.c
@@ -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;
}
--
2.25.1
Powered by blists - more mailing lists