public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: renesas: rswitch: Fix memory leak in rswitch_phy_device_init()
@ 2026-03-30  7:35 Ma Ke
  2026-03-30  7:59 ` Nikita Yushchenko
  2026-03-30 22:01 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Ma Ke @ 2026-03-30  7:35 UTC (permalink / raw)
  To: yoshihiro.shimoda.uh, andrew+netdev, davem, edumazet, kuba,
	pabeni, niklas.soderlund+renesas, michael.dege, nikita.yoush,
	yury.norov, geert+renesas
  Cc: netdev, linux-renesas-soc, linux-kernel, Ma Ke, stable

rswitch_phy_device_init() calls of_phy_find_device(), which calls
bus_find_device() to increments the refcount of the returned device.
The current implementation does not decrement the refcount after the
reference is no longer needed, causing a memory leak.

Add phy_device_free() to release the reference via put_device() and
balance the refcount.

Found by code review.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Cc: stable@vger.kernel.org
Fixes: 0df024d0f1d3 ("net: renesas: rswitch: Add host_interfaces setting")
---
 drivers/net/ethernet/renesas/rswitch_main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c
index 6fe964816322..126da0371a19 100644
--- a/drivers/net/ethernet/renesas/rswitch_main.c
+++ b/drivers/net/ethernet/renesas/rswitch_main.c
@@ -1459,7 +1459,7 @@ static void rswitch_phy_remove_link_mode(struct rswitch_device *rdev,
 
 static int rswitch_phy_device_init(struct rswitch_device *rdev)
 {
-	struct phy_device *phydev;
+	struct phy_device *phydev, *tmp_phydev;
 	struct device_node *phy;
 	int err = -ENOENT;
 
@@ -1473,14 +1473,18 @@ static int rswitch_phy_device_init(struct rswitch_device *rdev)
 	/* Set phydev->host_interfaces before calling of_phy_connect() to
 	 * configure the PHY with the information of host_interfaces.
 	 */
-	phydev = of_phy_find_device(phy);
-	if (!phydev)
+	tmp_phydev = of_phy_find_device(phy);
+	if (!tmp_phydev)
 		goto out;
-	__set_bit(rdev->etha->phy_interface, phydev->host_interfaces);
+	__set_bit(rdev->etha->phy_interface, tmp_phydev->host_interfaces);
 	phydev->mac_managed_pm = true;
 
 	phydev = of_phy_connect(rdev->ndev, phy, rswitch_adjust_link, 0,
 				rdev->etha->phy_interface);
+
+	/* Release the temporary reference obtained by of_phy_find_device() */
+	phy_device_free(tmp_phydev);
+
 	if (!phydev)
 		goto out;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-30 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30  7:35 [PATCH] net: renesas: rswitch: Fix memory leak in rswitch_phy_device_init() Ma Ke
2026-03-30  7:59 ` Nikita Yushchenko
2026-03-30 22:01 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox