kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Virt: Kvm - Improvement in code readability when
@ 2016-11-10  9:50 Shailendra Verma
  0 siblings, 0 replies; only message in thread
From: Shailendra Verma @ 2016-11-10  9:50 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini, kvm, Shailendra Verma,
	Shailendra Verma
  Cc: linux-kernel, vidushi.koul

From: "Shailendra Verma" <shailendra.v@samsung.com>

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@samsung.com>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-10  9:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-10  9:50 [PATCH] Virt: Kvm - Improvement in code readability when Shailendra Verma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).