Skip to contentSkip to conversation

fsl/fman: Drop device references when dpaa_eth_add_device() fails

PATCH In review Yige Jiang 3 participants 4 messages Nov 26 – Dec 4

Subsystems (3)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH 1/1 fsl/fman: Drop device references when dpaa_eth_add_device() fails

When dpaa_eth_add_device() fails at the end of mac_probe(), the error is returned directly. This skips the _return_dev_arr_put and _return_dev_put labels, so the references held on the FMan device and on both FMan port devices are never dropped. mac_remove() would drop them, but it does not run after a failed probe.

Jump to _return_dev_arr_put instead, as the init() failure above does. The devices are created from the device tree and are not normally removed, so the leaked references have no visible effect in practice. The MAC state allocated by init() is still not freed on this path, as in mac_remove(); that needs a separate change.

Fixes 1dec67e0d9fb ("fsl/fman: Fix refcount handling of fman-related devices")

---
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 mac.o, no new warnings. No hardware or runtime test was performed.

The path needs dpaa_eth_add_device() to fail (allocation failure or a platform_device_add() error) after the MAC was initialized.

 drivers/net/ethernet/freescale/fman/mac.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/fman/mac.c +1 -0
index 29c2fa2be837..4180cec15c0f 100644
@@ -307,6 +307,7 @@ static int mac_probe(struct platform_device *_of_dev)
 		dev_err(dev, "failed to add Ethernet platform device for MAC %d\n",
 			priv->cell_index);
 		priv->eth_dev = NULL;
+		goto _return_dev_arr_put;
 	}
 
 	return err;

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
author
#2 lore raw

Hi,

A static analysis warning about of_node_put() led me to look at mac_probe(). The warning was a false positive. During an LLM-assisted review of the surrounding error paths, I found that a failure in dpaa_eth_add_device() bypasses the cleanup for the FMan device and both port devices.

I compile-tested the fix on arm64 but did not reproduce the leak at runtime.

Thanks,
Yige

Quoted 20 lines · On Nov 26, 2026, at 5:42 PM, [email protected] wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
maintainer
#3 lore raw
In reply to Yige Jiang
Quoted 6 lines · Yige Jiang

When dpaa_eth_add_device() fails at the end of mac_probe(), the error is returned directly. This skips the _return_dev_arr_put and _return_dev_put labels, so the references held on the FMan device and on both FMan port devices are never dropped. mac_remove() would drop them, but it does not run after a failed probe.

Quoted 8 lines

Jump to _return_dev_arr_put instead, as the init() failure above does. The devices are created from the device tree and are not normally removed, so the leaked references have no visible effect in practice. The MAC state allocated by init() is still not freed on this path, as in mac_remove(); that needs a separate change.

Fixes 1dec67e0d9fb ("fsl/fman: Fix refcount handling of fman-related devices")

The same error path has more issues, please address all of them together:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

/P