From: Ma Ke <make24@iscas.ac.cn>
To: yoshihiro.shimoda.uh@renesas.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, niklas.soderlund+renesas@ragnatech.se,
michael.dege@renesas.com, nikita.yoush@cogentembedded.com,
yury.norov@gmail.com, geert+renesas@glider.be
Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org, Ma Ke <make24@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] net: renesas: rswitch: Fix memory leak in rswitch_phy_device_init()
Date: Mon, 30 Mar 2026 15:35:41 +0800 [thread overview]
Message-ID: <20260330073541.2871414-1-make24@iscas.ac.cn> (raw)
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
next reply other threads:[~2026-03-30 7:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 7:35 Ma Ke [this message]
2026-03-30 7:59 ` [PATCH] net: renesas: rswitch: Fix memory leak in rswitch_phy_device_init() Nikita Yushchenko
2026-03-30 22:01 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260330073541.2871414-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=geert+renesas@glider.be \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=michael.dege@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=nikita.yoush@cogentembedded.com \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=yoshihiro.shimoda.uh@renesas.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox