[PATCH] net: fman: drop the FMan device reference after port probe

From: Wentao Liang

Date: Tue Nov 03 2026 - 05:22:19 EST


fman_port_probe() looks up the parent FMan platform device with
of_find_device_by_node(), which takes a reference on the embedded
struct device. The reference is released on the error paths, but not
after a successful probe, and the __devm_request_region() failure path
jumps directly to freeing the port.

As a result the reference is never dropped. Put the FMan device and
the port node before returning success, and route the failed region
request through the existing cleanup labels as well.

Fixes: 18a6c85fcc78 ("fsl/fman: Add FMan Port Support")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/net/ethernet/freescale/fman/fman_port.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c
index 1b8fef69114e..faf1e35399cd 100644
--- a/drivers/net/ethernet/freescale/fman/fman_port.c
+++ b/drivers/net/ethernet/freescale/fman/fman_port.c
@@ -1850,15 +1850,13 @@ static int fman_port_probe(struct platform_device *of_dev)

port->dts_params.fman = fman;

- of_node_put(port_node);
-
dev_res = __devm_request_region(port->dev, &res, res.start,
resource_size(&res), "fman-port");
if (!dev_res) {
dev_err(port->dev, "%s: __devm_request_region() failed\n",
__func__);
err = -EINVAL;
- goto free_port;
+ goto put_device;
}

port->dts_params.base_addr = devm_ioremap(port->dev, res.start,
@@ -1868,13 +1866,14 @@ static int fman_port_probe(struct platform_device *of_dev)

dev_set_drvdata(&of_dev->dev, port);

+ of_node_put(port_node);
+ put_device(&fm_pdev->dev);
return 0;

put_device:
put_device(&fm_pdev->dev);
return_err:
of_node_put(port_node);
-free_port:
kfree(port);
return err;
}
--
2.34.1