diff mbox series

KVM: fix error handling in svm_hardware_setup

Message ID 1552375767-27828-1-git-send-email-lirongqing@baidu.com (mailing list archive)
State New, archived
Headers show
Series KVM: fix error handling in svm_hardware_setup | expand

Commit Message

Li RongQing March 12, 2019, 7:29 a.m. UTC
From: Li Rongqing <lirongqing@baidu.com>

free all memory if fail to setup, otherwise they will be leaked

Signed-off-by: Li Rongqing <lirongqing@baidu.com>
Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
---
 arch/x86/kvm/svm.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Brijesh Singh March 13, 2019, 3:50 p.m. UTC | #1
On 3/12/19 2:29 AM, Li RongQing wrote:
> From: Li Rongqing <lirongqing@baidu.com>
> 
> free all memory if fail to setup, otherwise they will be leaked
> 
> Signed-off-by: Li Rongqing <lirongqing@baidu.com>
> Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
> ---
>   arch/x86/kvm/svm.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 1787a484d21c..b80a11d99a2a 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1396,6 +1396,12 @@ static __init int svm_hardware_setup(void)
>   	return 0;
>   
>   err:
> +	if (svm_sev_enabled())
> +		bitmap_free(sev_asid_bitmap);
> +
> +	for_each_possible_cpu(cpu)
> +		svm_cpu_uninit(cpu);
> +
>   	__free_pages(iopm_pages, IOPM_ALLOC_ORDER);
>   	iopm_base = 0;
>   	return r;
> 


Does it make sense to call the svm_hardware_unsetup() instead of
duplicating the logic in error code path ?

thanks
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1787a484d21c..b80a11d99a2a 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1396,6 +1396,12 @@  static __init int svm_hardware_setup(void)
 	return 0;
 
 err:
+	if (svm_sev_enabled())
+		bitmap_free(sev_asid_bitmap);
+
+	for_each_possible_cpu(cpu)
+		svm_cpu_uninit(cpu);
+
 	__free_pages(iopm_pages, IOPM_ALLOC_ORDER);
 	iopm_base = 0;
 	return r;