Commit 0c6ddceb authored by Jiri Slaby's avatar Jiri Slaby Committed by Avi Kivity

KVM: fix lock imbalance in kvm_*_irq_source_id()

Stanse found 2 lock imbalances in kvm_request_irq_source_id and
kvm_free_irq_source_id. They omit to unlock kvm->irq_lock on fail paths.

Fix that by adding unlock labels at the end of the functions and jump
there from the fail paths.
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent e935d48e
...@@ -220,11 +220,13 @@ int kvm_request_irq_source_id(struct kvm *kvm) ...@@ -220,11 +220,13 @@ int kvm_request_irq_source_id(struct kvm *kvm)
if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n"); printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n");
return -EFAULT; irq_source_id = -EFAULT;
goto unlock;
} }
ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID); ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID);
set_bit(irq_source_id, bitmap); set_bit(irq_source_id, bitmap);
unlock:
mutex_unlock(&kvm->irq_lock); mutex_unlock(&kvm->irq_lock);
return irq_source_id; return irq_source_id;
...@@ -240,7 +242,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) ...@@ -240,7 +242,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
if (irq_source_id < 0 || if (irq_source_id < 0 ||
irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
printk(KERN_ERR "kvm: IRQ source ID out of range!\n"); printk(KERN_ERR "kvm: IRQ source ID out of range!\n");
return; goto unlock;
} }
for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) { for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) {
clear_bit(irq_source_id, &kvm->arch.vioapic->irq_states[i]); clear_bit(irq_source_id, &kvm->arch.vioapic->irq_states[i]);
...@@ -251,6 +253,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) ...@@ -251,6 +253,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
#endif #endif
} }
clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap); clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
unlock:
mutex_unlock(&kvm->irq_lock); mutex_unlock(&kvm->irq_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment