Skip to content

Commit 4feb74a

Browse files
farosasmpe
authored andcommitted
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
1 parent 175be7e commit 4feb74a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/powerpc/kvm/powerpc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ int kvm_arch_check_processor_compat(void *opaque)
453453
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
454454
{
455455
struct kvmppc_ops *kvm_ops = NULL;
456+
int r;
457+
456458
/*
457459
* if we have both HV and PR enabled, default is HV
458460
*/
@@ -474,11 +476,14 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
474476
} else
475477
goto err_out;
476478

477-
if (kvm_ops->owner && !try_module_get(kvm_ops->owner))
479+
if (!try_module_get(kvm_ops->owner))
478480
return -ENOENT;
479481

480482
kvm->arch.kvm_ops = kvm_ops;
481-
return kvmppc_core_init_vm(kvm);
483+
r = kvmppc_core_init_vm(kvm);
484+
if (r)
485+
module_put(kvm_ops->owner);
486+
return r;
482487
err_out:
483488
return -EINVAL;
484489
}

0 commit comments

Comments
 (0)