Skip to contentSkip to conversation

net: ethernet: fix device leaks

PATCH Applied Johan Hovold 3 participants 12 messages Jul 25, 2025 – Jul 31, 2025

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover net: ethernet: fix device leaks

This series fixes devices leaks stemming from failure to drop the reference taken by of_find_device_by_node().

Johan

Johan Hovold (5):
net: dpaa: fix device leak when querying time stamp info
net: enetc: fix device and OF node leak at probe
net: gianfar: fix device leak when querying time stamp info
net: mtk_eth_soc: fix device leak at probe
net: ti: icss-iep: fix device and OF node leaks at probe

 .../ethernet/freescale/dpaa/dpaa_ethtool.c    |  4 +++-
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 14 +++++++++--
 .../net/ethernet/freescale/gianfar_ethtool.c  |  4 +++-
 drivers/net/ethernet/mediatek/mtk_wed.c       |  1 -
 drivers/net/ethernet/ti/icssg/icss_iep.c      | 23 +++++++++++++++----
 5 files changed, 36 insertions(+), 10 deletions(-)
Signature · 1 line
2.49.1
#1 lore raw

PATCH 1/5 net: dpaa: fix device leak when querying time stamp info

Make sure to drop the reference to the ptp device taken by of_find_device_by_node() when querying the time stamping capabilities.

Note that holding a reference to the ptp device does not prevent its driver data from going away.

Fixes 17ae0b0ee9db ("dpaa_eth: add the get_ts_info interface for ethtool")
Cc Yangbo Lu <[email protected]>
---
 drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c +3 -1
index 9986f6e1f587..7fc01baef280 100644
@@ -401,8 +401,10 @@ static int dpaa_get_ts_info(struct net_device *net_dev,
 		of_node_put(ptp_node);
 	}
 
-	if (ptp_dev)
+	if (ptp_dev) {
 		ptp = platform_get_drvdata(ptp_dev);
+		put_device(&ptp_dev->dev);
+	}
 
 	if (ptp)
 		info->phc_index = ptp->phc_index;
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] net: dpaa: fix device leak when querying time stamp info

Quoted 10 lines · Johan Hovold

Make sure to drop the reference to the ptp device taken by of_find_device_by_node() when querying the time stamping capabilities.

Note that holding a reference to the ptp device does not prevent its driver data from going away.

Fixes 17ae0b0ee9db ("dpaa_eth: add the get_ts_info interface for ethtool")
Cc Yangbo Lu <[email protected]>
#3 lore raw

PATCH 2/5 net: enetc: fix device and OF node leak at probe

In reply to Johan Hovold

Make sure to drop the references to the IERB OF node and platform device taken by of_parse_phandle() and of_find_device_by_node() during probe.

Fixes e7d48e5fbf30 ("net: enetc: add a mini driver for the Integrated Endpoint Register Block")
Cc Vladimir Oltean <[email protected]>
---
 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +12 -2
index f63a29e2e031..de0fb272c847 100644
@@ -829,19 +829,29 @@ static int enetc_pf_register_with_ierb(struct pci_dev *pdev)
 {
 	struct platform_device *ierb_pdev;
 	struct device_node *ierb_node;
+	int ret;
 
 	ierb_node = of_find_compatible_node(NULL, NULL,
 					    "fsl,ls1028a-enetc-ierb");
-	if (!ierb_node || !of_device_is_available(ierb_node))
+	if (!ierb_node)
 		return -ENODEV;
 
+	if (!of_device_is_available(ierb_node)) {
+		of_node_put(ierb_node);
+		return -ENODEV;
+	}
+
 	ierb_pdev = of_find_device_by_node(ierb_node);
 	of_node_put(ierb_node);
 
 	if (!ierb_pdev)
 		return -EPROBE_DEFER;
 
-	return enetc_ierb_register_pf(ierb_pdev, pdev);
+	ret = enetc_ierb_register_pf(ierb_pdev, pdev);
+
+	put_device(&ierb_pdev->dev);
+
+	return ret;
 }
 
 static const struct enetc_si_ops enetc_psi_ops = {
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] net: enetc: fix device and OF node leak at probe

Quoted 7 lines · Johan Hovold

Make sure to drop the references to the IERB OF node and platform device taken by of_parse_phandle() and of_find_device_by_node() during probe.

Fixes e7d48e5fbf30 ("net: enetc: add a mini driver for the Integrated Endpoint Register Block")
Cc Vladimir Oltean <[email protected]>
#5 lore raw

PATCH 3/5 net: gianfar: fix device leak when querying time stamp info

In reply to Johan Hovold

Make sure to drop the reference to the ptp device taken by of_find_device_by_node() when querying the time stamping capabilities.

Note that holding a reference to the ptp device does not prevent its driver data from going away.

Fixes 7349a74ea75c ("net: ethernet: gianfar_ethtool: get phc index through drvdata")
Cc Yangbo Lu <[email protected]>
---
 drivers/net/ethernet/freescale/gianfar_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +3 -1
index 781d92e703cb..c9992ed4e301 100644
@@ -1466,8 +1466,10 @@ static int gfar_get_ts_info(struct net_device *dev,
 	if (ptp_node) {
 		ptp_dev = of_find_device_by_node(ptp_node);
 		of_node_put(ptp_node);
-		if (ptp_dev)
+		if (ptp_dev) {
 			ptp = platform_get_drvdata(ptp_dev);
+			put_device(&ptp_dev->dev);
+		}
 	}
 
 	if (ptp)
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] net: gianfar: fix device leak when querying time stamp info

Quoted 10 lines · Johan Hovold

Make sure to drop the reference to the ptp device taken by of_find_device_by_node() when querying the time stamping capabilities.

Note that holding a reference to the ptp device does not prevent its driver data from going away.

Fixes 7349a74ea75c ("net: ethernet: gianfar_ethtool: get phc index through drvdata")
Cc Yangbo Lu <[email protected]>
#7 lore raw

PATCH 4/5 net: mtk_eth_soc: fix device leak at probe

In reply to Johan Hovold

The reference count to the WED devices has already been incremented when looking them up using of_find_device_by_node() so drop the bogus additional reference taken during probe.

Fixes 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
Cc Felix Fietkau <[email protected]>
---
 drivers/net/ethernet/mediatek/mtk_wed.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +0 -1
index 351dd152f4f3..4f3014fc389b 100644
@@ -2794,7 +2794,6 @@ void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
 	if (!pdev)
 		goto err_of_node_put;
 
-	get_device(&pdev->dev);
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		goto err_put_device;
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] net: mtk_eth_soc: fix device leak at probe

Quoted 8 lines · Johan Hovold

The reference count to the WED devices has already been incremented when looking them up using of_find_device_by_node() so drop the bogus additional reference taken during probe.

Fixes 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
Cc Felix Fietkau <[email protected]>
#9 lore raw

PATCH 5/5 net: ti: icss-iep: fix device and OF node leaks at probe

In reply to Johan Hovold

Make sure to drop the references to the IEP OF node and device taken by of_parse_phandle() and of_find_device_by_node() when looking up IEP devices during probe.

Drop the bogus additional reference taken on successful lookup so that the device is released correctly by icss_iep_put().

Fixes c1e0230eeaab ("net: ti: icss-iep: Add IEP driver")
Cc Roger Quadros <[email protected]>
---
 drivers/net/ethernet/ti/icssg/icss_iep.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssg/icss_iep.c +18 -5
index 2a1c43316f46..50bfbc2779e4 100644
@@ -685,11 +685,17 @@ struct icss_iep *icss_iep_get_idx(struct device_node *np, int idx)
 	struct platform_device *pdev;
 	struct device_node *iep_np;
 	struct icss_iep *iep;
+	int ret;
 
 	iep_np = of_parse_phandle(np, "ti,iep", idx);
-	if (!iep_np || !of_device_is_available(iep_np))
+	if (!iep_np)
 		return ERR_PTR(-ENODEV);
 
+	if (!of_device_is_available(iep_np)) {
+		of_node_put(iep_np);
+		return ERR_PTR(-ENODEV);
+	}
+
 	pdev = of_find_device_by_node(iep_np);
 	of_node_put(iep_np);
 
@@ -698,21 +704,28 @@ struct icss_iep *icss_iep_get_idx(struct device_node *np, int idx)
 		return ERR_PTR(-EPROBE_DEFER);
 
 	iep = platform_get_drvdata(pdev);
-	if (!iep)
-		return ERR_PTR(-EPROBE_DEFER);
+	if (!iep) {
+		ret = -EPROBE_DEFER;
+		goto err_put_pdev;
+	}
 
 	device_lock(iep->dev);
 	if (iep->client_np) {
 		device_unlock(iep->dev);
 		dev_err(iep->dev, "IEP is already acquired by %s",
 			iep->client_np->name);
-		return ERR_PTR(-EBUSY);
+		ret = -EBUSY;
+		goto err_put_pdev;
 	}
 	iep->client_np = np;
 	device_unlock(iep->dev);
-	get_device(iep->dev);
 
 	return iep;
+
+err_put_pdev:
+	put_device(&pdev->dev);
+
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(icss_iep_get_idx);
 
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 5/5
#10 lore raw

Re: [PATCH 5/5] net: ti: icss-iep: fix device and OF node leaks at probe

Quoted 11 lines · Johan Hovold

Make sure to drop the references to the IEP OF node and device taken by of_parse_phandle() and of_find_device_by_node() when looking up IEP devices during probe.

Drop the bogus additional reference taken on successful lookup so that the device is released correctly by icss_iep_put().

Fixes c1e0230eeaab ("net: ti: icss-iep: Add IEP driver")
Cc Roger Quadros <[email protected]>
#11 lore raw
In reply to Johan Hovold
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Fri, 25 Jul 2025 19:12:08 +0200 you wrote:

This series fixes devices leaks stemming from failure to drop the reference taken by of_find_device_by_node().

Johan

Quoted 8 lines

Johan Hovold (5):
net: dpaa: fix device leak when querying time stamp info
net: enetc: fix device and OF node leak at probe
net: gianfar: fix device leak when querying time stamp info
net: mtk_eth_soc: fix device leak at probe
net: ti: icss-iep: fix device and OF node leaks at probe

[...]

Here is the summary with links:
- [1/5] net: dpaa: fix device leak when querying time stamp info

    https://git.kernel.org/netdev/net/c/3fa840230f53
  - [2/5] net: enetc: fix device and OF node leak at probe
    https://git.kernel.org/netdev/net/c/70458f8a6b44
  - [3/5] net: gianfar: fix device leak when querying time stamp info
    https://git.kernel.org/netdev/net/c/da717540acd3
  - [4/5] net: mtk_eth_soc: fix device leak at probe
    https://git.kernel.org/netdev/net/c/3e13274ca875
  - [5/5] net: ti: icss-iep: fix device and OF node leaks at probe
    https://git.kernel.org/netdev/net/c/e05c54974a05

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html