net: ethernet: fix device leaks
Subsystems (9)
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
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.
--- 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
@@ -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
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 [email protected] # 4.19Cc Yangbo Lu <[email protected]>Signed-off-by Johan Hovold <[email protected]>
PATCH 2/5 net: enetc: fix device and OF node leak at probe
In reply to Johan HovoldMake 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.
--- 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
@@ -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
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()andof_find_device_by_node()during probe.Fixes e7d48e5fbf30 ("net: enetc: add a mini driver for the Integrated Endpoint Register Block")Cc [email protected] # 5.13Cc Vladimir Oltean <[email protected]>Signed-off-by Johan Hovold <[email protected]>
PATCH 3/5 net: gianfar: fix device leak when querying time stamp info
In reply to Johan HovoldMake 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.
--- drivers/net/ethernet/freescale/gianfar_ethtool.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/gianfar_ethtool.c +3 -1
@@ -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
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 [email protected] # 4.18Cc Yangbo Lu <[email protected]>Signed-off-by Johan Hovold <[email protected]>
PATCH 4/5 net: mtk_eth_soc: fix device leak at probe
In reply to Johan HovoldThe 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.
--- drivers/net/ethernet/mediatek/mtk_wed.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +0 -1
@@ -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
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 [email protected] # 5.19Cc Felix Fietkau <[email protected]>Signed-off-by Johan Hovold <[email protected]>
PATCH 5/5 net: ti: icss-iep: fix device and OF node leaks at probe
In reply to Johan HovoldMake 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().
--- 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
@@ -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
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()andof_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 [email protected] # 6.6Cc Roger Quadros <[email protected]>Signed-off-by Johan Hovold <[email protected]>
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