Skip to content

Commit

Permalink
kvm_main: Use common error handling code in kvm_dev_ioctl_create_vm()
Browse files Browse the repository at this point in the history
Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
  • Loading branch information
Markus Elfring authored and Paolo Bonzini committed Dec 14, 2017
1 parent 52797bf commit 7858833
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3186,21 +3186,18 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
return PTR_ERR(kvm);
#ifdef CONFIG_KVM_MMIO
r = kvm_coalesced_mmio_init(kvm);
if (r < 0) {
kvm_put_kvm(kvm);
return r;
}
if (r < 0)
goto put_kvm;
#endif
r = get_unused_fd_flags(O_CLOEXEC);
if (r < 0) {
kvm_put_kvm(kvm);
return r;
}
if (r < 0)
goto put_kvm;

file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
if (IS_ERR(file)) {
put_unused_fd(r);
kvm_put_kvm(kvm);
return PTR_ERR(file);
r = PTR_ERR(file);
goto put_kvm;
}

/*
Expand All @@ -3218,6 +3215,10 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)

fd_install(r, file);
return r;

put_kvm:
kvm_put_kvm(kvm);
return r;
}

static long kvm_dev_ioctl(struct file *filp,
Expand Down

0 comments on commit 7858833

Please sign in to comment.