Re: [PATCH 3/3] KVM: PPC: Book3S HV: Free allocated memory if module init fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Excerpts from Fabiano Rosas's message of December 24, 2021 7:19 am:
> The module's exit function is not called when the init fails, we need
> to do cleanup before returning.
> 
> Signed-off-by: Fabiano Rosas <farosas@xxxxxxxxxxxxx>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 53400932f5d8..2d79298e7ca4 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -6065,7 +6065,7 @@ static int kvmppc_book3s_init_hv(void)
>  
>  	r = kvm_init_subcore_bitmap();
>  	if (r)
> -		return r;
> +		goto err;
>  
>  	/*
>  	 * We need a way of accessing the XICS interrupt controller,
> @@ -6080,7 +6080,8 @@ static int kvmppc_book3s_init_hv(void)
>  		np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
>  		if (!np) {
>  			pr_err("KVM-HV: Cannot determine method for accessing XICS\n");
> -			return -ENODEV;
> +			r = -ENODEV;
> +			goto err;
>  		}
>  		/* presence of intc confirmed - node can be dropped again */
>  		of_node_put(np);
> @@ -6093,12 +6094,12 @@ static int kvmppc_book3s_init_hv(void)
>  
>  	r = kvmppc_mmu_hv_init();
>  	if (r)
> -		return r;
> +		goto err;
>  
>  	if (kvmppc_radix_possible()) {
>  		r = kvmppc_radix_init();
>  		if (r)
> -			return r;
> +			goto err;
>  	}
>  
>  	r = kvmppc_uvmem_init();
> @@ -6111,6 +6112,12 @@ static int kvmppc_book3s_init_hv(void)
>  	kvmppc_hv_ops = &kvm_ops_hv;
>  
>  	return 0;
> +
> +err:
> +	kvmhv_nested_exit();
> +	kvmppc_radix_exit();

These should both be callable without init functions succeeding
so this looks right to me.

Reviewed-by: Nicholas Piggin <npiggin@xxxxxxxxx>

Thanks,
Nick

> +
> +	return r;
>  }
>  
>  static void kvmppc_book3s_exit_hv(void)
> -- 
> 2.33.1
> 
> 




[Index of Archives]     [KVM Development]     [KVM ARM]     [KVM ia64]     [Linux Virtualization]     [Linux USB Devel]     [Linux Video]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux