lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230706123021.8174-1-machel@vivo.com>
Date: Thu,  6 Jul 2023 20:30:11 +0800
From: Wang Ming <machel@...o.com>
To: Sunil Goutham <sgoutham@...vell.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	linux-arm-kernel@...ts.infradead.org,
	netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: opensource.kernel@...o.com,
	simon.horman@...igine.com,
	Wang Ming <machel@...o.com>
Subject: [PATCH net v2] net:thunder:Fix resource leaks in device_for_each_child_node() loops

The device_for_each_child_node() loop in
bgx_init_of_phy() function should have
fwnode_handle_put() before break
which could avoid resource leaks.
This patch could fix this bug.

Signed-off-by: Wang Ming <machel@...o.com>
---
 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index a317feb8decb..f8a8b2ab72aa 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1469,6 +1469,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
 	struct fwnode_handle *fwn;
 	struct device_node *node = NULL;
 	u8 lmac = 0;
+	int err = 0;
 
 	device_for_each_child_node(&bgx->pdev->dev, fwn) {
 		struct phy_device *pd;
@@ -1479,7 +1480,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
 		 */
 		node = to_of_node(fwn);
 		if (!node)
-			break;
+			goto out_handle_put;
 
 		of_get_mac_address(node, bgx->lmac[lmac].mac);
 
@@ -1501,10 +1502,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
 		}
 
 		lmac++;
-		if (lmac == bgx->max_lmac) {
-			of_node_put(node);
-			break;
-		}
+		if (lmac == bgx->max_lmac)
+			goto out_node_put;
 	}
 	return 0;
 
@@ -1519,8 +1518,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
 		}
 		lmac--;
 	}
+	err = -EPROBE_DEFER;
+out_node_put:
 	of_node_put(node);
-	return -EPROBE_DEFER;
+out_handle_put:
+	fwnode_handle_put(fwn);
+	return err;
 }
 
 #else
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ