KVM: only clear irq_source_id if irqchip is present
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 29 Oct 2009 15:44:17 +0000 (13:44 -0200)
committerAvi Kivity <avi@redhat.com>
Thu, 3 Dec 2009 07:32:23 +0000 (09:32 +0200)
Otherwise kvm might attempt to dereference a NULL pointer.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
virt/kvm/irq_comm.c

index 0d454d352717f7db8b9edd0b89e1843bb7b01f7a..9b077342ab54c93e79266cf7d48c56a14466c802 100644 (file)
@@ -243,6 +243,10 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
                printk(KERN_ERR "kvm: IRQ source ID out of range!\n");
                goto unlock;
        }
+       clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
+       if (!irqchip_in_kernel(kvm))
+               goto unlock;
+
        for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) {
                clear_bit(irq_source_id, &kvm->arch.vioapic->irq_states[i]);
                if (i >= 16)
@@ -251,7 +255,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
                clear_bit(irq_source_id, &pic_irqchip(kvm)->irq_states[i]);
 #endif
        }
-       clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
 unlock:
        mutex_unlock(&kvm->irq_lock);
 }