linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity()
@ 2022-12-08  1:32 Wang Yufen
  2022-12-13  6:06 ` Naveen N. Rao
  0 siblings, 1 reply; 3+ messages in thread
From: Wang Yufen @ 2022-12-08  1:32 UTC (permalink / raw)
  To: mpe, npiggin, christophe.leroy; +Cc: Wang Yufen, naveen.n.rao, linuxppc-dev

If the vcpu_associativity alloc memory successfully but the
pcpu_associativity fails to alloc memory, the vcpu_associativity
memory leaks.

Fixes: d62c8deeb6e6 ("powerpc/pseries: Provide vcpu dispatch statistics")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
 arch/powerpc/platforms/pseries/lpar.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index 97ef649..501ee6c 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -211,6 +211,7 @@ static int init_cpu_associativity(void)
 
 	if (!vcpu_associativity || !pcpu_associativity) {
 		pr_err("error allocating memory for associativity information\n");
+		kfree(vcpu_associativity);
 		return -ENOMEM;
 	}
 
-- 
1.8.3.1


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

* Re: [PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity()
  2022-12-08  1:32 [PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity() Wang Yufen
@ 2022-12-13  6:06 ` Naveen N. Rao
  2022-12-14  6:51   ` wangyufen
  0 siblings, 1 reply; 3+ messages in thread
From: Naveen N. Rao @ 2022-12-13  6:06 UTC (permalink / raw)
  To: christophe.leroy, mpe, npiggin, Wang Yufen; +Cc: linuxppc-dev

Wang Yufen wrote:
> If the vcpu_associativity alloc memory successfully but the
> pcpu_associativity fails to alloc memory, the vcpu_associativity
> memory leaks.
> 
> Fixes: d62c8deeb6e6 ("powerpc/pseries: Provide vcpu dispatch statistics")
> Signed-off-by: Wang Yufen <wangyufen@huawei.com>
> ---
>  arch/powerpc/platforms/pseries/lpar.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
> index 97ef649..501ee6c 100644
> --- a/arch/powerpc/platforms/pseries/lpar.c
> +++ b/arch/powerpc/platforms/pseries/lpar.c
> @@ -211,6 +211,7 @@ static int init_cpu_associativity(void)
> 
>  	if (!vcpu_associativity || !pcpu_associativity) {
>  		pr_err("error allocating memory for associativity information\n");
> +		kfree(vcpu_associativity);

I think we should call destroy_cpu_associativity() here instead. We 
don't know which allocation failed, so it is better to try and free 
both, and also to reset the pointers to 0.


- Naveen


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

* Re: [PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity()
  2022-12-13  6:06 ` Naveen N. Rao
@ 2022-12-14  6:51   ` wangyufen
  0 siblings, 0 replies; 3+ messages in thread
From: wangyufen @ 2022-12-14  6:51 UTC (permalink / raw)
  To: Naveen N. Rao, christophe.leroy, mpe, npiggin; +Cc: linuxppc-dev



在 2022/12/13 14:06, Naveen N. Rao 写道:
> Wang Yufen wrote:
>> If the vcpu_associativity alloc memory successfully but the
>> pcpu_associativity fails to alloc memory, the vcpu_associativity
>> memory leaks.
>>
>> Fixes: d62c8deeb6e6 ("powerpc/pseries: Provide vcpu dispatch statistics")
>> Signed-off-by: Wang Yufen <wangyufen@huawei.com>
>> ---
>>  arch/powerpc/platforms/pseries/lpar.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/powerpc/platforms/pseries/lpar.c 
>> b/arch/powerpc/platforms/pseries/lpar.c
>> index 97ef649..501ee6c 100644
>> --- a/arch/powerpc/platforms/pseries/lpar.c
>> +++ b/arch/powerpc/platforms/pseries/lpar.c
>> @@ -211,6 +211,7 @@ static int init_cpu_associativity(void)
>>
>>      if (!vcpu_associativity || !pcpu_associativity) {
>>          pr_err("error allocating memory for associativity 
>> information\n");
>> +        kfree(vcpu_associativity);
> 
> I think we should call destroy_cpu_associativity() here instead. We 
> don't know which allocation failed, so it is better to try and free 
> both, and also to reset the pointers to 0.

Hi,

Okay, I'll send a v2 with the following modifications:

--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -524,8 +524,10 @@ static ssize_t vcpudispatch_stats_write(struct file 
*file, const char __user *p,

  	if (cmd) {
  		rc = init_cpu_associativity();
-		if (rc)
+		if (rc) {
+			destroy_cpu_associativity();
  			goto out;
+		}

  		for_each_possible_cpu(cpu) {
  			disp = per_cpu_ptr(&vcpu_disp_data, cpu);

Thanks,
Wang

> 
> 
> - Naveen
> 
> 

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

end of thread, other threads:[~2022-12-14  6:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08  1:32 [PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity() Wang Yufen
2022-12-13  6:06 ` Naveen N. Rao
2022-12-14  6:51   ` wangyufen

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).