]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
KVM: Clean up error handling during VCPU creation
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 23 May 2011 08:33:05 +0000 (10:33 +0200)
committerAvi Kivity <avi@redhat.com>
Tue, 12 Jul 2011 08:45:08 +0000 (11:45 +0300)
So far kvm_arch_vcpu_setup is responsible for freeing the vcpu struct if
it fails. Move this confusing resonsibility back into the hands of
kvm_vm_ioctl_create_vcpu. Only kvm_arch_vcpu_setup of x86 is affected,
all other archs cannot fail.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/x86.c
virt/kvm/kvm_main.c

index da48622d170fd135dba2113531aba945d38d81f5..aaa3735004bcedeea42dd8d3b622f7395687d6f9 100644 (file)
@@ -6126,12 +6126,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
        if (r == 0)
                r = kvm_mmu_setup(vcpu);
        vcpu_put(vcpu);
-       if (r < 0)
-               goto free_vcpu;
 
-       return 0;
-free_vcpu:
-       kvm_x86_ops->vcpu_free(vcpu);
        return r;
 }
 
index 087b3f8ca46ef1d0303dec290c021771f2a42a80..fa2321ac77ccf719e8a19fa5a8273145f24edd80 100644 (file)
@@ -1615,18 +1615,18 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
 
        r = kvm_arch_vcpu_setup(vcpu);
        if (r)
-               return r;
+               goto vcpu_destroy;
 
        mutex_lock(&kvm->lock);
        if (atomic_read(&kvm->online_vcpus) == KVM_MAX_VCPUS) {
                r = -EINVAL;
-               goto vcpu_destroy;
+               goto unlock_vcpu_destroy;
        }
 
        kvm_for_each_vcpu(r, v, kvm)
                if (v->vcpu_id == id) {
                        r = -EEXIST;
-                       goto vcpu_destroy;
+                       goto unlock_vcpu_destroy;
                }
 
        BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]);
@@ -1636,7 +1636,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
        r = create_vcpu_fd(vcpu);
        if (r < 0) {
                kvm_put_kvm(kvm);
-               goto vcpu_destroy;
+               goto unlock_vcpu_destroy;
        }
 
        kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
@@ -1650,8 +1650,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
        mutex_unlock(&kvm->lock);
        return r;
 
-vcpu_destroy:
+unlock_vcpu_destroy:
        mutex_unlock(&kvm->lock);
+vcpu_destroy:
        kvm_arch_vcpu_destroy(vcpu);
        return r;
 }