[PATCH] net: ethernet: renesas: rswitch: fix device_node refcount leak in rswitch_get_port_node()

Manush Prajwal <[email protected]>
Newsgroups org.kernel.vger.linux-renesas-soc,org.kernel.vger.netdev
Message-ID <[email protected]>
On an of_property_read_u32() failure, rswitch_get_port_node() sets
port to NULL and jumps to the out label before releasing the
reference the for_each_available_child_of_node() iterator was holding
on it. Once port is overwritten with NULL, that reference can never be
released since out: only puts "ports", the parent node. Call
of_node_put(port) before clearing it.

Signed-off-by: Manush Prajwal <[email protected]>
---
 drivers/net/ethernet/renesas/rswitch_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c
index 6fe9648163..ffdc42f430 100644
--- a/drivers/net/ethernet/renesas/rswitch_main.c
+++ b/drivers/net/ethernet/renesas/rswitch_main.c
@@ -1315,6 +1315,7 @@ static struct device_node *rswitch_get_port_node(struct rswitch_device *rdev)
 	for_each_available_child_of_node(ports, port) {
 		err = of_property_read_u32(port, "reg", &index);
 		if (err < 0) {
+			of_node_put(port);
 			port = NULL;
 			goto out;
 		}
-- 
2.46.2.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.