Message ID | 20240909092825.1117058-1-ruanjinjie@huawei.com (mailing list archive) |
---|---|
State | Under Review |
Delegated to: | Geert Uytterhoeven |
Headers | show |
Series | net: rswitch: Fix a possible memory leak in rswitch_phy_device_init() | expand |
On Mon, Sep 09, 2024 at 05:28:25PM +0800, Jinjie Ruan wrote: > 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@huawei.com> > --- > 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); This has the same problem as discussed in net: ethernet: nxp: Fix a possible memory leak in lpc_mii_probe() I've not looked to see if there are more of these 'fixes'. If there are, it would be good to self NACK them so they don't get accidentally merged. Andrew --- pw-bot: cr
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);
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@huawei.com> --- drivers/net/ethernet/renesas/rswitch.c | 1 + 1 file changed, 1 insertion(+)