All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] cleanup of redundant statements
@ 2014-09-04 19:13 Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 1/3] KVM: remove redundant check of in_spin_loop Christian Borntraeger
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christian Borntraeger @ 2014-09-04 19:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Gleb Natapov, Christian Borntraeger

Paolo,

I was playing with some static code checkers. Here is some "fallout"
from the kvm common code. Only minor things that are not real error,
just redundant statements.

One could argue here and there that these statement make the code easier
to understand. So, please have a look and either drop or apply the patches.

Christian Borntraeger (3):
  KVM: remove redundant check of in_spin_loop
  KVM: remove redundant assigment of return value in kvm_dev_ioctl
  KVM: remove redundant assignments in __kvm_set_memory_region

 virt/kvm/kvm_main.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

-- 
1.8.4.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] KVM: remove redundant check of in_spin_loop
  2014-09-04 19:13 [PATCH 0/3] cleanup of redundant statements Christian Borntraeger
@ 2014-09-04 19:13 ` Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 2/3] KVM: remove redundant assigment of return value in kvm_dev_ioctl Christian Borntraeger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2014-09-04 19:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Gleb Natapov, Christian Borntraeger

The expression `vcpu->spin_loop.in_spin_loop' is always true,
because it is evaluated only when the condition
`!vcpu->spin_loop.in_spin_loop' is false.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 virt/kvm/kvm_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7176929..0a824a0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1768,10 +1768,9 @@ static bool kvm_vcpu_eligible_for_directed_yield(struct kvm_vcpu *vcpu)
 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
 	bool eligible;
 
 	eligible = !vcpu->spin_loop.in_spin_loop ||
-			(vcpu->spin_loop.in_spin_loop &&
-			 vcpu->spin_loop.dy_eligible);
+		    vcpu->spin_loop.dy_eligible;
 
 	if (vcpu->spin_loop.in_spin_loop)
 		kvm_vcpu_set_dy_eligible(vcpu, !vcpu->spin_loop.dy_eligible);
 
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] KVM: remove redundant assigment of return value in kvm_dev_ioctl
  2014-09-04 19:13 [PATCH 0/3] cleanup of redundant statements Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 1/3] KVM: remove redundant check of in_spin_loop Christian Borntraeger
@ 2014-09-04 19:13 ` Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 3/3] KVM: remove redundant assignments in __kvm_set_memory_region Christian Borntraeger
  2014-09-04 20:39 ` [PATCH 0/3] cleanup of redundant statements Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2014-09-04 19:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Gleb Natapov, Christian Borntraeger

The first statement of kvm_dev_ioctl is
        long r = -EINVAL;

No need to reassign the same value.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 virt/kvm/kvm_main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 0a824a0..5ea65d2 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2610,9 +2610,8 @@ static long kvm_dev_ioctl(struct file *filp,
 	long r = -EINVAL;
 
 	switch (ioctl) {
 	case KVM_GET_API_VERSION:
-		r = -EINVAL;
 		if (arg)
 			goto out;
 		r = KVM_API_VERSION;
 		break;
@@ -2622,9 +2621,8 @@ static long kvm_dev_ioctl(struct file *filp,
 	case KVM_CHECK_EXTENSION:
 		r = kvm_vm_ioctl_check_extension_generic(NULL, arg);
 		break;
 	case KVM_GET_VCPU_MMAP_SIZE:
-		r = -EINVAL;
 		if (arg)
 			goto out;
 		r = PAGE_SIZE;     /* struct kvm_run */
 #ifdef CONFIG_X86
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] KVM: remove redundant assignments in __kvm_set_memory_region
  2014-09-04 19:13 [PATCH 0/3] cleanup of redundant statements Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 1/3] KVM: remove redundant check of in_spin_loop Christian Borntraeger
  2014-09-04 19:13 ` [PATCH 2/3] KVM: remove redundant assigment of return value in kvm_dev_ioctl Christian Borntraeger
@ 2014-09-04 19:13 ` Christian Borntraeger
  2014-09-04 20:39 ` [PATCH 0/3] cleanup of redundant statements Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2014-09-04 19:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Gleb Natapov, Christian Borntraeger

__kvm_set_memory_region sets r to EINVAL very early.
Doing it again is not necessary. The same is true later on, where
r is assigned -ENOMEM twice.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 virt/kvm/kvm_main.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 5ea65d2..2d868ad 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -776,9 +776,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	slot = id_to_memslot(kvm->memslots, mem->slot);
 	base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
 	npages = mem->memory_size >> PAGE_SHIFT;
 
-	r = -EINVAL;
 	if (npages > KVM_MEM_MAX_NR_PAGES)
 		goto out;
 
 	if (!npages)
@@ -790,9 +789,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	new.base_gfn = base_gfn;
 	new.npages = npages;
 	new.flags = mem->flags;
 
-	r = -EINVAL;
 	if (npages) {
 		if (!old.npages)
 			change = KVM_MR_CREATE;
 		else { /* Modify an existing slot. */
@@ -846,9 +844,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
 			goto out_free;
 	}
 
 	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
-		r = -ENOMEM;
 		slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
 				GFP_KERNEL);
 		if (!slots)
 			goto out_free;
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] cleanup of redundant statements
  2014-09-04 19:13 [PATCH 0/3] cleanup of redundant statements Christian Borntraeger
                   ` (2 preceding siblings ...)
  2014-09-04 19:13 ` [PATCH 3/3] KVM: remove redundant assignments in __kvm_set_memory_region Christian Borntraeger
@ 2014-09-04 20:39 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-09-04 20:39 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, Gleb Natapov

Il 04/09/2014 21:13, Christian Borntraeger ha scritto:
> Paolo,
> 
> I was playing with some static code checkers. Here is some "fallout"
> from the kvm common code. Only minor things that are not real error,
> just redundant statements.
> 
> One could argue here and there that these statement make the code easier
> to understand. So, please have a look and either drop or apply the patches.

I think all the patches are an improvement.  Thanks!

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-09-04 20:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-04 19:13 [PATCH 0/3] cleanup of redundant statements Christian Borntraeger
2014-09-04 19:13 ` [PATCH 1/3] KVM: remove redundant check of in_spin_loop Christian Borntraeger
2014-09-04 19:13 ` [PATCH 2/3] KVM: remove redundant assigment of return value in kvm_dev_ioctl Christian Borntraeger
2014-09-04 19:13 ` [PATCH 3/3] KVM: remove redundant assignments in __kvm_set_memory_region Christian Borntraeger
2014-09-04 20:39 ` [PATCH 0/3] cleanup of redundant statements Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.