[PATCH] net: rswitch: Fix a possible memory leak in rswitch_phy_device_init()

From: Jinjie Ruan
Date: Mon Sep 09 2024 - 05:22:53 EST


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: 0df024d0f1d3 ("net: renesas: rswitch: Add host_interfaces setting")
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
drivers/net/ethernet/renesas/rswitch.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c
index ff50e20856ec..69a67bd75f33 100644
--- a/drivers/net/ethernet/renesas/rswitch.c
+++ b/drivers/net/ethernet/renesas/rswitch.c
@@ -1404,6 +1404,7 @@ static int rswitch_phy_device_init(struct rswitch_device *rdev)
goto out;
__set_bit(rdev->etha->phy_interface, phydev->host_interfaces);
phydev->mac_managed_pm = true;
+ phy_device_free(phydev);

phydev = of_phy_connect(rdev->ndev, phy, rswitch_adjust_link, 0,
rdev->etha->phy_interface);
--
2.34.1