diff mbox series

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

Message ID 20240909092825.1117058-1-ruanjinjie@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: rswitch: Fix a possible memory leak in rswitch_phy_device_init() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-10--06-00 (tests: 722)

Commit Message

Jinjie Ruan Sept. 9, 2024, 9:28 a.m. UTC
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(+)

Comments

Andrew Lunn Sept. 10, 2024, 2:44 p.m. UTC | #1
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 mbox series

Patch

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);