[PATCH] powerpc/pseries: fix potential memory leak in init_cpu_associativity()

Naveen N. Rao naveen.n.rao at linux.vnet.ibm.com
Tue Dec 13 17:06:36 AEDT 2022


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 at 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



More information about the Linuxppc-dev mailing list