aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/kvm_main.c
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2011-05-23 04:33:05 -0400
committerAvi Kivity <avi@redhat.com>2011-07-12 04:45:08 -0400
commitd780592b99d7d8a5ff905f6bacca519d4a342c76 (patch)
treeb1779fdd8dfef925161ff804582b5377c0f86cd8 /virt/kvm/kvm_main.c
parentd462b8192368f10e979250377930f9695a4039d0 (diff)
KVM: Clean up error handling during VCPU creation
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>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r--virt/kvm/kvm_main.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 087b3f8ca46e..fa2321ac77cc 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1615,18 +1615,18 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
1615 1615
1616 r = kvm_arch_vcpu_setup(vcpu); 1616 r = kvm_arch_vcpu_setup(vcpu);
1617 if (r) 1617 if (r)
1618 return r; 1618 goto vcpu_destroy;
1619 1619
1620 mutex_lock(&kvm->lock); 1620 mutex_lock(&kvm->lock);
1621 if (atomic_read(&kvm->online_vcpus) == KVM_MAX_VCPUS) { 1621 if (atomic_read(&kvm->online_vcpus) == KVM_MAX_VCPUS) {
1622 r = -EINVAL; 1622 r = -EINVAL;
1623 goto vcpu_destroy; 1623 goto unlock_vcpu_destroy;
1624 } 1624 }
1625 1625
1626 kvm_for_each_vcpu(r, v, kvm) 1626 kvm_for_each_vcpu(r, v, kvm)
1627 if (v->vcpu_id == id) { 1627 if (v->vcpu_id == id) {
1628 r = -EEXIST; 1628 r = -EEXIST;
1629 goto vcpu_destroy; 1629 goto unlock_vcpu_destroy;
1630 } 1630 }
1631 1631
1632 BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]); 1632 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)
1636 r = create_vcpu_fd(vcpu); 1636 r = create_vcpu_fd(vcpu);
1637 if (r < 0) { 1637 if (r < 0) {
1638 kvm_put_kvm(kvm); 1638 kvm_put_kvm(kvm);
1639 goto vcpu_destroy; 1639 goto unlock_vcpu_destroy;
1640 } 1640 }
1641 1641
1642 kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu; 1642 kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
@@ -1650,8 +1650,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
1650 mutex_unlock(&kvm->lock); 1650 mutex_unlock(&kvm->lock);
1651 return r; 1651 return r;
1652 1652
1653vcpu_destroy: 1653unlock_vcpu_destroy:
1654 mutex_unlock(&kvm->lock); 1654 mutex_unlock(&kvm->lock);
1655vcpu_destroy:
1655 kvm_arch_vcpu_destroy(vcpu); 1656 kvm_arch_vcpu_destroy(vcpu);
1656 return r; 1657 return r;
1657} 1658}