aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/lapic.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-10-07 20:48:30 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:50 -0500
commitd589444e924bc72e42fa94853f9096589d69374d (patch)
tree4150b8e1274288911687fe6f4b2dff7f7d052d2b /drivers/kvm/lapic.c
parent82ce2c96831f049a37118733ced5c8f7c8848102 (diff)
KVM: Add kvm_free_lapic() to pair with kvm_create_lapic()
Instead of the asymetry of kvm_free_apic, implement kvm_free_lapic(). And guess what? I found a minor bug: we don't need to hrtimer_cancel() from kvm_main.c, because we do that in kvm_free_apic(). Also: 1) kvm_vcpu_uninit should be the reverse order from kvm_vcpu_init. 2) Don't set apic->regs_page to zero before freeing apic. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/lapic.c')
-rw-r--r--drivers/kvm/lapic.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/kvm/lapic.c b/drivers/kvm/lapic.c
index 238fcad3cece..8e8dab08be58 100644
--- a/drivers/kvm/lapic.c
+++ b/drivers/kvm/lapic.c
@@ -762,19 +762,17 @@ static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr)
762 return ret; 762 return ret;
763} 763}
764 764
765void kvm_free_apic(struct kvm_lapic *apic) 765void kvm_free_lapic(struct kvm_vcpu *vcpu)
766{ 766{
767 if (!apic) 767 if (!vcpu->apic)
768 return; 768 return;
769 769
770 hrtimer_cancel(&apic->timer.dev); 770 hrtimer_cancel(&vcpu->apic->timer.dev);
771 771
772 if (apic->regs_page) { 772 if (vcpu->apic->regs_page)
773 __free_page(apic->regs_page); 773 __free_page(vcpu->apic->regs_page);
774 apic->regs_page = 0;
775 }
776 774
777 kfree(apic); 775 kfree(vcpu->apic);
778} 776}
779 777
780/* 778/*
@@ -962,7 +960,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
962 if (apic->regs_page == NULL) { 960 if (apic->regs_page == NULL) {
963 printk(KERN_ERR "malloc apic regs error for vcpu %x\n", 961 printk(KERN_ERR "malloc apic regs error for vcpu %x\n",
964 vcpu->vcpu_id); 962 vcpu->vcpu_id);
965 goto nomem; 963 goto nomem_free_apic;
966 } 964 }
967 apic->regs = page_address(apic->regs_page); 965 apic->regs = page_address(apic->regs_page);
968 memset(apic->regs, 0, PAGE_SIZE); 966 memset(apic->regs, 0, PAGE_SIZE);
@@ -980,8 +978,9 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
980 apic->dev.private = apic; 978 apic->dev.private = apic;
981 979
982 return 0; 980 return 0;
981nomem_free_apic:
982 kfree(apic);
983nomem: 983nomem:
984 kvm_free_apic(apic);
985 return -ENOMEM; 984 return -ENOMEM;
986} 985}
987EXPORT_SYMBOL_GPL(kvm_create_lapic); 986EXPORT_SYMBOL_GPL(kvm_create_lapic);