From: Ma Ke <make24@iscas.ac.cn>
To: vz@mleia.com, piotr.wojtaszczyk@timesys.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
alexandre.belloni@bootlin.com
Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Ma Ke <make24@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] net: lpc_eth: Fix a possible memory leak in lpc_mii_probe()
Date: Mon, 30 Mar 2026 16:16:36 +0800 [thread overview]
Message-ID: <20260330081636.2887980-1-make24@iscas.ac.cn> (raw)
lpc_mii_probe() calls of_phy_find_device() to obtain a phy_device
pointer. of_phy_find_device() increments the refcount of the device.
The current implementation does not decrement the refcount after using
the pointer, which leads to a memory leak.
Add phy_device_free() to balance the refcount.
Found by code review.
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Cc: stable@vger.kernel.org
Fixes: 3503bf024b3e ("net: lpc_eth: parse phy nodes from device tree")
---
drivers/net/ethernet/nxp/lpc_eth.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
index 8b9a3e3bba30..8ce7c9bb6dd6 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -751,7 +751,7 @@ static void lpc_handle_link_change(struct net_device *ndev)
static int lpc_mii_probe(struct net_device *ndev)
{
struct netdata_local *pldat = netdev_priv(ndev);
- struct phy_device *phydev;
+ struct phy_device *phydev, *phydev_tmp;
/* Attach to the PHY */
if (lpc_phy_interface_mode(&pldat->pdev->dev) == PHY_INTERFACE_MODE_MII)
@@ -760,17 +760,18 @@ static int lpc_mii_probe(struct net_device *ndev)
netdev_info(ndev, "using RMII interface\n");
if (pldat->phy_node)
- phydev = of_phy_find_device(pldat->phy_node);
+ phydev_tmp = of_phy_find_device(pldat->phy_node);
else
- phydev = phy_find_first(pldat->mii_bus);
- if (!phydev) {
+ phydev_tmp = phy_find_first(pldat->mii_bus);
+ if (!phydev_tmp) {
netdev_err(ndev, "no PHY found\n");
return -ENODEV;
}
- phydev = phy_connect(ndev, phydev_name(phydev),
+ phydev = phy_connect(ndev, phydev_name(phydev_tmp),
&lpc_handle_link_change,
lpc_phy_interface_mode(&pldat->pdev->dev));
+ phy_device_free(phydev_tmp);
if (IS_ERR(phydev)) {
netdev_err(ndev, "Could not attach to PHY\n");
return PTR_ERR(phydev);
--
2.43.0
next reply other threads:[~2026-03-30 8:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 8:16 Ma Ke [this message]
2026-03-30 10:04 ` [PATCH] net: lpc_eth: Fix a possible memory leak in lpc_mii_probe() Vladimir Zapolskiy
2026-03-31 0:43 ` Ma Ke
2026-04-01 13:18 ` Ma Ke
2026-04-07 20:58 ` Vladimir Zapolskiy
2026-04-20 3:24 ` Ma Ke
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=20260330081636.2887980-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=alexandre.belloni@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=piotr.wojtaszczyk@timesys.com \
--cc=stable@vger.kernel.org \
--cc=vz@mleia.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