Skip to contentSkip to conversation

net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds

PATCH Applied Miaoqian Lin 4 participants 4 messages Sep 1, 2025 – Sep 3, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds

Fix multiple fwnode reference leaks:

1. The function calls fwnode_get_named_child_node() to get the "leds" node, but never calls fwnode_handle_put(leds) to release this reference.

2. Within the fwnode_for_each_child_node() loop, the early return paths that don't properly release the "led" fwnode reference.

This fix follows the same pattern as commit d029edefed39 ("net dsa: qca8k: fix usages of device_get_named_child_node()")

Fixes 94a2a84f5e9e ("net: dsa: mv88e6xxx: Support LED control")

---
changes in v2:
- use goto for cleanup in error paths
- v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/net/dsa/mv88e6xxx/leds.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/dsa/mv88e6xxx/leds.c +13 -4
index 1c88bfaea46b..ab3bc645da56 100644
@@ -779,7 +779,8 @@ int mv88e6xxx_port_setup_leds(struct mv88e6xxx_chip *chip, int port)
 			continue;
 		if (led_num > 1) {
 			dev_err(dev, "invalid LED specified port %d\n", port);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err_put_led;
 		}
 
 		if (led_num == 0)
@@ -823,17 +824,25 @@ int mv88e6xxx_port_setup_leds(struct mv88e6xxx_chip *chip, int port)
 		init_data.devname_mandatory = true;
 		init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d:0%d", chip->info->name,
 						 port, led_num);
-		if (!init_data.devicename)
-			return -ENOMEM;
+		if (!init_data.devicename) {
+			ret = -ENOMEM;
+			goto err_put_led;
+		}
 
 		ret = devm_led_classdev_register_ext(dev, l, &init_data);
 		kfree(init_data.devicename);
 
 		if (ret) {
 			dev_err(dev, "Failed to init LED %d for port %d", led_num, port);
-			return ret;
+			goto err_put_led;
 		}
 	}
 
+	fwnode_handle_put(leds);
 	return 0;
+
+err_put_led:
+	fwnode_handle_put(led);
+	fwnode_handle_put(leds);
+	return ret;
 }
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Miaoqian Lin

Fix multiple fwnode reference leaks:

1. The function calls fwnode_get_named_child_node() to get the "leds" node, but never calls fwnode_handle_put(leds) to release this reference.

2. Within the fwnode_for_each_child_node() loop, the early return paths that don't properly release the "led" fwnode reference.

This fix follows the same pattern as commit d029edefed39 ("net dsa: qca8k: fix usages of device_get_named_child_node()")

Quoted 7 lines
Fixes 94a2a84f5e9e ("net: dsa: mv88e6xxx: Support LED control")

---
changes in v2:
- use goto for cleanup in error paths
- v1: https://lore.kernel.org/all/[email protected]/

When I coded it I honestly believed fwnode_get_named_child_node() also released the children after use but apparently not, my bad :(

Yours,
Linus Walleij

#2 lore raw
In reply to Miaoqian Lin
Quoted 1 line

Fix multiple fwnode reference leaks:

…

* How do you think about to complete the object clean-up by using a better goto chain?

* Would it be helpful to append parentheses to the function name in the summary phrase?

Regards,
Markus

#3 lore raw
In reply to Miaoqian Lin
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 1 Sep 2025 15:32:23 +0800 you wrote:

Fix multiple fwnode reference leaks:

1. The function calls fwnode_get_named_child_node() to get the "leds" node, but never calls fwnode_handle_put(leds) to release this reference.

2. Within the fwnode_for_each_child_node() loop, the early return paths that don't properly release the "led" fwnode reference.

[...]

Here is the summary with links:
- [v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds

    https://git.kernel.org/netdev/net/c/f63e7c8a8389

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html