Skip to content

Commit 175be7e

Browse files
farosasmpe
authored andcommitted
KVM: PPC: Book3S HV: Free allocated memory if module init fails
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@linux.ibm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220125155735.1018683-4-farosas@linux.ibm.com
1 parent c5d0d77 commit 175be7e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

arch/powerpc/kvm/book3s_hv.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6096,7 +6096,7 @@ static int kvmppc_book3s_init_hv(void)
60966096
if (!cpu_has_feature(CPU_FTR_ARCH_300)) {
60976097
r = kvm_init_subcore_bitmap();
60986098
if (r)
6099-
return r;
6099+
goto err;
61006100
}
61016101

61026102
/*
@@ -6112,7 +6112,8 @@ static int kvmppc_book3s_init_hv(void)
61126112
np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
61136113
if (!np) {
61146114
pr_err("KVM-HV: Cannot determine method for accessing XICS\n");
6115-
return -ENODEV;
6115+
r = -ENODEV;
6116+
goto err;
61166117
}
61176118
/* presence of intc confirmed - node can be dropped again */
61186119
of_node_put(np);
@@ -6125,12 +6126,12 @@ static int kvmppc_book3s_init_hv(void)
61256126

61266127
r = kvmppc_mmu_hv_init();
61276128
if (r)
6128-
return r;
6129+
goto err;
61296130

61306131
if (kvmppc_radix_possible()) {
61316132
r = kvmppc_radix_init();
61326133
if (r)
6133-
return r;
6134+
goto err;
61346135
}
61356136

61366137
r = kvmppc_uvmem_init();
@@ -6143,6 +6144,12 @@ static int kvmppc_book3s_init_hv(void)
61436144
kvmppc_hv_ops = &kvm_ops_hv;
61446145

61456146
return 0;
6147+
6148+
err:
6149+
kvmhv_nested_exit();
6150+
kvmppc_radix_exit();
6151+
6152+
return r;
61466153
}
61476154

61486155
static void kvmppc_book3s_exit_hv(void)

0 commit comments

Comments
 (0)