[PATCH] net: ethernet: nxp: Fix a possible memory leak in lpc_mii_probe()
Jinjie Ruan
ruanjinjie at huawei.com
Mon Sep 9 02:29:48 PDT 2024
of_phy_find_device() calls bus_find_device(), which calls get_device()
on the returned struct device * to increment the refcount. The current
implementation does not decrement the refcount, which causes memory leak.
So add the missing phy_device_free() call to decrement the
refcount via put_device() to balance the refcount.
Fixes: 3503bf024b3e ("net: lpc_eth: parse phy nodes from device tree")
Signed-off-by: Jinjie Ruan <ruanjinjie at huawei.com>
---
drivers/net/ethernet/nxp/lpc_eth.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
index dd3e58a1319c..8bff394991e4 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -768,6 +768,9 @@ static int lpc_mii_probe(struct net_device *ndev)
return -ENODEV;
}
+ if (pldat->phy_node)
+ phy_device_free(phydev);
+
phydev = phy_connect(ndev, phydev_name(phydev),
&lpc_handle_link_change,
lpc_phy_interface_mode(&pldat->pdev->dev));
--
2.34.1
More information about the linux-arm-kernel
mailing list