[PATCH] ARM: zynq: Fix refcount leak in zynq_early_slcr_init

Qiheng Lin posted 1 patch 2 years, 9 months ago
arch/arm/mach-zynq/slcr.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] ARM: zynq: Fix refcount leak in zynq_early_slcr_init
Posted by Qiheng Lin 2 years, 9 months ago
of_find_compatible_node() returns a node pointer with refcount incremented,
we should use of_node_put() on error path.
Add missing of_node_put() to avoid refcount leak.

Fixes: 3329659df030 ("ARM: zynq: Simplify SLCR initialization")
Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
---
 arch/arm/mach-zynq/slcr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-zynq/slcr.c b/arch/arm/mach-zynq/slcr.c
index 37707614885a..9765b3f4c2fc 100644
--- a/arch/arm/mach-zynq/slcr.c
+++ b/arch/arm/mach-zynq/slcr.c
@@ -213,6 +213,7 @@ int __init zynq_early_slcr_init(void)
 	zynq_slcr_regmap = syscon_regmap_lookup_by_compatible("xlnx,zynq-slcr");
 	if (IS_ERR(zynq_slcr_regmap)) {
 		pr_err("%s: failed to find zynq-slcr\n", __func__);
+		of_node_put(np);
 		return -ENODEV;
 	}

--
2.32.0
Re: [PATCH] ARM: zynq: Fix refcount leak in zynq_early_slcr_init
Posted by Michal Simek 2 years, 9 months ago
Hi,

On 11/29/22 15:05, Qiheng Lin wrote:
> 
> of_find_compatible_node() returns a node pointer with refcount incremented,
> we should use of_node_put() on error path.
> Add missing of_node_put() to avoid refcount leak.
> 
> Fixes: 3329659df030 ("ARM: zynq: Simplify SLCR initialization")
> Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
> ---
>   arch/arm/mach-zynq/slcr.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/mach-zynq/slcr.c b/arch/arm/mach-zynq/slcr.c
> index 37707614885a..9765b3f4c2fc 100644
> --- a/arch/arm/mach-zynq/slcr.c
> +++ b/arch/arm/mach-zynq/slcr.c
> @@ -213,6 +213,7 @@ int __init zynq_early_slcr_init(void)
>          zynq_slcr_regmap = syscon_regmap_lookup_by_compatible("xlnx,zynq-slcr");
>          if (IS_ERR(zynq_slcr_regmap)) {
>                  pr_err("%s: failed to find zynq-slcr\n", __func__);
> +               of_node_put(np);
>                  return -ENODEV;
>          }
> 
> --
> 2.32.0
> 

Applied.

Thanks,
Michal