From: SF Markus Elfring <elfring@users.sourceforge.net>
To: kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/9] KVM: Move error code settings in kvm_vm_ioctl()
Date: Sun, 22 Jan 2017 18:12:39 +0000 [thread overview]
Message-ID: <18acab5d-a10d-77c0-8e8c-67bbaa1f0edb@users.sourceforge.net> (raw)
In-Reply-To: <a2fb541a-7a7d-1f78-b587-1191b9832088@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Jan 2017 13:45:18 +0100
* A local variable was set to an error code before a concrete error
situation was detected. Thus move the corresponding assignments
into if branches to indicate a software failure there.
This issue was detected by using the Coccinelle software.
* Return directly after a call of the function "copy_from_user"
(or two other checks) failed in a case block.
* Delete the jump label "out" and two zero assignments which became
unnecessary with this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
virt/kvm/kvm_main.c | 66 ++++++++++++++++++-----------------------------------
1 file changed, 22 insertions(+), 44 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index eeb340708d97..2773e5012948 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2960,20 +2960,17 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_SET_USER_MEMORY_REGION: {
struct kvm_userspace_memory_region kvm_userspace_mem;
- r = -EFAULT;
if (copy_from_user(&kvm_userspace_mem, argp,
sizeof(kvm_userspace_mem)))
- goto out;
-
+ return -EFAULT;
r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_userspace_mem);
break;
}
case KVM_GET_DIRTY_LOG: {
struct kvm_dirty_log log;
- r = -EFAULT;
if (copy_from_user(&log, argp, sizeof(log)))
- goto out;
+ return -EFAULT;
r = kvm_vm_ioctl_get_dirty_log(kvm, &log);
break;
}
@@ -2981,18 +2978,16 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_REGISTER_COALESCED_MMIO: {
struct kvm_coalesced_mmio_zone zone;
- r = -EFAULT;
if (copy_from_user(&zone, argp, sizeof(zone)))
- goto out;
+ return -EFAULT;
r = kvm_vm_ioctl_register_coalesced_mmio(kvm, &zone);
break;
}
case KVM_UNREGISTER_COALESCED_MMIO: {
struct kvm_coalesced_mmio_zone zone;
- r = -EFAULT;
if (copy_from_user(&zone, argp, sizeof(zone)))
- goto out;
+ return -EFAULT;
r = kvm_vm_ioctl_unregister_coalesced_mmio(kvm, &zone);
break;
}
@@ -3000,18 +2995,16 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_IRQFD: {
struct kvm_irqfd data;
- r = -EFAULT;
if (copy_from_user(&data, argp, sizeof(data)))
- goto out;
+ return -EFAULT;
r = kvm_irqfd(kvm, &data);
break;
}
case KVM_IOEVENTFD: {
struct kvm_ioeventfd data;
- r = -EFAULT;
if (copy_from_user(&data, argp, sizeof(data)))
- goto out;
+ return -EFAULT;
r = kvm_ioeventfd(kvm, &data);
break;
}
@@ -3019,9 +3012,8 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_SIGNAL_MSI: {
struct kvm_msi msi;
- r = -EFAULT;
if (copy_from_user(&msi, argp, sizeof(msi)))
- goto out;
+ return -EFAULT;
r = kvm_send_userspace_msi(kvm, &msi);
break;
}
@@ -3031,22 +3023,17 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_IRQ_LINE: {
struct kvm_irq_level irq_event;
- r = -EFAULT;
if (copy_from_user(&irq_event, argp, sizeof(irq_event)))
- goto out;
+ return -EFAULT;
r = kvm_vm_ioctl_irq_line(kvm, &irq_event,
ioctl = KVM_IRQ_LINE_STATUS);
if (r)
- goto out;
-
- r = -EFAULT;
- if (ioctl = KVM_IRQ_LINE_STATUS) {
- if (copy_to_user(argp, &irq_event, sizeof(irq_event)))
- goto out;
- }
+ return r;
- r = 0;
+ if (ioctl = KVM_IRQ_LINE_STATUS &&
+ copy_to_user(argp, &irq_event, sizeof(irq_event)))
+ return -EFAULT;
break;
}
#endif
@@ -3056,24 +3043,20 @@ static long kvm_vm_ioctl(struct file *filp,
struct kvm_irq_routing __user *urouting;
struct kvm_irq_routing_entry *entries = NULL;
- r = -EFAULT;
if (copy_from_user(&routing, argp, sizeof(routing)))
- goto out;
- r = -EINVAL;
- if (routing.nr > KVM_MAX_IRQ_ROUTES)
- goto out;
- if (routing.flags)
- goto out;
+ return -EFAULT;
+ if (routing.nr > KVM_MAX_IRQ_ROUTES || routing.flags)
+ return -EINVAL;
if (routing.nr) {
- r = -ENOMEM;
entries = vmalloc(routing.nr * sizeof(*entries));
if (!entries)
- goto out;
- r = -EFAULT;
+ return -ENOMEM;
urouting = argp;
if (copy_from_user(entries, urouting->entries,
- routing.nr * sizeof(*entries)))
+ routing.nr * sizeof(*entries))) {
+ r = -EFAULT;
goto out_free_irq_routing;
+ }
}
r = kvm_set_irq_routing(kvm, entries, routing.nr,
routing.flags);
@@ -3085,19 +3068,15 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_CREATE_DEVICE: {
struct kvm_create_device cd;
- r = -EFAULT;
if (copy_from_user(&cd, argp, sizeof(cd)))
- goto out;
+ return -EFAULT;
r = kvm_ioctl_create_device(kvm, &cd);
if (r)
- goto out;
+ return r;
- r = -EFAULT;
if (copy_to_user(argp, &cd, sizeof(cd)))
- goto out;
-
- r = 0;
+ return -EFAULT;
break;
}
case KVM_CHECK_EXTENSION:
@@ -3106,7 +3085,6 @@ static long kvm_vm_ioctl(struct file *filp,
default:
r = kvm_arch_vm_ioctl(filp, ioctl, arg);
}
-out:
return r;
}
--
2.11.0
next prev parent reply other threads:[~2017-01-22 18:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-22 18:09 [PATCH 0/9] KVM: Fine-tuning for several function implementations SF Markus Elfring
2017-01-22 18:11 ` [PATCH 1/9] KVM: Return directly after a failed copy_from_user() in kvm_vm_compat_ioctl() SF Markus Elfring
2017-01-22 18:12 ` SF Markus Elfring [this message]
2017-01-22 18:13 ` [PATCH 3/9] KVM: Move error code settings in kvm_vcpu_compat_ioctl() SF Markus Elfring
2017-01-22 18:14 ` [PATCH 4/9] KVM: Move error code settings in kvm_vcpu_ioctl() SF Markus Elfring
2017-01-22 18:15 ` [PATCH 5/9] KVM: Improve size determinations " SF Markus Elfring
2017-01-22 18:16 ` [PATCH 6/9] KVM: Return an error code only as a constant in kvm_get_dirty_log_protect() SF Markus Elfring
2017-01-22 18:17 ` [PATCH 7/9] KVM: Return an error code only as a constant in kvm_get_dirty_log() SF Markus Elfring
2017-01-22 18:18 ` [PATCH 8/9] KVM: Adjust seven checks for null pointers SF Markus Elfring
2017-01-22 20:32 ` kbuild test robot
2017-01-22 21:35 ` kbuild test robot
2017-01-23 9:30 ` Dan Carpenter
2017-01-22 18:19 ` [PATCH 9/9] KVM: Improve another size determination in kvm_create_vm() SF Markus Elfring
2017-01-23 9:22 ` [PATCH 0/9] KVM: Fine-tuning for several function implementations Paolo Bonzini
2017-01-23 9:48 ` SF Markus Elfring
2017-01-23 14:06 ` Paolo Bonzini
2017-01-24 2:15 ` Bernd Petrovitsch
2017-01-24 11:36 ` SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18acab5d-a10d-77c0-8e8c-67bbaa1f0edb@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox