aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2009-09-25 03:33:38 -0400
committerAvi Kivity <avi@redhat.com>2009-12-03 02:32:12 -0500
commit0c6ddcebd8303ada6faefa6f72ac18b6230320c4 (patch)
treef9ad607a5c433b310fe78adbf934d465de06cc94
parente935d48e1b49451490218e1181d9834176200955 (diff)
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: Jiri Slaby <jirislaby@gmail.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--virt/kvm/irq_comm.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 15a83b93566d..00c68d298579 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -220,11 +220,13 @@ int kvm_request_irq_source_id(struct kvm *kvm)
220 220
221 if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { 221 if (irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
222 printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n"); 222 printk(KERN_WARNING "kvm: exhaust allocatable IRQ sources!\n");
223 return -EFAULT; 223 irq_source_id = -EFAULT;
224 goto unlock;
224 } 225 }
225 226
226 ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID); 227 ASSERT(irq_source_id != KVM_USERSPACE_IRQ_SOURCE_ID);
227 set_bit(irq_source_id, bitmap); 228 set_bit(irq_source_id, bitmap);
229unlock:
228 mutex_unlock(&kvm->irq_lock); 230 mutex_unlock(&kvm->irq_lock);
229 231
230 return irq_source_id; 232 return irq_source_id;
@@ -240,7 +242,7 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
240 if (irq_source_id < 0 || 242 if (irq_source_id < 0 ||
241 irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) { 243 irq_source_id >= sizeof(kvm->arch.irq_sources_bitmap)) {
242 printk(KERN_ERR "kvm: IRQ source ID out of range!\n"); 244 printk(KERN_ERR "kvm: IRQ source ID out of range!\n");
243 return; 245 goto unlock;
244 } 246 }
245 for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) { 247 for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++) {
246 clear_bit(irq_source_id, &kvm->arch.vioapic->irq_states[i]); 248 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#endif 253#endif
252 } 254 }
253 clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap); 255 clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
256unlock:
254 mutex_unlock(&kvm->irq_lock); 257 mutex_unlock(&kvm->irq_lock);
255} 258}
256 259