All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] PowerPC-KVM: Fine-tuning for some function implementations
@ 2017-01-20 18:18 ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:18 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 19:07:21 +0100

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (11):
  Move assignments for the variable "err" in kvm_htab_write()
  Improve a size determination in kvmppc_alloc_hpt()
  Move error code assignments in two functions
  Use common error handling code in kvmppc_clr_passthru_irq()
  Adjust nine checks for null pointers
  Use kcalloc() in kvmppc_alloc_host_rm_ops()
  Improve size determinations in five functions
  Use seq_puts() in xics_debug_show()
  Improve a size determination in two functions
  Use kcalloc() in e500_mmu_host_init()
  Return directly after a failed copy_from_user() in two functions

 arch/powerpc/kvm/book3s_64_mmu_hv.c | 26 +++++++------
 arch/powerpc/kvm/book3s_hv.c        | 73 +++++++++++++++++++------------------
 arch/powerpc/kvm/book3s_xics.c      |  7 ++--
 arch/powerpc/kvm/e500_mmu_host.c    |  5 +--
 arch/powerpc/kvm/powerpc.c          | 48 ++++++++++--------------
 5 files changed, 75 insertions(+), 84 deletions(-)

-- 
2.11.0

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

* [PATCH 00/11] PowerPC-KVM: Fine-tuning for some function implementations
@ 2017-01-20 18:18 ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:18 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 19:07:21 +0100

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (11):
  Move assignments for the variable "err" in kvm_htab_write()
  Improve a size determination in kvmppc_alloc_hpt()
  Move error code assignments in two functions
  Use common error handling code in kvmppc_clr_passthru_irq()
  Adjust nine checks for null pointers
  Use kcalloc() in kvmppc_alloc_host_rm_ops()
  Improve size determinations in five functions
  Use seq_puts() in xics_debug_show()
  Improve a size determination in two functions
  Use kcalloc() in e500_mmu_host_init()
  Return directly after a failed copy_from_user() in two functions

 arch/powerpc/kvm/book3s_64_mmu_hv.c | 26 +++++++------
 arch/powerpc/kvm/book3s_hv.c        | 73 +++++++++++++++++++------------------
 arch/powerpc/kvm/book3s_xics.c      |  7 ++--
 arch/powerpc/kvm/e500_mmu_host.c    |  5 +--
 arch/powerpc/kvm/powerpc.c          | 48 ++++++++++--------------
 5 files changed, 75 insertions(+), 84 deletions(-)

-- 
2.11.0


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

* [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:19   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:19 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Jan 2017 22:45:56 +0100

* A local variable was set to an error code in five cases
  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.

* Delete two zero assignments which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index b795dd1ac2ef..dc34729e4ad0 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 
 	err = 0;
 	for (nb = 0; nb + sizeof(hdr) <= count; ) {
-		err = -EFAULT;
-		if (__copy_from_user(&hdr, buf, sizeof(hdr)))
+		if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
+			err = -EFAULT;
 			break;
+		}
 
-		err = 0;
 		if (nb + hdr.n_valid * HPTE_SIZE > count)
 			break;
 
 		nb += sizeof(hdr);
 		buf += sizeof(hdr);
 
-		err = -EINVAL;
 		i = hdr.index;
 		if (i >= kvm->arch.hpt_npte ||
-		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
+		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
+			err = -EINVAL;
 			break;
+		}
 
 		hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
 		lbuf = (unsigned long __user *)buf;
@@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			__be64 hpte_v;
 			__be64 hpte_r;
 
-			err = -EFAULT;
 			if (__get_user(hpte_v, lbuf) ||
-			    __get_user(hpte_r, lbuf + 1))
+			    __get_user(hpte_r, lbuf + 1)) {
+				err = -EFAULT;
 				goto out;
+			}
 			v = be64_to_cpu(hpte_v);
 			r = be64_to_cpu(hpte_r);
-			err = -EINVAL;
-			if (!(v & HPTE_V_VALID))
+			if (!(v & HPTE_V_VALID)) {
+				err = -EINVAL;
 				goto out;
+			}
 			lbuf += 2;
 			nb += HPTE_SIZE;
 
 			if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
 				kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
-			err = -EIO;
 			ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
 							 tmp);
 			if (ret != H_SUCCESS) {
 				pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
 				       "r=%lx\n", ret, i, v, r);
+				err = -EIO;
 				goto out;
 			}
 			if (!hpte_setup && is_vrma_hpte(v)) {
@@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			++i;
 			hptp += 2;
 		}
-		err = 0;
 	}
 
  out:
-- 
2.11.0

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

* [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
@ 2017-01-20 18:19   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:19 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Jan 2017 22:45:56 +0100

* A local variable was set to an error code in five cases
  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.

* Delete two zero assignments which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index b795dd1ac2ef..dc34729e4ad0 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 
 	err = 0;
 	for (nb = 0; nb + sizeof(hdr) <= count; ) {
-		err = -EFAULT;
-		if (__copy_from_user(&hdr, buf, sizeof(hdr)))
+		if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
+			err = -EFAULT;
 			break;
+		}
 
-		err = 0;
 		if (nb + hdr.n_valid * HPTE_SIZE > count)
 			break;
 
 		nb += sizeof(hdr);
 		buf += sizeof(hdr);
 
-		err = -EINVAL;
 		i = hdr.index;
 		if (i >= kvm->arch.hpt_npte ||
-		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
+		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
+			err = -EINVAL;
 			break;
+		}
 
 		hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
 		lbuf = (unsigned long __user *)buf;
@@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			__be64 hpte_v;
 			__be64 hpte_r;
 
-			err = -EFAULT;
 			if (__get_user(hpte_v, lbuf) ||
-			    __get_user(hpte_r, lbuf + 1))
+			    __get_user(hpte_r, lbuf + 1)) {
+				err = -EFAULT;
 				goto out;
+			}
 			v = be64_to_cpu(hpte_v);
 			r = be64_to_cpu(hpte_r);
-			err = -EINVAL;
-			if (!(v & HPTE_V_VALID))
+			if (!(v & HPTE_V_VALID)) {
+				err = -EINVAL;
 				goto out;
+			}
 			lbuf += 2;
 			nb += HPTE_SIZE;
 
 			if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
 				kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
-			err = -EIO;
 			ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
 							 tmp);
 			if (ret != H_SUCCESS) {
 				pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
 				       "r=%lx\n", ret, i, v, r);
+				err = -EIO;
 				goto out;
 			}
 			if (!hpte_setup && is_vrma_hpte(v)) {
@@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
 			++i;
 			hptp += 2;
 		}
-		err = 0;
 	}
 
  out:
-- 
2.11.0


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

* [PATCH 02/11] KVM: PPC: Book3S HV: Improve a size determination in kvmppc_alloc_hpt()
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:20   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:20 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 10:00:13 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index dc34729e4ad0..4655f27e0518 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -91,7 +91,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
 	atomic64_set(&kvm->arch.mmio_update, 0);
 
 	/* Allocate reverse map array */
-	rev = vmalloc(sizeof(struct revmap_entry) * kvm->arch.hpt_npte);
+	rev = vmalloc(sizeof(*rev) * kvm->arch.hpt_npte);
 	if (!rev) {
 		pr_err("kvmppc_alloc_hpt: Couldn't alloc reverse map array\n");
 		goto out_freehpt;
-- 
2.11.0

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

* [PATCH 02/11] KVM: PPC: Book3S HV: Improve a size determination in kvmppc_alloc_hpt()
@ 2017-01-20 18:20   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:20 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 10:00:13 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index dc34729e4ad0..4655f27e0518 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -91,7 +91,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
 	atomic64_set(&kvm->arch.mmio_update, 0);
 
 	/* Allocate reverse map array */
-	rev = vmalloc(sizeof(struct revmap_entry) * kvm->arch.hpt_npte);
+	rev = vmalloc(sizeof(*rev) * kvm->arch.hpt_npte);
 	if (!rev) {
 		pr_err("kvmppc_alloc_hpt: Couldn't alloc reverse map array\n");
 		goto out_freehpt;
-- 
2.11.0


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

* [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:21   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:21 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 10:30:26 +0100

A local variable was set to an error code in a few cases 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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 8dcbe37a4dac..a93e1c4445da 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2967,15 +2967,17 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
 
 	mutex_lock(&kvm->slots_lock);
 
-	r = -EINVAL;
-	if (log->slot >= KVM_USER_MEM_SLOTS)
+	if (log->slot >= KVM_USER_MEM_SLOTS) {
+		r = -EINVAL;
 		goto out;
+	}
 
 	slots = kvm_memslots(kvm);
 	memslot = id_to_memslot(slots, log->slot);
-	r = -ENOENT;
-	if (!memslot->dirty_bitmap)
+	if (!memslot->dirty_bitmap) {
+		r = -ENOENT;
 		goto out;
+	}
 
 	n = kvm_dirty_bitmap_bytes(memslot);
 	memset(memslot->dirty_bitmap, 0, n);
@@ -2984,9 +2986,10 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
 	if (r)
 		goto out;
 
-	r = -EFAULT;
-	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
+	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) {
+		r = -EFAULT;
 		goto out;
+	}
 
 	r = 0;
 out:
@@ -3127,9 +3130,10 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
 	memslot = gfn_to_memslot(kvm, 0);
 
 	/* We must have some memory at 0 by now */
-	err = -EINVAL;
-	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
+	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
+		err = -EINVAL;
 		goto out_srcu;
+	}
 
 	/* Look up the VMA for the start of this memory slot */
 	hva = memslot->userspace_addr;
@@ -3144,10 +3148,11 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
 	up_read(&current->mm->mmap_sem);
 
 	/* We can handle 4k, 64k or 16M pages in the VRMA */
-	err = -EINVAL;
 	if (!(psize == 0x1000 || psize == 0x10000 ||
-	      psize == 0x1000000))
+	      psize == 0x1000000)) {
+		err = -EINVAL;
 		goto out_srcu;
+	}
 
 	senc = slb_pgsize_encoding(psize);
 	kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
-- 
2.11.0

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

* [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions
@ 2017-01-20 18:21   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:21 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 10:30:26 +0100

A local variable was set to an error code in a few cases 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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 8dcbe37a4dac..a93e1c4445da 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2967,15 +2967,17 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
 
 	mutex_lock(&kvm->slots_lock);
 
-	r = -EINVAL;
-	if (log->slot >= KVM_USER_MEM_SLOTS)
+	if (log->slot >= KVM_USER_MEM_SLOTS) {
+		r = -EINVAL;
 		goto out;
+	}
 
 	slots = kvm_memslots(kvm);
 	memslot = id_to_memslot(slots, log->slot);
-	r = -ENOENT;
-	if (!memslot->dirty_bitmap)
+	if (!memslot->dirty_bitmap) {
+		r = -ENOENT;
 		goto out;
+	}
 
 	n = kvm_dirty_bitmap_bytes(memslot);
 	memset(memslot->dirty_bitmap, 0, n);
@@ -2984,9 +2986,10 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
 	if (r)
 		goto out;
 
-	r = -EFAULT;
-	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
+	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) {
+		r = -EFAULT;
 		goto out;
+	}
 
 	r = 0;
 out:
@@ -3127,9 +3130,10 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
 	memslot = gfn_to_memslot(kvm, 0);
 
 	/* We must have some memory at 0 by now */
-	err = -EINVAL;
-	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
+	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
+		err = -EINVAL;
 		goto out_srcu;
+	}
 
 	/* Look up the VMA for the start of this memory slot */
 	hva = memslot->userspace_addr;
@@ -3144,10 +3148,11 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
 	up_read(&current->mm->mmap_sem);
 
 	/* We can handle 4k, 64k or 16M pages in the VRMA */
-	err = -EINVAL;
 	if (!(psize = 0x1000 || psize = 0x10000 ||
-	      psize = 0x1000000))
+	      psize = 0x1000000)) {
+		err = -EINVAL;
 		goto out_srcu;
+	}
 
 	senc = slb_pgsize_encoding(psize);
 	kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
-- 
2.11.0


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

* [PATCH 04/11] KVM: PPC: Book3S HV: Use common error handling code in kvmppc_clr_passthru_irq()
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:22   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:22 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:00:08 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index a93e1c4445da..cfc7699d05df 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3509,11 +3509,9 @@ static int kvmppc_clr_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 		return -EIO;
 
 	mutex_lock(&kvm->lock);
+	if (!kvm->arch.pimap)
+		goto unlock;
 
-	if (kvm->arch.pimap == NULL) {
-		mutex_unlock(&kvm->lock);
-		return 0;
-	}
 	pimap = kvm->arch.pimap;
 
 	for (i = 0; i < pimap->n_mapped; i++) {
@@ -3535,7 +3533,7 @@ static int kvmppc_clr_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	 * We don't free this structure even when the count goes to
 	 * zero. The structure is freed when we destroy the VM.
 	 */
-
+unlock:
 	mutex_unlock(&kvm->lock);
 	return 0;
 }
-- 
2.11.0

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

* [PATCH 04/11] KVM: PPC: Book3S HV: Use common error handling code in kvmppc_clr_passthru_irq()
@ 2017-01-20 18:22   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:22 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:00:08 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index a93e1c4445da..cfc7699d05df 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3509,11 +3509,9 @@ static int kvmppc_clr_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 		return -EIO;
 
 	mutex_lock(&kvm->lock);
+	if (!kvm->arch.pimap)
+		goto unlock;
 
-	if (kvm->arch.pimap = NULL) {
-		mutex_unlock(&kvm->lock);
-		return 0;
-	}
 	pimap = kvm->arch.pimap;
 
 	for (i = 0; i < pimap->n_mapped; i++) {
@@ -3535,7 +3533,7 @@ static int kvmppc_clr_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	 * We don't free this structure even when the count goes to
 	 * zero. The structure is freed when we destroy the VM.
 	 */
-
+unlock:
 	mutex_unlock(&kvm->lock);
 	return 0;
 }
-- 
2.11.0


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

* [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
  2017-01-20 18:18 ` SF Markus Elfring
  (?)
  (?)
@ 2017-01-20 18:23   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:23 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:25:48 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index cfc7699d05df..3122998f6a32 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
 
 		/* convert logical addr to kernel addr and read length */
 		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
-		if (va == NULL)
+		if (!va)
 			return H_PARAMETER;
 		if (subfunc == H_VPA_REG_VPA)
 			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
@@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 	struct kvmppc_vcore *vcore;
 
 	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
-
-	if (vcore == NULL)
+	if (!vcore)
 		return NULL;
 
 	spin_lock_init(&vcore->lock);
@@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
 		prepare_threads(pvc);
 		if (!pvc->n_runnable) {
 			list_del_init(&pvc->preempt_list);
-			if (pvc->runner == NULL) {
+			if (!pvc->runner) {
 				pvc->vcore_state = VCORE_INACTIVE;
 				kvmppc_core_end_stolen(pvc);
 			}
@@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
 		} else {
 			vc->vcore_state = VCORE_INACTIVE;
 		}
-		if (vc->n_runnable > 0 && vc->runner == NULL) {
+		if (vc->n_runnable > 0 && !vc->runner) {
 			/* make sure there's a candidate runner awake */
 			i = -1;
 			vcpu = next_runnable_thread(vc, &i);
@@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
 	       !signal_pending(current)) {
-		if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
+		if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
 			kvmppc_vcore_end_preempt(vc);
 
 		if (vc->vcore_state != VCORE_INACTIVE) {
@@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		vc->vcore_state == VCORE_PIGGYBACK))
 		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
 
-	if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
+	if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
 		kvmppc_vcore_end_preempt(vc);
 
 	if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
@@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	int size;
 
 	/* Not the first time here ? */
-	if (kvmppc_host_rm_ops_hv != NULL)
+	if (kvmppc_host_rm_ops_hv)
 		return;
 
 	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
@@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	mutex_lock(&kvm->lock);
 
 	pimap = kvm->arch.pimap;
-	if (pimap == NULL) {
+	if (!pimap) {
 		/* First call, allocate structure to hold IRQ map */
 		pimap = kvmppc_alloc_pimap();
-		if (pimap == NULL) {
+		if (!pimap) {
 			mutex_unlock(&kvm->lock);
 			return -ENOMEM;
 		}
-- 
2.11.0

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

* [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
@ 2017-01-20 18:23   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:23 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: kernel-janitors, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:25:48 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index cfc7699d05df..3122998f6a32 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
 
 		/* convert logical addr to kernel addr and read length */
 		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
-		if (va = NULL)
+		if (!va)
 			return H_PARAMETER;
 		if (subfunc = H_VPA_REG_VPA)
 			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
@@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 	struct kvmppc_vcore *vcore;
 
 	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
-
-	if (vcore = NULL)
+	if (!vcore)
 		return NULL;
 
 	spin_lock_init(&vcore->lock);
@@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
 		prepare_threads(pvc);
 		if (!pvc->n_runnable) {
 			list_del_init(&pvc->preempt_list);
-			if (pvc->runner = NULL) {
+			if (!pvc->runner) {
 				pvc->vcore_state = VCORE_INACTIVE;
 				kvmppc_core_end_stolen(pvc);
 			}
@@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
 		} else {
 			vc->vcore_state = VCORE_INACTIVE;
 		}
-		if (vc->n_runnable > 0 && vc->runner = NULL) {
+		if (vc->n_runnable > 0 && !vc->runner) {
 			/* make sure there's a candidate runner awake */
 			i = -1;
 			vcpu = next_runnable_thread(vc, &i);
@@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	while (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE &&
 	       !signal_pending(current)) {
-		if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
+		if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
 			kvmppc_vcore_end_preempt(vc);
 
 		if (vc->vcore_state != VCORE_INACTIVE) {
@@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		vc->vcore_state = VCORE_PIGGYBACK))
 		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
 
-	if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
+	if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
 		kvmppc_vcore_end_preempt(vc);
 
 	if (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE) {
@@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	int size;
 
 	/* Not the first time here ? */
-	if (kvmppc_host_rm_ops_hv != NULL)
+	if (kvmppc_host_rm_ops_hv)
 		return;
 
 	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
@@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	mutex_lock(&kvm->lock);
 
 	pimap = kvm->arch.pimap;
-	if (pimap = NULL) {
+	if (!pimap) {
 		/* First call, allocate structure to hold IRQ map */
 		pimap = kvmppc_alloc_pimap();
-		if (pimap = NULL) {
+		if (!pimap) {
 			mutex_unlock(&kvm->lock);
 			return -ENOMEM;
 		}
-- 
2.11.0

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

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

* [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
@ 2017-01-20 18:23   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:23 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: kernel-janitors, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:25:48 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index cfc7699d05df..3122998f6a32 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
 
 		/* convert logical addr to kernel addr and read length */
 		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
-		if (va == NULL)
+		if (!va)
 			return H_PARAMETER;
 		if (subfunc == H_VPA_REG_VPA)
 			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
@@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 	struct kvmppc_vcore *vcore;
 
 	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
-
-	if (vcore == NULL)
+	if (!vcore)
 		return NULL;
 
 	spin_lock_init(&vcore->lock);
@@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
 		prepare_threads(pvc);
 		if (!pvc->n_runnable) {
 			list_del_init(&pvc->preempt_list);
-			if (pvc->runner == NULL) {
+			if (!pvc->runner) {
 				pvc->vcore_state = VCORE_INACTIVE;
 				kvmppc_core_end_stolen(pvc);
 			}
@@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
 		} else {
 			vc->vcore_state = VCORE_INACTIVE;
 		}
-		if (vc->n_runnable > 0 && vc->runner == NULL) {
+		if (vc->n_runnable > 0 && !vc->runner) {
 			/* make sure there's a candidate runner awake */
 			i = -1;
 			vcpu = next_runnable_thread(vc, &i);
@@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
 	       !signal_pending(current)) {
-		if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
+		if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
 			kvmppc_vcore_end_preempt(vc);
 
 		if (vc->vcore_state != VCORE_INACTIVE) {
@@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		vc->vcore_state == VCORE_PIGGYBACK))
 		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
 
-	if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
+	if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
 		kvmppc_vcore_end_preempt(vc);
 
 	if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
@@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	int size;
 
 	/* Not the first time here ? */
-	if (kvmppc_host_rm_ops_hv != NULL)
+	if (kvmppc_host_rm_ops_hv)
 		return;
 
 	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
@@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	mutex_lock(&kvm->lock);
 
 	pimap = kvm->arch.pimap;
-	if (pimap == NULL) {
+	if (!pimap) {
 		/* First call, allocate structure to hold IRQ map */
 		pimap = kvmppc_alloc_pimap();
-		if (pimap == NULL) {
+		if (!pimap) {
 			mutex_unlock(&kvm->lock);
 			return -ENOMEM;
 		}
-- 
2.11.0

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

* [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
@ 2017-01-20 18:23   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:23 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 11:25:48 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written …

Thus fix affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index cfc7699d05df..3122998f6a32 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
 
 		/* convert logical addr to kernel addr and read length */
 		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
-		if (va = NULL)
+		if (!va)
 			return H_PARAMETER;
 		if (subfunc = H_VPA_REG_VPA)
 			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
@@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 	struct kvmppc_vcore *vcore;
 
 	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
-
-	if (vcore = NULL)
+	if (!vcore)
 		return NULL;
 
 	spin_lock_init(&vcore->lock);
@@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
 		prepare_threads(pvc);
 		if (!pvc->n_runnable) {
 			list_del_init(&pvc->preempt_list);
-			if (pvc->runner = NULL) {
+			if (!pvc->runner) {
 				pvc->vcore_state = VCORE_INACTIVE;
 				kvmppc_core_end_stolen(pvc);
 			}
@@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
 		} else {
 			vc->vcore_state = VCORE_INACTIVE;
 		}
-		if (vc->n_runnable > 0 && vc->runner = NULL) {
+		if (vc->n_runnable > 0 && !vc->runner) {
 			/* make sure there's a candidate runner awake */
 			i = -1;
 			vcpu = next_runnable_thread(vc, &i);
@@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	while (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE &&
 	       !signal_pending(current)) {
-		if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
+		if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
 			kvmppc_vcore_end_preempt(vc);
 
 		if (vc->vcore_state != VCORE_INACTIVE) {
@@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		vc->vcore_state = VCORE_PIGGYBACK))
 		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
 
-	if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
+	if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
 		kvmppc_vcore_end_preempt(vc);
 
 	if (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE) {
@@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	int size;
 
 	/* Not the first time here ? */
-	if (kvmppc_host_rm_ops_hv != NULL)
+	if (kvmppc_host_rm_ops_hv)
 		return;
 
 	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
@@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
 	mutex_lock(&kvm->lock);
 
 	pimap = kvm->arch.pimap;
-	if (pimap = NULL) {
+	if (!pimap) {
 		/* First call, allocate structure to hold IRQ map */
 		pimap = kvmppc_alloc_pimap();
-		if (pimap = NULL) {
+		if (!pimap) {
 			mutex_unlock(&kvm->lock);
 			return -ENOMEM;
 		}
-- 
2.11.0


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

* [PATCH 06/11] KVM: PPC: Book3S HV: Use kcalloc() in kvmppc_alloc_host_rm_ops()
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:24   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:24 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:20:43 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Delete the local variable "size" which became unnecessary
  with this refactoring.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 3122998f6a32..596201b3f22e 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3199,7 +3199,6 @@ void kvmppc_alloc_host_rm_ops(void)
 	struct kvmppc_host_rm_ops *ops;
 	unsigned long l_ops;
 	int cpu, core;
-	int size;
 
 	/* Not the first time here ? */
 	if (kvmppc_host_rm_ops_hv)
@@ -3209,9 +3208,9 @@ void kvmppc_alloc_host_rm_ops(void)
 	if (!ops)
 		return;
 
-	size = cpu_nr_cores() * sizeof(struct kvmppc_host_rm_core);
-	ops->rm_core = kzalloc(size, GFP_KERNEL);
-
+	ops->rm_core = kcalloc(cpu_nr_cores(),
+			       sizeof(*ops->rm_core),
+			       GFP_KERNEL);
 	if (!ops->rm_core) {
 		kfree(ops);
 		return;
-- 
2.11.0

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

* [PATCH 06/11] KVM: PPC: Book3S HV: Use kcalloc() in kvmppc_alloc_host_rm_ops()
@ 2017-01-20 18:24   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:24 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:20:43 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Delete the local variable "size" which became unnecessary
  with this refactoring.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 3122998f6a32..596201b3f22e 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3199,7 +3199,6 @@ void kvmppc_alloc_host_rm_ops(void)
 	struct kvmppc_host_rm_ops *ops;
 	unsigned long l_ops;
 	int cpu, core;
-	int size;
 
 	/* Not the first time here ? */
 	if (kvmppc_host_rm_ops_hv)
@@ -3209,9 +3208,9 @@ void kvmppc_alloc_host_rm_ops(void)
 	if (!ops)
 		return;
 
-	size = cpu_nr_cores() * sizeof(struct kvmppc_host_rm_core);
-	ops->rm_core = kzalloc(size, GFP_KERNEL);
-
+	ops->rm_core = kcalloc(cpu_nr_cores(),
+			       sizeof(*ops->rm_core),
+			       GFP_KERNEL);
 	if (!ops->rm_core) {
 		kfree(ops);
 		return;
-- 
2.11.0


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

* [PATCH 07/11] KVM: PPC: Book3S HV: Improve size determinations in five functions
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:25   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:25 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:23:30 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 596201b3f22e..9b7a5a8c9e4b 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -655,7 +655,7 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,
 	spin_unlock_irq(&vcpu->arch.tbacct_lock);
 	if (!dt || !vpa)
 		return;
-	memset(dt, 0, sizeof(struct dtl_entry));
+	memset(dt, 0, sizeof(*dt));
 	dt->dispatch_reason = 7;
 	dt->processor_id = cpu_to_be16(vc->pcpu + vcpu->arch.ptid);
 	dt->timebase = cpu_to_be64(now + vc->tb_offset);
@@ -1073,7 +1073,7 @@ static int kvm_arch_vcpu_ioctl_get_sregs_hv(struct kvm_vcpu *vcpu,
 {
 	int i;
 
-	memset(sregs, 0, sizeof(struct kvm_sregs));
+	memset(sregs, 0, sizeof(*sregs));
 	sregs->pvr = vcpu->arch.pvr;
 	for (i = 0; i < vcpu->arch.slb_max; i++) {
 		sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige;
@@ -1590,7 +1590,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 {
 	struct kvmppc_vcore *vcore;
 
-	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
+	vcore = kzalloc(sizeof(*vcore), GFP_KERNEL);
 	if (!vcore)
 		return NULL;
 
@@ -3204,7 +3204,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	if (kvmppc_host_rm_ops_hv)
 		return;
 
-	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
+	ops = kzalloc(sizeof(*ops), GFP_KERNEL);
 	if (!ops)
 		return;
 
@@ -3713,13 +3713,13 @@ static int kvm_init_subcore_bitmap(void)
 			continue;
 
 		sibling_subcore_state =
-			kmalloc_node(sizeof(struct sibling_subcore_state),
-							GFP_KERNEL, node);
+			kmalloc_node(sizeof(*sibling_subcore_state), GFP_KERNEL,
+				     node);
 		if (!sibling_subcore_state)
 			return -ENOMEM;
 
 		memset(sibling_subcore_state, 0,
-				sizeof(struct sibling_subcore_state));
+		       sizeof(*sibling_subcore_state));
 
 		for (j = 0; j < threads_per_core; j++) {
 			int cpu = first_cpu + j;
-- 
2.11.0

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

* [PATCH 07/11] KVM: PPC: Book3S HV: Improve size determinations in five functions
@ 2017-01-20 18:25   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:25 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:23:30 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_hv.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 596201b3f22e..9b7a5a8c9e4b 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -655,7 +655,7 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,
 	spin_unlock_irq(&vcpu->arch.tbacct_lock);
 	if (!dt || !vpa)
 		return;
-	memset(dt, 0, sizeof(struct dtl_entry));
+	memset(dt, 0, sizeof(*dt));
 	dt->dispatch_reason = 7;
 	dt->processor_id = cpu_to_be16(vc->pcpu + vcpu->arch.ptid);
 	dt->timebase = cpu_to_be64(now + vc->tb_offset);
@@ -1073,7 +1073,7 @@ static int kvm_arch_vcpu_ioctl_get_sregs_hv(struct kvm_vcpu *vcpu,
 {
 	int i;
 
-	memset(sregs, 0, sizeof(struct kvm_sregs));
+	memset(sregs, 0, sizeof(*sregs));
 	sregs->pvr = vcpu->arch.pvr;
 	for (i = 0; i < vcpu->arch.slb_max; i++) {
 		sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige;
@@ -1590,7 +1590,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 {
 	struct kvmppc_vcore *vcore;
 
-	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
+	vcore = kzalloc(sizeof(*vcore), GFP_KERNEL);
 	if (!vcore)
 		return NULL;
 
@@ -3204,7 +3204,7 @@ void kvmppc_alloc_host_rm_ops(void)
 	if (kvmppc_host_rm_ops_hv)
 		return;
 
-	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
+	ops = kzalloc(sizeof(*ops), GFP_KERNEL);
 	if (!ops)
 		return;
 
@@ -3713,13 +3713,13 @@ static int kvm_init_subcore_bitmap(void)
 			continue;
 
 		sibling_subcore_state -			kmalloc_node(sizeof(struct sibling_subcore_state),
-							GFP_KERNEL, node);
+			kmalloc_node(sizeof(*sibling_subcore_state), GFP_KERNEL,
+				     node);
 		if (!sibling_subcore_state)
 			return -ENOMEM;
 
 		memset(sibling_subcore_state, 0,
-				sizeof(struct sibling_subcore_state));
+		       sizeof(*sibling_subcore_state));
 
 		for (j = 0; j < threads_per_core; j++) {
 			int cpu = first_cpu + j;
-- 
2.11.0


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

* [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show()
  2017-01-20 18:18 ` SF Markus Elfring
  (?)
  (?)
@ 2017-01-20 18:26   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:26 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:26:51 +0100

A string which did not contain data format specifications should be put
into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3bdc639157c1..3740f9efcf06 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -934,8 +934,7 @@ static int xics_debug_show(struct seq_file *m, void *private)
 	t_reject = 0;
 
 	xics_debugfs_irqmap(m, kvm->arch.pimap);
-
-	seq_printf(m, "=========\nICP state\n=========\n");
+	seq_puts(m, "=========\nICP state\n=========\n");
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		struct kvmppc_icp *icp = vcpu->arch.icp;
-- 
2.11.0

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

* [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show()
@ 2017-01-20 18:26   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:26 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: kernel-janitors, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:26:51 +0100

A string which did not contain data format specifications should be put
into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3bdc639157c1..3740f9efcf06 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -934,8 +934,7 @@ static int xics_debug_show(struct seq_file *m, void *private)
 	t_reject = 0;
 
 	xics_debugfs_irqmap(m, kvm->arch.pimap);
-
-	seq_printf(m, "=====\nICP state\n=====\n");
+	seq_puts(m, "=====\nICP state\n=====\n");
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		struct kvmppc_icp *icp = vcpu->arch.icp;
-- 
2.11.0


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

* [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show()
@ 2017-01-20 18:26   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:26 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: kernel-janitors, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:26:51 +0100

A string which did not contain data format specifications should be put
into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3bdc639157c1..3740f9efcf06 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -934,8 +934,7 @@ static int xics_debug_show(struct seq_file *m, void *private)
 	t_reject = 0;
 
 	xics_debugfs_irqmap(m, kvm->arch.pimap);
-
-	seq_printf(m, "=========\nICP state\n=========\n");
+	seq_puts(m, "=========\nICP state\n=========\n");
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		struct kvmppc_icp *icp = vcpu->arch.icp;
-- 
2.11.0

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

* [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show()
@ 2017-01-20 18:26   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:26 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:26:51 +0100

A string which did not contain data format specifications should be put
into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3bdc639157c1..3740f9efcf06 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -934,8 +934,7 @@ static int xics_debug_show(struct seq_file *m, void *private)
 	t_reject = 0;
 
 	xics_debugfs_irqmap(m, kvm->arch.pimap);
-
-	seq_printf(m, "=====\nICP state\n=====\n");
+	seq_puts(m, "=====\nICP state\n=====\n");
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		struct kvmppc_icp *icp = vcpu->arch.icp;
-- 
2.11.0


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

* [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:27   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:27 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:28:43 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3740f9efcf06..d45c1b59b70a 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1032,7 +1032,7 @@ static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
 		goto out;
 
 	/* Create the ICS */
-	ics = kzalloc(sizeof(struct kvmppc_ics), GFP_KERNEL);
+	ics = kzalloc(*ics), GFP_KERNEL);
 	if (!ics)
 		goto out;
 
@@ -1064,7 +1064,7 @@ int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num)
 	if (kvmppc_xics_find_server(vcpu->kvm, server_num))
 		return -EEXIST;
 
-	icp = kzalloc(sizeof(struct kvmppc_icp), GFP_KERNEL);
+	icp = kzalloc(sizeof(*icp), GFP_KERNEL);
 	if (!icp)
 		return -ENOMEM;
 
-- 
2.11.0

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

* [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
@ 2017-01-20 18:27   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:27 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:28:43 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/book3s_xics.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 3740f9efcf06..d45c1b59b70a 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1032,7 +1032,7 @@ static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
 		goto out;
 
 	/* Create the ICS */
-	ics = kzalloc(sizeof(struct kvmppc_ics), GFP_KERNEL);
+	ics = kzalloc(*ics), GFP_KERNEL);
 	if (!ics)
 		goto out;
 
@@ -1064,7 +1064,7 @@ int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num)
 	if (kvmppc_xics_find_server(vcpu->kvm, server_num))
 		return -EEXIST;
 
-	icp = kzalloc(sizeof(struct kvmppc_icp), GFP_KERNEL);
+	icp = kzalloc(sizeof(*icp), GFP_KERNEL);
 	if (!icp)
 		return -ENOMEM;
 
-- 
2.11.0


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

* [PATCH 10/11] KVM: PPC: e500: Use kcalloc() in e500_mmu_host_init()
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:28   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:28 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:30:18 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/e500_mmu_host.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index b0333cc737dd..a1af2f445988 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -797,9 +797,8 @@ int e500_mmu_host_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	host_tlb_params[0].sets =
 		host_tlb_params[0].entries / host_tlb_params[0].ways;
 	host_tlb_params[1].sets = 1;
-
-	vcpu_e500->h2g_tlb1_rmap = kzalloc(sizeof(unsigned int) *
-					   host_tlb_params[1].entries,
+	vcpu_e500->h2g_tlb1_rmap = kcalloc(host_tlb_params[1].entries,
+					   sizeof(*vcpu_e500->h2g_tlb1_rmap),
 					   GFP_KERNEL);
 	if (!vcpu_e500->h2g_tlb1_rmap)
 		return -EINVAL;
-- 
2.11.0

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

* [PATCH 10/11] KVM: PPC: e500: Use kcalloc() in e500_mmu_host_init()
@ 2017-01-20 18:28   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:28 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 16:30:18 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/e500_mmu_host.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index b0333cc737dd..a1af2f445988 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -797,9 +797,8 @@ int e500_mmu_host_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	host_tlb_params[0].sets  		host_tlb_params[0].entries / host_tlb_params[0].ways;
 	host_tlb_params[1].sets = 1;
-
-	vcpu_e500->h2g_tlb1_rmap = kzalloc(sizeof(unsigned int) *
-					   host_tlb_params[1].entries,
+	vcpu_e500->h2g_tlb1_rmap = kcalloc(host_tlb_params[1].entries,
+					   sizeof(*vcpu_e500->h2g_tlb1_rmap),
 					   GFP_KERNEL);
 	if (!vcpu_e500->h2g_tlb1_rmap)
 		return -EINVAL;
-- 
2.11.0


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

* [PATCH 11/11] KVM: PPC: Return directly after a failed copy_from_user() in two functions
  2017-01-20 18:18 ` SF Markus Elfring
@ 2017-01-20 18:29   ` SF Markus Elfring
  -1 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:29 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 18:00:35 +0100

* Return directly after a call of the function "copy_from_user"
  (or two other checks) failed in a case block.

  This issue was detected by using the Coccinelle software.

* Delete the jump label "out" which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/powerpc.c | 48 ++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index efd1183a6b16..7083a680f5fb 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1256,19 +1256,19 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	switch (ioctl) {
 	case KVM_INTERRUPT: {
 		struct kvm_interrupt irq;
-		r = -EFAULT;
+
 		if (copy_from_user(&irq, argp, sizeof(irq)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
-		goto out;
+		break;
 	}
 
 	case KVM_ENABLE_CAP:
 	{
 		struct kvm_enable_cap cap;
-		r = -EFAULT;
+
 		if (copy_from_user(&cap, argp, sizeof(cap)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
 		break;
 	}
@@ -1277,9 +1277,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	case KVM_GET_ONE_REG:
 	{
 		struct kvm_one_reg reg;
-		r = -EFAULT;
+
 		if (copy_from_user(&reg, argp, sizeof(reg)))
-			goto out;
+			return -EFAULT;
 		if (ioctl == KVM_SET_ONE_REG)
 			r = kvm_vcpu_ioctl_set_one_reg(vcpu, &reg);
 		else
@@ -1290,9 +1290,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
 	case KVM_DIRTY_TLB: {
 		struct kvm_dirty_tlb dirty;
-		r = -EFAULT;
+
 		if (copy_from_user(&dirty, argp, sizeof(dirty)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_dirty_tlb(vcpu, &dirty);
 		break;
 	}
@@ -1300,8 +1300,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	default:
 		r = -EINVAL;
 	}
-
-out:
 	return r;
 }
 
@@ -1405,19 +1403,16 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		struct kvm_ppc_pvinfo pvinfo;
 		memset(&pvinfo, 0, sizeof(pvinfo));
 		r = kvm_vm_ioctl_get_pvinfo(&pvinfo);
-		if (copy_to_user(argp, &pvinfo, sizeof(pvinfo))) {
-			r = -EFAULT;
-			goto out;
-		}
-
+		if (copy_to_user(argp, &pvinfo, sizeof(pvinfo)))
+			return -EFAULT;
 		break;
 	}
 	case KVM_ENABLE_CAP:
 	{
 		struct kvm_enable_cap cap;
-		r = -EFAULT;
+
 		if (copy_from_user(&cap, argp, sizeof(cap)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vm_ioctl_enable_cap(kvm, &cap);
 		break;
 	}
@@ -1425,23 +1420,19 @@ long kvm_arch_vm_ioctl(struct file *filp,
 	case KVM_CREATE_SPAPR_TCE_64: {
 		struct kvm_create_spapr_tce_64 create_tce_64;
 
-		r = -EFAULT;
 		if (copy_from_user(&create_tce_64, argp, sizeof(create_tce_64)))
-			goto out;
-		if (create_tce_64.flags) {
-			r = -EINVAL;
-			goto out;
-		}
+			return -EFAULT;
+		if (create_tce_64.flags)
+			return -EINVAL;
 		r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
-		goto out;
+		break;
 	}
 	case KVM_CREATE_SPAPR_TCE: {
 		struct kvm_create_spapr_tce create_tce;
 		struct kvm_create_spapr_tce_64 create_tce_64;
 
-		r = -EFAULT;
 		if (copy_from_user(&create_tce, argp, sizeof(create_tce)))
-			goto out;
+			return -EFAULT;
 
 		create_tce_64.liobn = create_tce.liobn;
 		create_tce_64.page_shift = IOMMU_PAGE_SHIFT_4K;
@@ -1450,7 +1441,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
 				IOMMU_PAGE_SHIFT_4K;
 		create_tce_64.flags = 0;
 		r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
-		goto out;
+		break;
 	}
 	case KVM_PPC_GET_SMMU_INFO: {
 		struct kvm_ppc_smmu_info info;
@@ -1477,7 +1468,6 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = -ENOTTY;
 #endif
 	}
-out:
 	return r;
 }
 
-- 
2.11.0

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

* [PATCH 11/11] KVM: PPC: Return directly after a failed copy_from_user() in two functions
@ 2017-01-20 18:29   ` SF Markus Elfring
  0 siblings, 0 replies; 41+ messages in thread
From: SF Markus Elfring @ 2017-01-20 18:29 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Jan 2017 18:00:35 +0100

* Return directly after a call of the function "copy_from_user"
  (or two other checks) failed in a case block.

  This issue was detected by using the Coccinelle software.

* Delete the jump label "out" which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kvm/powerpc.c | 48 ++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index efd1183a6b16..7083a680f5fb 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1256,19 +1256,19 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	switch (ioctl) {
 	case KVM_INTERRUPT: {
 		struct kvm_interrupt irq;
-		r = -EFAULT;
+
 		if (copy_from_user(&irq, argp, sizeof(irq)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
-		goto out;
+		break;
 	}
 
 	case KVM_ENABLE_CAP:
 	{
 		struct kvm_enable_cap cap;
-		r = -EFAULT;
+
 		if (copy_from_user(&cap, argp, sizeof(cap)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
 		break;
 	}
@@ -1277,9 +1277,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	case KVM_GET_ONE_REG:
 	{
 		struct kvm_one_reg reg;
-		r = -EFAULT;
+
 		if (copy_from_user(&reg, argp, sizeof(reg)))
-			goto out;
+			return -EFAULT;
 		if (ioctl = KVM_SET_ONE_REG)
 			r = kvm_vcpu_ioctl_set_one_reg(vcpu, &reg);
 		else
@@ -1290,9 +1290,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
 	case KVM_DIRTY_TLB: {
 		struct kvm_dirty_tlb dirty;
-		r = -EFAULT;
+
 		if (copy_from_user(&dirty, argp, sizeof(dirty)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vcpu_ioctl_dirty_tlb(vcpu, &dirty);
 		break;
 	}
@@ -1300,8 +1300,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 	default:
 		r = -EINVAL;
 	}
-
-out:
 	return r;
 }
 
@@ -1405,19 +1403,16 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		struct kvm_ppc_pvinfo pvinfo;
 		memset(&pvinfo, 0, sizeof(pvinfo));
 		r = kvm_vm_ioctl_get_pvinfo(&pvinfo);
-		if (copy_to_user(argp, &pvinfo, sizeof(pvinfo))) {
-			r = -EFAULT;
-			goto out;
-		}
-
+		if (copy_to_user(argp, &pvinfo, sizeof(pvinfo)))
+			return -EFAULT;
 		break;
 	}
 	case KVM_ENABLE_CAP:
 	{
 		struct kvm_enable_cap cap;
-		r = -EFAULT;
+
 		if (copy_from_user(&cap, argp, sizeof(cap)))
-			goto out;
+			return -EFAULT;
 		r = kvm_vm_ioctl_enable_cap(kvm, &cap);
 		break;
 	}
@@ -1425,23 +1420,19 @@ long kvm_arch_vm_ioctl(struct file *filp,
 	case KVM_CREATE_SPAPR_TCE_64: {
 		struct kvm_create_spapr_tce_64 create_tce_64;
 
-		r = -EFAULT;
 		if (copy_from_user(&create_tce_64, argp, sizeof(create_tce_64)))
-			goto out;
-		if (create_tce_64.flags) {
-			r = -EINVAL;
-			goto out;
-		}
+			return -EFAULT;
+		if (create_tce_64.flags)
+			return -EINVAL;
 		r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
-		goto out;
+		break;
 	}
 	case KVM_CREATE_SPAPR_TCE: {
 		struct kvm_create_spapr_tce create_tce;
 		struct kvm_create_spapr_tce_64 create_tce_64;
 
-		r = -EFAULT;
 		if (copy_from_user(&create_tce, argp, sizeof(create_tce)))
-			goto out;
+			return -EFAULT;
 
 		create_tce_64.liobn = create_tce.liobn;
 		create_tce_64.page_shift = IOMMU_PAGE_SHIFT_4K;
@@ -1450,7 +1441,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
 				IOMMU_PAGE_SHIFT_4K;
 		create_tce_64.flags = 0;
 		r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
-		goto out;
+		break;
 	}
 	case KVM_PPC_GET_SMMU_INFO: {
 		struct kvm_ppc_smmu_info info;
@@ -1477,7 +1468,6 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = -ENOTTY;
 #endif
 	}
-out:
 	return r;
 }
 
-- 
2.11.0


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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
  2017-01-20 18:27   ` SF Markus Elfring
  (?)
@ 2017-01-21  6:24     ` kbuild test robot
  -1 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:24 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kbuild-all, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář,
	LKML, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2731 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
>> arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: statement with no effect [-Wunused-value]
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token

vim +/kzalloc +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51888 bytes --]

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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
@ 2017-01-21  6:24     ` kbuild test robot
  0 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:24 UTC (permalink / raw)
  To: kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2731 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
>> arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: statement with no effect [-Wunused-value]
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token

vim +/kzalloc +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51888 bytes --]

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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
@ 2017-01-21  6:24     ` kbuild test robot
  0 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:24 UTC (permalink / raw)
  To: kvm-ppc

[-- Attachment #1: Type: text/plain, Size: 2731 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
>> arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
   arch/powerpc/kvm/book3s_xics.c:1035:21: warning: statement with no effect [-Wunused-value]
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
>> arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token

vim +/kzalloc +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51888 bytes --]

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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
  2017-01-20 18:27   ` SF Markus Elfring
  (?)
@ 2017-01-21  6:37     ` kbuild test robot
  -1 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:37 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kbuild-all, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář,
	LKML, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
   arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: statement with no effect [-Werror=unused-value]
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token
   cc1: all warnings being treated as errors

vim +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 22632 bytes --]

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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
@ 2017-01-21  6:37     ` kbuild test robot
  0 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:37 UTC (permalink / raw)
  To: kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
   arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: statement with no effect [-Werror=unused-value]
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token
   cc1: all warnings being treated as errors

vim +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 22632 bytes --]

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

* Re: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
@ 2017-01-21  6:37     ` kbuild test robot
  0 siblings, 0 replies; 41+ messages in thread
From: kbuild test robot @ 2017-01-21  6:37 UTC (permalink / raw)
  To: kvm-ppc

[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]

Hi Markus,

[auto build test ERROR on next-20170119]
[also build test ERROR on v4.10-rc4]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/PowerPC-KVM-Fine-tuning-for-some-function-implementations/20170121-121537
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_xics.c: In function 'kvmppc_xics_create_ics':
   arch/powerpc/kvm/book3s_xics.c:1035:16: error: incompatible type for argument 1 of 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
                   ^
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: expected 'size_t {aka long unsigned int}' but argument is of type 'struct kvmppc_ics'
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
   arch/powerpc/kvm/book3s_xics.c:1035:8: error: too few arguments to function 'kzalloc'
     ics = kzalloc(*ics), GFP_KERNEL);
           ^~~~~~~
   In file included from include/linux/kvm_host.h:21:0,
                    from arch/powerpc/kvm/book3s_xics.c:11:
   include/linux/slab.h:634:21: note: declared here
    static inline void *kzalloc(size_t size, gfp_t flags)
                        ^~~~~~~
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
     ics = kzalloc(*ics), GFP_KERNEL);
                        ^
>> arch/powerpc/kvm/book3s_xics.c:1035:21: error: statement with no effect [-Werror=unused-value]
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected ';' before ')' token
     ics = kzalloc(*ics), GFP_KERNEL);
                                    ^
   arch/powerpc/kvm/book3s_xics.c:1035:33: error: expected statement before ')' token
   cc1: all warnings being treated as errors

vim +1035 arch/powerpc/kvm/book3s_xics.c

  1029	
  1030		/* ICS already exists - somebody else got here first */
  1031		if (xics->ics[icsid])
  1032			goto out;
  1033	
  1034		/* Create the ICS */
> 1035		ics = kzalloc(*ics), GFP_KERNEL);
  1036		if (!ics)
  1037			goto out;
  1038	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 22632 bytes --]

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

* Re: [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
  2017-01-20 18:19   ` SF Markus Elfring
@ 2017-01-23 14:12     ` Paolo Bonzini
  -1 siblings, 0 replies; 41+ messages in thread
From: Paolo Bonzini @ 2017-01-23 14:12 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman,
	Radim Krčmář
  Cc: LKML, kernel-janitors



On 20/01/2017 19:19, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Jan 2017 22:45:56 +0100
> 
> * A local variable was set to an error code in five cases
>   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.
> 
> * Delete two zero assignments which became unnecessary with
>   this refactoring.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

NACK, current code uses consistent style.

> ---
>  arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index b795dd1ac2ef..dc34729e4ad0 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  
>  	err = 0;
>  	for (nb = 0; nb + sizeof(hdr) <= count; ) {
> -		err = -EFAULT;
> -		if (__copy_from_user(&hdr, buf, sizeof(hdr)))
> +		if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
> +			err = -EFAULT;
>  			break;
> +		}
>  
> -		err = 0;
>  		if (nb + hdr.n_valid * HPTE_SIZE > count)
>  			break;
>  
>  		nb += sizeof(hdr);
>  		buf += sizeof(hdr);
>  
> -		err = -EINVAL;
>  		i = hdr.index;
>  		if (i >= kvm->arch.hpt_npte ||
> -		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
> +		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
> +			err = -EINVAL;
>  			break;
> +		}
>  
>  		hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
>  		lbuf = (unsigned long __user *)buf;
> @@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  			__be64 hpte_v;
>  			__be64 hpte_r;
>  
> -			err = -EFAULT;
>  			if (__get_user(hpte_v, lbuf) ||
> -			    __get_user(hpte_r, lbuf + 1))
> +			    __get_user(hpte_r, lbuf + 1)) {
> +				err = -EFAULT;
>  				goto out;
> +			}
>  			v = be64_to_cpu(hpte_v);
>  			r = be64_to_cpu(hpte_r);
> -			err = -EINVAL;
> -			if (!(v & HPTE_V_VALID))
> +			if (!(v & HPTE_V_VALID)) {
> +				err = -EINVAL;
>  				goto out;
> +			}
>  			lbuf += 2;
>  			nb += HPTE_SIZE;
>  
>  			if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
>  				kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
> -			err = -EIO;
>  			ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
>  							 tmp);
>  			if (ret != H_SUCCESS) {
>  				pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
>  				       "r=%lx\n", ret, i, v, r);
> +				err = -EIO;
>  				goto out;
>  			}
>  			if (!hpte_setup && is_vrma_hpte(v)) {
> @@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  			++i;
>  			hptp += 2;
>  		}
> -		err = 0;
>  	}
>  
>   out:
> 

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

* Re: [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
@ 2017-01-23 14:12     ` Paolo Bonzini
  0 siblings, 0 replies; 41+ messages in thread
From: Paolo Bonzini @ 2017-01-23 14:12 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman,
	Radim Krčmář
  Cc: LKML, kernel-janitors



On 20/01/2017 19:19, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Jan 2017 22:45:56 +0100
> 
> * A local variable was set to an error code in five cases
>   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.
> 
> * Delete two zero assignments which became unnecessary with
>   this refactoring.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

NACK, current code uses consistent style.

> ---
>  arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index b795dd1ac2ef..dc34729e4ad0 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  
>  	err = 0;
>  	for (nb = 0; nb + sizeof(hdr) <= count; ) {
> -		err = -EFAULT;
> -		if (__copy_from_user(&hdr, buf, sizeof(hdr)))
> +		if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
> +			err = -EFAULT;
>  			break;
> +		}
>  
> -		err = 0;
>  		if (nb + hdr.n_valid * HPTE_SIZE > count)
>  			break;
>  
>  		nb += sizeof(hdr);
>  		buf += sizeof(hdr);
>  
> -		err = -EINVAL;
>  		i = hdr.index;
>  		if (i >= kvm->arch.hpt_npte ||
> -		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
> +		    i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
> +			err = -EINVAL;
>  			break;
> +		}
>  
>  		hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
>  		lbuf = (unsigned long __user *)buf;
> @@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  			__be64 hpte_v;
>  			__be64 hpte_r;
>  
> -			err = -EFAULT;
>  			if (__get_user(hpte_v, lbuf) ||
> -			    __get_user(hpte_r, lbuf + 1))
> +			    __get_user(hpte_r, lbuf + 1)) {
> +				err = -EFAULT;
>  				goto out;
> +			}
>  			v = be64_to_cpu(hpte_v);
>  			r = be64_to_cpu(hpte_r);
> -			err = -EINVAL;
> -			if (!(v & HPTE_V_VALID))
> +			if (!(v & HPTE_V_VALID)) {
> +				err = -EINVAL;
>  				goto out;
> +			}
>  			lbuf += 2;
>  			nb += HPTE_SIZE;
>  
>  			if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
>  				kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
> -			err = -EIO;
>  			ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
>  							 tmp);
>  			if (ret != H_SUCCESS) {
>  				pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
>  				       "r=%lx\n", ret, i, v, r);
> +				err = -EIO;
>  				goto out;
>  			}
>  			if (!hpte_setup && is_vrma_hpte(v)) {
> @@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>  			++i;
>  			hptp += 2;
>  		}
> -		err = 0;
>  	}
>  
>   out:
> 

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

* Re: [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions
  2017-01-20 18:21   ` SF Markus Elfring
@ 2017-01-23 14:13     ` Paolo Bonzini
  -1 siblings, 0 replies; 41+ messages in thread
From: Paolo Bonzini @ 2017-01-23 14:13 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman,
	Radim Krčmář
  Cc: LKML, kernel-janitors



On 20/01/2017 19:21, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 20 Jan 2017 10:30:26 +0100
> 
> A local variable was set to an error code in a few cases 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.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)

NACK, current code uses consistent style.

Paolo

> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 8dcbe37a4dac..a93e1c4445da 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -2967,15 +2967,17 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
>  
>  	mutex_lock(&kvm->slots_lock);
>  
> -	r = -EINVAL;
> -	if (log->slot >= KVM_USER_MEM_SLOTS)
> +	if (log->slot >= KVM_USER_MEM_SLOTS) {
> +		r = -EINVAL;
>  		goto out;
> +	}
>  
>  	slots = kvm_memslots(kvm);
>  	memslot = id_to_memslot(slots, log->slot);
> -	r = -ENOENT;
> -	if (!memslot->dirty_bitmap)
> +	if (!memslot->dirty_bitmap) {
> +		r = -ENOENT;
>  		goto out;
> +	}
>  
>  	n = kvm_dirty_bitmap_bytes(memslot);
>  	memset(memslot->dirty_bitmap, 0, n);
> @@ -2984,9 +2986,10 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
>  	if (r)
>  		goto out;
>  
> -	r = -EFAULT;
> -	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
> +	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) {
> +		r = -EFAULT;
>  		goto out;
> +	}
>  
>  	r = 0;
>  out:
> @@ -3127,9 +3130,10 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
>  	memslot = gfn_to_memslot(kvm, 0);
>  
>  	/* We must have some memory at 0 by now */
> -	err = -EINVAL;
> -	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
> +	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
> +		err = -EINVAL;
>  		goto out_srcu;
> +	}
>  
>  	/* Look up the VMA for the start of this memory slot */
>  	hva = memslot->userspace_addr;
> @@ -3144,10 +3148,11 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
>  	up_read(&current->mm->mmap_sem);
>  
>  	/* We can handle 4k, 64k or 16M pages in the VRMA */
> -	err = -EINVAL;
>  	if (!(psize == 0x1000 || psize == 0x10000 ||
> -	      psize == 0x1000000))
> +	      psize == 0x1000000)) {
> +		err = -EINVAL;
>  		goto out_srcu;
> +	}
>  
>  	senc = slb_pgsize_encoding(psize);
>  	kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
> 

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

* Re: [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions
@ 2017-01-23 14:13     ` Paolo Bonzini
  0 siblings, 0 replies; 41+ messages in thread
From: Paolo Bonzini @ 2017-01-23 14:13 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman,
	Radim Krčmář
  Cc: LKML, kernel-janitors



On 20/01/2017 19:21, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 20 Jan 2017 10:30:26 +0100
> 
> A local variable was set to an error code in a few cases 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.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)

NACK, current code uses consistent style.

Paolo

> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 8dcbe37a4dac..a93e1c4445da 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -2967,15 +2967,17 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
>  
>  	mutex_lock(&kvm->slots_lock);
>  
> -	r = -EINVAL;
> -	if (log->slot >= KVM_USER_MEM_SLOTS)
> +	if (log->slot >= KVM_USER_MEM_SLOTS) {
> +		r = -EINVAL;
>  		goto out;
> +	}
>  
>  	slots = kvm_memslots(kvm);
>  	memslot = id_to_memslot(slots, log->slot);
> -	r = -ENOENT;
> -	if (!memslot->dirty_bitmap)
> +	if (!memslot->dirty_bitmap) {
> +		r = -ENOENT;
>  		goto out;
> +	}
>  
>  	n = kvm_dirty_bitmap_bytes(memslot);
>  	memset(memslot->dirty_bitmap, 0, n);
> @@ -2984,9 +2986,10 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
>  	if (r)
>  		goto out;
>  
> -	r = -EFAULT;
> -	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
> +	if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) {
> +		r = -EFAULT;
>  		goto out;
> +	}
>  
>  	r = 0;
>  out:
> @@ -3127,9 +3130,10 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
>  	memslot = gfn_to_memslot(kvm, 0);
>  
>  	/* We must have some memory at 0 by now */
> -	err = -EINVAL;
> -	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
> +	if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
> +		err = -EINVAL;
>  		goto out_srcu;
> +	}
>  
>  	/* Look up the VMA for the start of this memory slot */
>  	hva = memslot->userspace_addr;
> @@ -3144,10 +3148,11 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
>  	up_read(&current->mm->mmap_sem);
>  
>  	/* We can handle 4k, 64k or 16M pages in the VRMA */
> -	err = -EINVAL;
>  	if (!(psize = 0x1000 || psize = 0x10000 ||
> -	      psize = 0x1000000))
> +	      psize = 0x1000000)) {
> +		err = -EINVAL;
>  		goto out_srcu;
> +	}
>  
>  	senc = slb_pgsize_encoding(psize);
>  	kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
> 

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

* Re: [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
  2017-01-20 18:23   ` SF Markus Elfring
  (?)
@ 2017-01-23 19:22     ` Thomas Huth
  -1 siblings, 0 replies; 41+ messages in thread
From: Thomas Huth @ 2017-01-23 19:22 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

On 20.01.2017 19:23, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 20 Jan 2017 11:25:48 +0100
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> The script "checkpatch.pl" pointed information out like the following.
> 
> Comparison to NULL could be written …

That's maybe ok for new code / if the code has to be touched anyway ...
but for existing code, this sounds very much like unnecessary code-churn
to me (e.g. it hides more important information with "git blame").

 Thomas


> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index cfc7699d05df..3122998f6a32 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
>  
>  		/* convert logical addr to kernel addr and read length */
>  		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
> -		if (va == NULL)
> +		if (!va)
>  			return H_PARAMETER;
>  		if (subfunc == H_VPA_REG_VPA)
>  			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
> @@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
>  	struct kvmppc_vcore *vcore;
>  
>  	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
> -
> -	if (vcore == NULL)
> +	if (!vcore)
>  		return NULL;
>  
>  	spin_lock_init(&vcore->lock);
> @@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
>  		prepare_threads(pvc);
>  		if (!pvc->n_runnable) {
>  			list_del_init(&pvc->preempt_list);
> -			if (pvc->runner == NULL) {
> +			if (!pvc->runner) {
>  				pvc->vcore_state = VCORE_INACTIVE;
>  				kvmppc_core_end_stolen(pvc);
>  			}
> @@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
>  		} else {
>  			vc->vcore_state = VCORE_INACTIVE;
>  		}
> -		if (vc->n_runnable > 0 && vc->runner == NULL) {
> +		if (vc->n_runnable > 0 && !vc->runner) {
>  			/* make sure there's a candidate runner awake */
>  			i = -1;
>  			vcpu = next_runnable_thread(vc, &i);
> @@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  
>  	while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
>  	       !signal_pending(current)) {
> -		if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
> +		if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
>  			kvmppc_vcore_end_preempt(vc);
>  
>  		if (vc->vcore_state != VCORE_INACTIVE) {
> @@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  		vc->vcore_state == VCORE_PIGGYBACK))
>  		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
>  
> -	if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL)
> +	if (vc->vcore_state == VCORE_PREEMPT && !vc->runner)
>  		kvmppc_vcore_end_preempt(vc);
>  
>  	if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
> @@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
>  	int size;
>  
>  	/* Not the first time here ? */
> -	if (kvmppc_host_rm_ops_hv != NULL)
> +	if (kvmppc_host_rm_ops_hv)
>  		return;
>  
>  	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
> @@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
>  	mutex_lock(&kvm->lock);
>  
>  	pimap = kvm->arch.pimap;
> -	if (pimap == NULL) {
> +	if (!pimap) {
>  		/* First call, allocate structure to hold IRQ map */
>  		pimap = kvmppc_alloc_pimap();
> -		if (pimap == NULL) {
> +		if (!pimap) {
>  			mutex_unlock(&kvm->lock);
>  			return -ENOMEM;
>  		}
> 

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

* Re: [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
@ 2017-01-23 19:22     ` Thomas Huth
  0 siblings, 0 replies; 41+ messages in thread
From: Thomas Huth @ 2017-01-23 19:22 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

On 20.01.2017 19:23, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 20 Jan 2017 11:25:48 +0100
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> The script "checkpatch.pl" pointed information out like the following.
> 
> Comparison to NULL could be written …

That's maybe ok for new code / if the code has to be touched anyway ...
but for existing code, this sounds very much like unnecessary code-churn
to me (e.g. it hides more important information with "git blame").

 Thomas


> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index cfc7699d05df..3122998f6a32 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
>  
>  		/* convert logical addr to kernel addr and read length */
>  		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
> -		if (va = NULL)
> +		if (!va)
>  			return H_PARAMETER;
>  		if (subfunc = H_VPA_REG_VPA)
>  			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
> @@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
>  	struct kvmppc_vcore *vcore;
>  
>  	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
> -
> -	if (vcore = NULL)
> +	if (!vcore)
>  		return NULL;
>  
>  	spin_lock_init(&vcore->lock);
> @@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
>  		prepare_threads(pvc);
>  		if (!pvc->n_runnable) {
>  			list_del_init(&pvc->preempt_list);
> -			if (pvc->runner = NULL) {
> +			if (!pvc->runner) {
>  				pvc->vcore_state = VCORE_INACTIVE;
>  				kvmppc_core_end_stolen(pvc);
>  			}
> @@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
>  		} else {
>  			vc->vcore_state = VCORE_INACTIVE;
>  		}
> -		if (vc->n_runnable > 0 && vc->runner = NULL) {
> +		if (vc->n_runnable > 0 && !vc->runner) {
>  			/* make sure there's a candidate runner awake */
>  			i = -1;
>  			vcpu = next_runnable_thread(vc, &i);
> @@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  
>  	while (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE &&
>  	       !signal_pending(current)) {
> -		if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
> +		if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
>  			kvmppc_vcore_end_preempt(vc);
>  
>  		if (vc->vcore_state != VCORE_INACTIVE) {
> @@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  		vc->vcore_state = VCORE_PIGGYBACK))
>  		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
>  
> -	if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
> +	if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
>  		kvmppc_vcore_end_preempt(vc);
>  
>  	if (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE) {
> @@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
>  	int size;
>  
>  	/* Not the first time here ? */
> -	if (kvmppc_host_rm_ops_hv != NULL)
> +	if (kvmppc_host_rm_ops_hv)
>  		return;
>  
>  	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
> @@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
>  	mutex_lock(&kvm->lock);
>  
>  	pimap = kvm->arch.pimap;
> -	if (pimap = NULL) {
> +	if (!pimap) {
>  		/* First call, allocate structure to hold IRQ map */
>  		pimap = kvmppc_alloc_pimap();
> -		if (pimap = NULL) {
> +		if (!pimap) {
>  			mutex_unlock(&kvm->lock);
>  			return -ENOMEM;
>  		}
> 

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

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

* Re: [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
@ 2017-01-23 19:22     ` Thomas Huth
  0 siblings, 0 replies; 41+ messages in thread
From: Thomas Huth @ 2017-01-23 19:22 UTC (permalink / raw)
  To: SF Markus Elfring, kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář
  Cc: LKML, kernel-janitors

On 20.01.2017 19:23, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 20 Jan 2017 11:25:48 +0100
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> The script "checkpatch.pl" pointed information out like the following.
> 
> Comparison to NULL could be written …

That's maybe ok for new code / if the code has to be touched anyway ...
but for existing code, this sounds very much like unnecessary code-churn
to me (e.g. it hides more important information with "git blame").

 Thomas


> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/book3s_hv.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index cfc7699d05df..3122998f6a32 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -458,7 +458,7 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
>  
>  		/* convert logical addr to kernel addr and read length */
>  		va = kvmppc_pin_guest_page(kvm, vpa, &nb);
> -		if (va = NULL)
> +		if (!va)
>  			return H_PARAMETER;
>  		if (subfunc = H_VPA_REG_VPA)
>  			len = be16_to_cpu(((struct reg_vpa *)va)->length.hword);
> @@ -1591,8 +1591,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
>  	struct kvmppc_vcore *vcore;
>  
>  	vcore = kzalloc(sizeof(struct kvmppc_vcore), GFP_KERNEL);
> -
> -	if (vcore = NULL)
> +	if (!vcore)
>  		return NULL;
>  
>  	spin_lock_init(&vcore->lock);
> @@ -2221,7 +2220,7 @@ static void collect_piggybacks(struct core_info *cip, int target_threads)
>  		prepare_threads(pvc);
>  		if (!pvc->n_runnable) {
>  			list_del_init(&pvc->preempt_list);
> -			if (pvc->runner = NULL) {
> +			if (!pvc->runner) {
>  				pvc->vcore_state = VCORE_INACTIVE;
>  				kvmppc_core_end_stolen(pvc);
>  			}
> @@ -2287,7 +2286,7 @@ static void post_guest_process(struct kvmppc_vcore *vc, bool is_master)
>  		} else {
>  			vc->vcore_state = VCORE_INACTIVE;
>  		}
> -		if (vc->n_runnable > 0 && vc->runner = NULL) {
> +		if (vc->n_runnable > 0 && !vc->runner) {
>  			/* make sure there's a candidate runner awake */
>  			i = -1;
>  			vcpu = next_runnable_thread(vc, &i);
> @@ -2786,7 +2785,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  
>  	while (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE &&
>  	       !signal_pending(current)) {
> -		if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
> +		if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
>  			kvmppc_vcore_end_preempt(vc);
>  
>  		if (vc->vcore_state != VCORE_INACTIVE) {
> @@ -2833,7 +2832,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
>  		vc->vcore_state = VCORE_PIGGYBACK))
>  		kvmppc_wait_for_exec(vc, vcpu, TASK_UNINTERRUPTIBLE);
>  
> -	if (vc->vcore_state = VCORE_PREEMPT && vc->runner = NULL)
> +	if (vc->vcore_state = VCORE_PREEMPT && !vc->runner)
>  		kvmppc_vcore_end_preempt(vc);
>  
>  	if (vcpu->arch.state = KVMPPC_VCPU_RUNNABLE) {
> @@ -3203,7 +3202,7 @@ void kvmppc_alloc_host_rm_ops(void)
>  	int size;
>  
>  	/* Not the first time here ? */
> -	if (kvmppc_host_rm_ops_hv != NULL)
> +	if (kvmppc_host_rm_ops_hv)
>  		return;
>  
>  	ops = kzalloc(sizeof(struct kvmppc_host_rm_ops), GFP_KERNEL);
> @@ -3430,10 +3429,10 @@ static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi)
>  	mutex_lock(&kvm->lock);
>  
>  	pimap = kvm->arch.pimap;
> -	if (pimap = NULL) {
> +	if (!pimap) {
>  		/* First call, allocate structure to hold IRQ map */
>  		pimap = kvmppc_alloc_pimap();
> -		if (pimap = NULL) {
> +		if (!pimap) {
>  			mutex_unlock(&kvm->lock);
>  			return -ENOMEM;
>  		}
> 


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

end of thread, other threads:[~2017-01-23 19:22 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20 18:18 [PATCH 00/11] PowerPC-KVM: Fine-tuning for some function implementations SF Markus Elfring
2017-01-20 18:18 ` SF Markus Elfring
2017-01-20 18:19 ` [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write() SF Markus Elfring
2017-01-20 18:19   ` SF Markus Elfring
2017-01-23 14:12   ` Paolo Bonzini
2017-01-23 14:12     ` Paolo Bonzini
2017-01-20 18:20 ` [PATCH 02/11] KVM: PPC: Book3S HV: Improve a size determination in kvmppc_alloc_hpt() SF Markus Elfring
2017-01-20 18:20   ` SF Markus Elfring
2017-01-20 18:21 ` [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions SF Markus Elfring
2017-01-20 18:21   ` SF Markus Elfring
2017-01-23 14:13   ` Paolo Bonzini
2017-01-23 14:13     ` Paolo Bonzini
2017-01-20 18:22 ` [PATCH 04/11] KVM: PPC: Book3S HV: Use common error handling code in kvmppc_clr_passthru_irq() SF Markus Elfring
2017-01-20 18:22   ` SF Markus Elfring
2017-01-20 18:23 ` [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers SF Markus Elfring
2017-01-20 18:23   ` SF Markus Elfring
2017-01-20 18:23   ` SF Markus Elfring
2017-01-20 18:23   ` SF Markus Elfring
2017-01-23 19:22   ` Thomas Huth
2017-01-23 19:22     ` Thomas Huth
2017-01-23 19:22     ` Thomas Huth
2017-01-20 18:24 ` [PATCH 06/11] KVM: PPC: Book3S HV: Use kcalloc() in kvmppc_alloc_host_rm_ops() SF Markus Elfring
2017-01-20 18:24   ` SF Markus Elfring
2017-01-20 18:25 ` [PATCH 07/11] KVM: PPC: Book3S HV: Improve size determinations in five functions SF Markus Elfring
2017-01-20 18:25   ` SF Markus Elfring
2017-01-20 18:26 ` [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show() SF Markus Elfring
2017-01-20 18:26   ` SF Markus Elfring
2017-01-20 18:26   ` SF Markus Elfring
2017-01-20 18:26   ` SF Markus Elfring
2017-01-20 18:27 ` [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions SF Markus Elfring
2017-01-20 18:27   ` SF Markus Elfring
2017-01-21  6:24   ` kbuild test robot
2017-01-21  6:24     ` kbuild test robot
2017-01-21  6:24     ` kbuild test robot
2017-01-21  6:37   ` kbuild test robot
2017-01-21  6:37     ` kbuild test robot
2017-01-21  6:37     ` kbuild test robot
2017-01-20 18:28 ` [PATCH 10/11] KVM: PPC: e500: Use kcalloc() in e500_mmu_host_init() SF Markus Elfring
2017-01-20 18:28   ` SF Markus Elfring
2017-01-20 18:29 ` [PATCH 11/11] KVM: PPC: Return directly after a failed copy_from_user() in two functions SF Markus Elfring
2017-01-20 18:29   ` SF Markus Elfring

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.