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

xiaopeitux@foxmail.com posted 1 patch 1 month, 3 weeks ago
drivers/soc/rockchip/grf.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] soc: rockchip: grf: fix device node refcount leak in error path
Posted by xiaopeitux@foxmail.com 1 month, 3 weeks ago
From: Pei Xiao <xiaopei01@kylinos.cn>

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")
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 drivers/soc/rockchip/grf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/rockchip/grf.c b/drivers/soc/rockchip/grf.c
index 04937c40da47..b459607c118a 100644
--- a/drivers/soc/rockchip/grf.c
+++ b/drivers/soc/rockchip/grf.c
@@ -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);
 		}
 
-- 
2.25.1
Re: [PATCH] soc: rockchip: grf: fix device node refcount leak in error path
Posted by Heiko Stübner 1 month, 3 weeks ago
Hi,

Am Samstag, 21. Februar 2026, 01:40:27 Mitteleuropäische Normalzeit schrieb xiaopeitux@foxmail.com:
> From: Pei Xiao <xiaopei01@kylinos.cn>
> 
> 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")
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>

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/20260217-grf-v1-1-2088c966875d@gmail.com
Re: [PATCH] soc: rockchip: grf: fix device node refcount leak in error path
Posted by Heiko Stübner 1 month, 3 weeks ago
Am Samstag, 21. Februar 2026, 15:51:46 Mitteleuropäische Normalzeit schrieb Heiko Stübner:
> Hi,
> 
> Am Samstag, 21. Februar 2026, 01:40:27 Mitteleuropäische Normalzeit schrieb xiaopeitux@foxmail.com:
> > From: Pei Xiao <xiaopei01@kylinos.cn>
> > 
> > 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")
> > Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> 
> 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]

> 
> Thanks
> Heiko
> 
> 
> [0] http://lore.kernel.org/r/20260217-grf-v1-1-2088c966875d@gmail.com
[1] https://lore.kernel.org/all/1770814957-17762-1-git-send-email-shawn.lin@rock-chips.com/