fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
Subsystems (3)
PATCH 1/1 fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
fman_bind() and fman_port_bind() call get_device() and return the device's driver data. They keep the reference even when the driver data is NULL, which happens when mac_probe() runs before the FMan or FMan port driver has set it. mac_probe() then fails and drops only the reference from its own of_find_device_by_node() call, so the reference taken by the bind helper is leaked on each such probe.
The FMan and port devices are created from the device tree and are not normally removed, so the leak has no visible effect in practice. The NULL return on the FMan side was pointed out as a probe ordering problem in a Sashiko review that Simon Horman forwarded to netdev in July 2026. The reference leak was not mentioned there.
Drop the reference in both helpers when they return NULL. mac_probe() is their only caller, and its success path is unchanged.
---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_FSL_FMAN=y, CONFIG_FSL_DPAA=y, CONFIG_COMPILE_TEST=y; baseline and patched fman.o and fman_port.o, no new warnings. No hardware or runtime test was performed.
The path needs mac_probe() to run before the FMan or FMan port device has its driver data set (probe ordering or module load order).
drivers/net/ethernet/freescale/fman/fman.c | 7 ++++++- drivers/net/ethernet/freescale/fman/fman_port.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fman/fman.c +6 -1
@@ -2493,7 +2493,12 @@ EXPORT_SYMBOL(fman_get_rx_extra_headroom);*/ struct fman *fman_bind (struct device *fm_dev) { -return (struct fman *)(dev_get_drvdata (get_device (fm_dev))); +struct fman *fman =dev_get_drvdata (get_device (fm_dev)); + +if (!fman) +put_device (fm_dev); + +return fman; }EXPORT_SYMBOL (fman_bind);
drivers/net/ethernet/freescale/fman/fman_port.c +6 -1
@@ -1684,7 +1684,12 @@ EXPORT_SYMBOL(fman_port_enable);*/ struct fman_port *fman_port_bind (struct device *dev) { -return (struct fman_port *)(dev_get_drvdata (get_device (dev))); +struct fman_port *port =dev_get_drvdata (get_device (dev)); + +if (!port) +put_device (dev); + +return port; }EXPORT_SYMBOL (fman_port_bind);
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
Signature · 1 line
2.50.1 (Apple Git-155)
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Thu, 26 Nov 2026 20:25:02 +0800 you wrote:
fman_bind()andfman_port_bind()callget_device()and return the device's driver data. They keep the reference even when the driver data is NULL, which happens whenmac_probe()runs before the FMan or FMan port driver has set it.mac_probe()then fails and drops only the reference from its ownof_find_device_by_node()call, so the reference taken by the bind helper is leaked on each such probe.[...]
Here is the summary with links:
- [net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
https://git.kernel.org/netdev/net-next/c/8a3d0368f58e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html