* [PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
@ 2026-11-26 12:25 Yige Jiang
2026-12-04 10:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Yige Jiang @ 2026-11-26 12:25 UTC (permalink / raw)
To: Madalin Bucur, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Yige Jiang, Sean Anderson, netdev, linux-kernel
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@uniontech.com
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
2026-11-26 12:25 [PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind() Yige Jiang
@ 2026-12-04 10:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-04 10:10 UTC (permalink / raw)
To: Yige Jiang
Cc: madalin.bucur, andrew+netdev, davem, edumazet, kuba, pabeni,
sean.anderson, netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Thu, 26 Nov 2026 20:25:02 +0800 you wrote:
> 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 10:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:25 [PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind() Yige Jiang
2026-12-04 10:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox