Skip to contentSkip to conversation

net: dsa: hellcreek: fix device_node leak in hellcreek_led_setup()

PATCH Applied Xia Yan 4 participants 5 messages Nov 6 – Nov 11

Subsystems (4)
lore
Share & tools
lore

Xia Yan

author
#0 lore raw

PATCH 1/1 net: dsa: hellcreek: fix device_node leak in hellcreek_led_setup()

hellcreek_led_setup() walks the two LED child nodes of the "leds" node with of_get_next_available_child(). The helper drops the reference on the child passed to it and takes one on the child it returns. After the second call the caller holds a reference on the second LED node.

That reference is never dropped. The out: label only releases the "leds" node itself. Boards with both LED child nodes leak one device_node reference per probe, on the registration failures as well as on the success path.

Drop it at the out: label, before the parent node. The early exits, where the walk stopped before the second child, pass NULL, which of_node_put() ignores.

Found during a code review of the OF node handling in DSA drivers.

---
  drivers/net/dsa/hirschmann/hellcreek_ptp.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/dsa/hirschmann/hellcreek_ptp.c +1 -0
index cb23bea9c21b..ed27731d4f4e 100644
@@ -392,6 +392,7 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek)
 	ret = 0;
 
 out:
+	of_node_put(led);
 	of_node_put(leds);
 
 	return ret;
#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:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

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. If the series needs another revision for other reasons, please include the information in the commit messages then.

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
Quoted 3 lines · netdev-bot+sinfo

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Hi,

The leak was not hit at runtime. I found it by code inspection while reviewing the OF node handling in DSA drivers, as the commit message notes. There is no stack trace: the effect would be one device_node reference leaked per probe and never released.

Thanks,
Xia Yan

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Xia Yan
Quoted 10 lines · Xia Yan

hellcreek_led_setup() walks the two LED child nodes of the "leds" node with of_get_next_available_child(). The helper drops the reference on the child passed to it and takes one on the child it returns. After the second call the caller holds a reference on the second LED node.

That reference is never dropped. The out: label only releases the "leds" node itself. Boards with both LED child nodes leak one device_node reference per probe, on the registration failures as well as on the success path.

Quoted 7 lines

Drop it at the out: label, before the parent node. The early exits, where the walk stopped before the second child, pass NULL, which of_node_put() ignores.

Found during a code review of the OF node handling in DSA drivers.

Looks correct to me. Thanks.

#4 lore raw
In reply to Xia Yan
This patch was applied to netdev/net-next.git (main) by Dave Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Dave Miller <[email protected]>:

Quoted 11 lines · On Fri, 06 Nov 2026 16:48:32 +0800 you wrote:

hellcreek_led_setup() walks the two LED child nodes of the "leds" node with of_get_next_available_child(). The helper drops the reference on the child passed to it and takes one on the child it returns. After the second call the caller holds a reference on the second LED node.

That reference is never dropped. The out: label only releases the "leds" node itself. Boards with both LED child nodes leak one device_node reference per probe, on the registration failures as well as on the success path.

[...]

Here is the summary with links:
- [net-next] net: dsa: hellcreek: fix device_node leak in hellcreek_led_setup()

    https://git.kernel.org/netdev/net-next/c/c4c470912125

You are awesome, thank you!

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