KVM: i8254: refactor kvm_create_pit
Locks are gone, so we don't need to duplicate error paths. Use goto everywhere. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
71474e2f0f
commit
10d2482126
|
@ -676,10 +676,8 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pit->irq_source_id = kvm_request_irq_source_id(kvm);
|
pit->irq_source_id = kvm_request_irq_source_id(kvm);
|
||||||
if (pit->irq_source_id < 0) {
|
if (pit->irq_source_id < 0)
|
||||||
kfree(pit);
|
goto fail_request;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_init(&pit->pit_state.lock);
|
mutex_init(&pit->pit_state.lock);
|
||||||
|
|
||||||
|
@ -690,11 +688,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
|
||||||
init_kthread_worker(&pit->worker);
|
init_kthread_worker(&pit->worker);
|
||||||
pit->worker_task = kthread_run(kthread_worker_fn, &pit->worker,
|
pit->worker_task = kthread_run(kthread_worker_fn, &pit->worker,
|
||||||
"kvm-pit/%d", pid_nr);
|
"kvm-pit/%d", pid_nr);
|
||||||
if (IS_ERR(pit->worker_task)) {
|
if (IS_ERR(pit->worker_task))
|
||||||
kvm_free_irq_source_id(kvm, pit->irq_source_id);
|
goto fail_kthread;
|
||||||
kfree(pit);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
init_kthread_work(&pit->expired, pit_do_work);
|
init_kthread_work(&pit->expired, pit_do_work);
|
||||||
|
|
||||||
pit->kvm = kvm;
|
pit->kvm = kvm;
|
||||||
|
@ -715,7 +711,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
|
||||||
ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, KVM_PIT_BASE_ADDRESS,
|
ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, KVM_PIT_BASE_ADDRESS,
|
||||||
KVM_PIT_MEM_LENGTH, &pit->dev);
|
KVM_PIT_MEM_LENGTH, &pit->dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
goto fail_register_pit;
|
||||||
|
|
||||||
if (flags & KVM_PIT_SPEAKER_DUMMY) {
|
if (flags & KVM_PIT_SPEAKER_DUMMY) {
|
||||||
kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops);
|
kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops);
|
||||||
|
@ -723,18 +719,19 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
|
||||||
KVM_SPEAKER_BASE_ADDRESS, 4,
|
KVM_SPEAKER_BASE_ADDRESS, 4,
|
||||||
&pit->speaker_dev);
|
&pit->speaker_dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail_unregister;
|
goto fail_register_speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pit;
|
return pit;
|
||||||
|
|
||||||
fail_unregister:
|
fail_register_speaker:
|
||||||
kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->dev);
|
kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->dev);
|
||||||
|
fail_register_pit:
|
||||||
fail:
|
|
||||||
kvm_pit_set_reinject(pit, false);
|
kvm_pit_set_reinject(pit, false);
|
||||||
kvm_free_irq_source_id(kvm, pit->irq_source_id);
|
|
||||||
kthread_stop(pit->worker_task);
|
kthread_stop(pit->worker_task);
|
||||||
|
fail_kthread:
|
||||||
|
kvm_free_irq_source_id(kvm, pit->irq_source_id);
|
||||||
|
fail_request:
|
||||||
kfree(pit);
|
kfree(pit);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue