linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm:cache-l2x0: Fix resource leak in the l2x0_of_init() failed branch
@ 2021-11-08  4:05 Xiaoming Ni
  2022-08-18  1:25 ` Xiaoming Ni
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoming Ni @ 2021-11-08  4:05 UTC (permalink / raw)
  To: linux-kernel, linux, arnd, olof, 21cnbao, grant.likely,
	santosh.shilimkar, m.szyprowski, tony, t.figa, linux-arm-kernel
  Cc: nixiaoming, wangle6

During the code review, some problems were found in the function l2x0_of_init().
1. Do not call Of_put_node() after calling of_find_match_node().
2. When __l2c_init() is called for identification, l2x0_base is not released.

Invoking Of_put_node() and iounmap() is added to solve this problem.

Fixes: 8c369264b6de3 ("ARM: 7009/1: l2x0: Add OF based initialization")
Fixes: 91c2ebb90b189 ("ARM: 7114/1: cache-l2x0: add resume entry for l2 in secure mode")
Fixes: 6b49241ac2525 ("ARM: 8259/1: l2c: Refactor the driver to use commit-like interface")
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 arch/arm/mm/cache-l2x0.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
index 43d91bfd2360..105bf7575cdf 100644
--- a/arch/arm/mm/cache-l2x0.c
+++ b/arch/arm/mm/cache-l2x0.c
@@ -1766,17 +1766,22 @@ int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
 	u32 cache_id, old_aux;
 	u32 cache_level = 2;
 	bool nosync = false;
+	int ret;
 
 	np = of_find_matching_node(NULL, l2x0_ids);
 	if (!np)
 		return -ENODEV;
 
-	if (of_address_to_resource(np, 0, &res))
+	if (of_address_to_resource(np, 0, &res)) {
+		of_put_node(np);
 		return -ENODEV;
+	}
 
 	l2x0_base = ioremap(res.start, resource_size(&res));
-	if (!l2x0_base)
+	if (!l2x0_base) {
+		of_put_node(np);
 		return -ENOMEM;
+	}
 
 	l2x0_saved_regs.phy_base = res.start;
 
@@ -1820,6 +1825,12 @@ int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
 	else
 		cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
 
-	return __l2c_init(data, aux_val, aux_mask, cache_id, nosync);
+	ret = _l2c_init(data, aux_val, aux_mask, cache_id, nosync);
+	if (ret != 0) {
+		iounmap(l2x0_base);
+		l2x0_base = NULL;
+	}
+	of_put_node(np);
+	return ret;
 }
 #endif
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] arm:cache-l2x0: Fix resource leak in the l2x0_of_init() failed branch
  2021-11-08  4:05 [PATCH] arm:cache-l2x0: Fix resource leak in the l2x0_of_init() failed branch Xiaoming Ni
@ 2022-08-18  1:25 ` Xiaoming Ni
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaoming Ni @ 2022-08-18  1:25 UTC (permalink / raw)
  To: linux-kernel, linux, arnd, olof, 21cnbao, grant.likely,
	santosh.shilimkar, m.szyprowski, tony, t.figa, linux-arm-kernel
  Cc: wangle6

ping

On 2021/11/8 12:05, Xiaoming Ni wrote:
> During the code review, some problems were found in the function l2x0_of_init().
> 1. Do not call Of_put_node() after calling of_find_match_node().
> 2. When __l2c_init() is called for identification, l2x0_base is not released.
> 
> Invoking Of_put_node() and iounmap() is added to solve this problem.
> 
> Fixes: 8c369264b6de3 ("ARM: 7009/1: l2x0: Add OF based initialization")
> Fixes: 91c2ebb90b189 ("ARM: 7114/1: cache-l2x0: add resume entry for l2 in secure mode")
> Fixes: 6b49241ac2525 ("ARM: 8259/1: l2c: Refactor the driver to use commit-like interface")
> Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
> ---
>   arch/arm/mm/cache-l2x0.c | 17 ++++++++++++++---
>   1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
> index 43d91bfd2360..105bf7575cdf 100644
> --- a/arch/arm/mm/cache-l2x0.c
> +++ b/arch/arm/mm/cache-l2x0.c
> @@ -1766,17 +1766,22 @@ int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
>   	u32 cache_id, old_aux;
>   	u32 cache_level = 2;
>   	bool nosync = false;
> +	int ret;
>   
>   	np = of_find_matching_node(NULL, l2x0_ids);
>   	if (!np)
>   		return -ENODEV;
>   
> -	if (of_address_to_resource(np, 0, &res))
> +	if (of_address_to_resource(np, 0, &res)) {
> +		of_put_node(np);
>   		return -ENODEV;
> +	}
>   
>   	l2x0_base = ioremap(res.start, resource_size(&res));
> -	if (!l2x0_base)
> +	if (!l2x0_base) {
> +		of_put_node(np);
>   		return -ENOMEM;
> +	}
>   
>   	l2x0_saved_regs.phy_base = res.start;
>   
> @@ -1820,6 +1825,12 @@ int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
>   	else
>   		cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
>   
> -	return __l2c_init(data, aux_val, aux_mask, cache_id, nosync);
> +	ret = _l2c_init(data, aux_val, aux_mask, cache_id, nosync);
> +	if (ret != 0) {
> +		iounmap(l2x0_base);
> +		l2x0_base = NULL;
> +	}
> +	of_put_node(np);
> +	return ret;
>   }
>   #endif
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-18  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08  4:05 [PATCH] arm:cache-l2x0: Fix resource leak in the l2x0_of_init() failed branch Xiaoming Ni
2022-08-18  1:25 ` Xiaoming Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).