summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabiano Rosas <farosas@linux.ibm.com>2022-01-25 18:57:35 +0300
committerMichael Ellerman <mpe@ellerman.id.au>2022-02-03 08:50:44 +0300
commit4feb74aa64b35b21a4937f96d7a940adee286e5b (patch)
treefd9c309897044cee4ba29566be056971ac9582ba
parent175be7e5800e2782a7e38ee9e1b64633494c4b44 (diff)
downloadlinux-4feb74aa64b35b21a4937f96d7a940adee286e5b.tar.xz
KVM: PPC: Decrement module refcount if init_vm fails
We increment the reference count for KVM-HV/PR before the call to kvmppc_core_init_vm. If that function fails we need to decrement the refcount. Also remove the check on kvm_ops->owner because try_module_get can handle a NULL module. 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-5-farosas@linux.ibm.com
-rw-r--r--arch/powerpc/kvm/powerpc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 1d06b68739b0..9772b176e406 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -453,6 +453,8 @@ int kvm_arch_check_processor_compat(void *opaque)
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
{
struct kvmppc_ops *kvm_ops = NULL;
+ int r;
+
/*
* if we have both HV and PR enabled, default is HV
*/
@@ -474,11 +476,14 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
} else
goto err_out;
- if (kvm_ops->owner && !try_module_get(kvm_ops->owner))
+ if (!try_module_get(kvm_ops->owner))
return -ENOENT;
kvm->arch.kvm_ops = kvm_ops;
- return kvmppc_core_init_vm(kvm);
+ r = kvmppc_core_init_vm(kvm);
+ if (r)
+ module_put(kvm_ops->owner);
+ return r;
err_out:
return -EINVAL;
}