* [PATCH] net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register()
@ 2024-08-02 8:54 Joe Hattori
2024-08-05 23:32 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Joe Hattori @ 2024-08-02 8:54 UTC (permalink / raw)
To: andrew, olteanv, davem, edumazet, kuba, pabeni; +Cc: netdev, Joe Hattori
bcm_sf2_mdio_register() calls of_phy_find_device() and then
phy_device_remove() in a loop to remove existing PHY devices.
of_phy_find_device() eventually 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.
This commit adds the missing phy_device_free() call to decrement the
refcount via put_device() to balance the refcount.
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
drivers/net/dsa/bcm_sf2.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index ed1e6560df25..0e663ec0c12a 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -675,8 +675,10 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds)
of_remove_property(child, prop);
phydev = of_phy_find_device(child);
- if (phydev)
+ if (phydev) {
phy_device_remove(phydev);
+ phy_device_free(phydev);
+ }
}
err = mdiobus_register(priv->user_mii_bus);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register()
2024-08-02 8:54 [PATCH] net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register() Joe Hattori
@ 2024-08-05 23:32 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-08-05 23:32 UTC (permalink / raw)
To: Joe Hattori; +Cc: andrew, olteanv, davem, edumazet, pabeni, netdev
On Fri, 2 Aug 2024 17:54:11 +0900 Joe Hattori wrote:
> bcm_sf2_mdio_register() calls of_phy_find_device() and then
> phy_device_remove() in a loop to remove existing PHY devices.
> of_phy_find_device() eventually 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.
>
> This commit adds the missing phy_device_free() call to decrement the
> refcount via put_device() to balance the refcount.
Please add a Fixes tag pointing to the commit where the problem was
introduced and make sure you CC the maintainer of the driver.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-05 23:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 8:54 [PATCH] net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register() Joe Hattori
2024-08-05 23:32 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).