[PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
From: Yige Jiang
Date: Thu Nov 26 2026 - 07:25:20 EST
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.
Fixes: 3933961682a3 ("fsl/fman: Add FMan MAC driver")
Link: https://lore.kernel.org/r/20260703074324.907294-1-zhaojinming@xxxxxxxxxxxxx
Signed-off-by: Yige Jiang <yigejiang86@xxxxxxxxx>
---
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(-)
diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
index 46cc28895e56..35a8e25ba993 100644
--- a/drivers/net/ethernet/freescale/fman/fman.c
+++ b/drivers/net/ethernet/freescale/fman/fman.c
@@ -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);
diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c
index 1b8fef69114e..5d96521066a5 100644
--- a/drivers/net/ethernet/freescale/fman/fman_port.c
+++ b/drivers/net/ethernet/freescale/fman/fman_port.c
@@ -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
--
2.50.1 (Apple Git-155)