[PATCH] Virt: Kvm - Improvement in code readability when

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Shailendra Verma" <shailendra.v@xxxxxxxxxxx>

There is no need to call kfree() if memdup_user() fails, as no memory
was allocated and the error in the error-valued pointer should be returned.

Signed-off-by: Shailendra Verma <shailendra.v@xxxxxxxxxxx>
---
 virt/kvm/kvm_main.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2907b7b..45e0af4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2581,8 +2581,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = -ENOMEM;
 		kvm_regs = memdup_user(argp, sizeof(*kvm_regs));
 		if (IS_ERR(kvm_regs)) {
-			r = PTR_ERR(kvm_regs);
-			goto out;
+			vcpu_put(vcpu);
+			return PTR_ERR(kvm_regs);
 		}
 		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
 		kfree(kvm_regs);
@@ -2605,9 +2605,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
 	case KVM_SET_SREGS: {
 		kvm_sregs = memdup_user(argp, sizeof(*kvm_sregs));
 		if (IS_ERR(kvm_sregs)) {
-			r = PTR_ERR(kvm_sregs);
-			kvm_sregs = NULL;
-			goto out;
+			vcpu_put(vcpu);
+			return PTR_ERR(kvm_sregs);
 		}
 		r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs);
 		break;
@@ -2697,9 +2696,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
 	case KVM_SET_FPU: {
 		fpu = memdup_user(argp, sizeof(*fpu));
 		if (IS_ERR(fpu)) {
-			r = PTR_ERR(fpu);
-			fpu = NULL;
-			goto out;
+			vcpu_put(vcpu);
+			return PTR_ERR(fpu);
 		}
 		r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
 		break;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux