Skip to contentSkip to conversation

soc: rockchip: grf: fix device node refcount leak in error path

PATCH In review [email protected] 2 participants 3 messages Feb 21 Arm Rockchip

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: rockchip: grf: fix device node refcount leak in error path

From: Pei Xiao <[email protected]>

The for_each_matching_node_and_match() macro automatically manages device node reference counts during normal iteration. However, when breaking out of the loop early with return, the current iteration's node is not automatically released, leading to a reference count leak.

Fix this by adding of_node_put() before returning from the loop when fails.

Fixes 75fb63ae0312 ("soc: rockchip: grf: Support multiple grf to be handled")
---
 drivers/soc/rockchip/grf.c | 1 +
 1 file changed, 1 insertion(+)
drivers/soc/rockchip/grf.c +1 -0
index 04937c40da47..b459607c118a 100644
@@ -231,6 +231,7 @@ static int __init rockchip_grf_init(void)
 		grf = syscon_node_to_regmap(np);
 		if (IS_ERR(grf)) {
 			pr_err("%s: could not get grf syscon\n", __func__);
+			of_node_put(np);
 			return PTR_ERR(grf);
 		}
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi,

Am Samstag, 21. Februar 2026, 01:40:27 Mitteleuropäische Normalzeit schrieb [email protected]:

Quoted 7 lines

From: Pei Xiao <[email protected]>

The for_each_matching_node_and_match() macro automatically manages device node reference counts during normal iteration. However, when breaking out of the loop early with return, the current iteration's node is not automatically released, leading to a reference count leak.

Quoted 5 lines

Fix this by adding of_node_put() before returning from the loop when fails.

Fixes 75fb63ae0312 ("soc: rockchip: grf: Support multiple grf to be handled")

Felix Gu was slightly faster [0], so I'll apply their patch once the merge- window is closed.

Thanks
Heiko

[0] http://lore.kernel.org/r/[email protected]

maintainer
#2 lore raw

Am Samstag, 21. Februar 2026, 15:51:46 Mitteleuropäische Normalzeit schrieb Heiko Stübner:

Quoted 10 lines

Hi,

Am Samstag, 21. Februar 2026, 01:40:27 Mitteleuropäische Normalzeit schrieb [email protected]:

Quoted 7 lines

From: Pei Xiao <[email protected]>

The for_each_matching_node_and_match() macro automatically manages device node reference counts during normal iteration. However, when breaking out of the loop early with return, the current iteration's node is not automatically released, leading to a reference count leak.

Quoted 8 lines
Quoted 5 lines

Fix this by adding of_node_put() before returning from the loop when fails.

Fixes 75fb63ae0312 ("soc: rockchip: grf: Support multiple grf to be handled")

Felix Gu was slightly faster [0], so I'll apply their patch once the merge- window is closed.

and I just realized that Shawn was actually even earlier [1]

Quoted 6 lines

Thanks
Heiko

[0] http://lore.kernel.org/r/[email protected]

[1] https://lore.kernel.org/all/[email protected]/