diff mbox series

net: ethernet: bgmac-platform: fix an OF node reference leak

Message ID 20241212023256.3453396-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: bgmac-platform: fix an OF node reference leak | expand

Commit Message

Joe Hattori Dec. 12, 2024, 2:32 a.m. UTC
The OF node obtained by of_parse_phandle() is not freed. Define a
device node with __free(device_node) to fix the leak.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: 1676aba5ef7e ("net: ethernet: bgmac: device tree phy enablement")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c
index ecce23cecbea..ca07a6d26590 100644
--- a/drivers/net/ethernet/broadcom/bgmac-platform.c
+++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
@@ -236,7 +236,10 @@  static int bgmac_probe(struct platform_device *pdev)
 	bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
 	bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
 	bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
-	if (of_parse_phandle(np, "phy-handle", 0)) {
+
+	struct device_node *phy_node __free(device_node) =
+		of_parse_phandle(np, "phy-handle", 0);
+	if (phy_node) {
 		bgmac->phy_connect = platform_phy_connect;
 	} else {
 		bgmac->phy_connect = bgmac_phy_connect_direct;