diff mbox series

[v2] arm/xen: Fix some refcount leaks

Message ID 20220420014913.2586-1-linmq006@gmail.com (mailing list archive)
State Accepted
Commit b12d41716e32d14e24d675af3913f2f22af31d54
Headers show
Series [v2] arm/xen: Fix some refcount leaks | expand

Commit Message

Miaoqian Lin April 20, 2022, 1:49 a.m. UTC
The of_find_compatible_node() function returns a node pointer with
refcount incremented, We should use of_node_put() on it when done
Add the missing of_node_put() to release the refcount.

Fixes: 9b08aaa3199a ("ARM: XEN: Move xen_early_init() before efi_init()")
Fixes: b2371587fe0c ("arm/xen: Read extended regions from DT and init Xen resource")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- call of_node_put in non-error path in xen_dt_guest_init
- fix same refcount leak error in arch_xen_unpopulated_init
---
 arch/arm/xen/enlighten.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Stefano Stabellini April 22, 2022, 12:36 a.m. UTC | #1
On Wed, 20 Apr 2022, Miaoqian Lin wrote:
> The of_find_compatible_node() function returns a node pointer with
> refcount incremented, We should use of_node_put() on it when done
> Add the missing of_node_put() to release the refcount.
> 
> Fixes: 9b08aaa3199a ("ARM: XEN: Move xen_early_init() before efi_init()")
> Fixes: b2371587fe0c ("arm/xen: Read extended regions from DT and init Xen resource")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

Juergen,  Boris,
I applied the patch to for-linus-5.18


> ---
> changes in v2:
> - call of_node_put in non-error path in xen_dt_guest_init
> - fix same refcount leak error in arch_xen_unpopulated_init
> ---
>  arch/arm/xen/enlighten.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> index ec5b082f3de6..07eb69f9e7df 100644
> --- a/arch/arm/xen/enlighten.c
> +++ b/arch/arm/xen/enlighten.c
> @@ -337,12 +337,15 @@ int __init arch_xen_unpopulated_init(struct resource **res)
>  
>  	if (!nr_reg) {
>  		pr_err("No extended regions are found\n");
> +		of_node_put(np);
>  		return -EINVAL;
>  	}
>  
>  	regs = kcalloc(nr_reg, sizeof(*regs), GFP_KERNEL);
> -	if (!regs)
> +	if (!regs) {
> +		of_node_put(np);
>  		return -ENOMEM;
> +	}
>  
>  	/*
>  	 * Create resource from extended regions provided by the hypervisor to be
> @@ -403,8 +406,8 @@ int __init arch_xen_unpopulated_init(struct resource **res)
>  	*res = &xen_resource;
>  
>  err:
> +	of_node_put(np);
>  	kfree(regs);
> -
>  	return rc;
>  }
>  #endif
> @@ -424,8 +427,10 @@ static void __init xen_dt_guest_init(void)
>  
>  	if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) {
>  		pr_err("Xen grant table region is not found\n");
> +		of_node_put(xen_node);
>  		return;
>  	}
> +	of_node_put(xen_node);
>  	xen_grant_frames = res.start;
>  }
>  
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index ec5b082f3de6..07eb69f9e7df 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -337,12 +337,15 @@  int __init arch_xen_unpopulated_init(struct resource **res)
 
 	if (!nr_reg) {
 		pr_err("No extended regions are found\n");
+		of_node_put(np);
 		return -EINVAL;
 	}
 
 	regs = kcalloc(nr_reg, sizeof(*regs), GFP_KERNEL);
-	if (!regs)
+	if (!regs) {
+		of_node_put(np);
 		return -ENOMEM;
+	}
 
 	/*
 	 * Create resource from extended regions provided by the hypervisor to be
@@ -403,8 +406,8 @@  int __init arch_xen_unpopulated_init(struct resource **res)
 	*res = &xen_resource;
 
 err:
+	of_node_put(np);
 	kfree(regs);
-
 	return rc;
 }
 #endif
@@ -424,8 +427,10 @@  static void __init xen_dt_guest_init(void)
 
 	if (of_address_to_resource(xen_node, GRANT_TABLE_INDEX, &res)) {
 		pr_err("Xen grant table region is not found\n");
+		of_node_put(xen_node);
 		return;
 	}
+	of_node_put(xen_node);
 	xen_grant_frames = res.start;
 }