netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds
@ 2025-09-01  7:32 Miaoqian Lin
  2025-09-01  8:23 ` Linus Walleij
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Miaoqian Lin @ 2025-09-01  7:32 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Linus Walleij, netdev, linux-kernel
  Cc: linmq006, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- use goto for cleanup in error paths
- v1: https://lore.kernel.org/all/20250830085508.2107507-1-linmq006@gmail.com/
---
 drivers/net/dsa/mv88e6xxx/leds.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/leds.c b/drivers/net/dsa/mv88e6xxx/leds.c
index 1c88bfaea46b..ab3bc645da56 100644
--- a/drivers/net/dsa/mv88e6xxx/leds.c
+++ b/drivers/net/dsa/mv88e6xxx/leds.c
@@ -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;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds
  2025-09-01  7:32 [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds Miaoqian Lin
@ 2025-09-01  8:23 ` Linus Walleij
  2025-09-02 12:52 ` Markus Elfring
  2025-09-03  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2025-09-01  8:23 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, stable

On Mon, Sep 1, 2025 at 9:32 AM Miaoqian Lin <linmq006@gmail.com> 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.
>
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - use goto for cleanup in error paths
> - v1: https://lore.kernel.org/all/20250830085508.2107507-1-linmq006@gmail.com/

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

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds
  2025-09-01  7:32 [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds Miaoqian Lin
  2025-09-01  8:23 ` Linus Walleij
@ 2025-09-02 12:52 ` Markus Elfring
  2025-09-03  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-09-02 12:52 UTC (permalink / raw)
  To: Miaoqian Lin, netdev
  Cc: stable, LKML, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Linus Walleij, Paolo Abeni, Vladimir Oltean

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds
  2025-09-01  7:32 [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds Miaoqian Lin
  2025-09-01  8:23 ` Linus Walleij
  2025-09-02 12:52 ` Markus Elfring
@ 2025-09-03  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-03  0:10 UTC (permalink / raw)
  To: =?utf-8?b?5p6X5aaZ5YCpIDxsaW5tcTAwNkBnbWFpbC5jb20+?=
  Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, linus.walleij,
	netdev, linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-03  0:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01  7:32 [PATCH v2] net: dsa: mv88e6xxx: Fix fwnode reference leaks in mv88e6xxx_port_setup_leds Miaoqian Lin
2025-09-01  8:23 ` Linus Walleij
2025-09-02 12:52 ` Markus Elfring
2025-09-03  0: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;
as well as URLs for NNTP newsgroup(s).