public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations
       [not found] <566ABCD9.1060404@users.sourceforge.net>
@ 2016-08-28 17:09 ` SF Markus Elfring
  2016-08-28 17:12   ` [PATCH 1/6] KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
                     ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:09 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 19:01:02 +0200

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

Markus Elfring (6):
  Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()
  Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection
  Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb()
  Replace kzalloc() calls by kcalloc() in two functions
  Use kmalloc_array() in kvmppc_e500_tlb_init()
  Rename jump labels in kvmppc_e500_tlb_init()

 arch/powerpc/kvm/e500_mmu.c | 71 +++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 35 deletions(-)

-- 
2.9.3

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

* [PATCH 1/6] KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
@ 2016-08-28 17:12   ` SF Markus Elfring
  2016-08-28 17:14   ` [PATCH 2/6] KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection SF Markus Elfring
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:12 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 16:30:07 +0200

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

  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.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 29911a0..26f3737 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -779,7 +779,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	num_pages = DIV_ROUND_UP(cfg->array + array_len - 1, PAGE_SIZE) -
 		    cfg->array / PAGE_SIZE;
-	pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
+	pages = kmalloc_array(num_pages, sizeof(*pages), GFP_KERNEL);
 	if (!pages)
 		return -ENOMEM;
 
-- 
2.9.3


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

* [PATCH 2/6] KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
  2016-08-28 17:12   ` [PATCH 1/6] KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
@ 2016-08-28 17:14   ` SF Markus Elfring
  2016-08-28 17:15   ` [PATCH 3/6] KVM: PPC: e500: Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:14 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 17:34:46 +0200

The kfree() function was called in two cases by the
kvm_vcpu_ioctl_config_tlb() function during error handling
even if the passed data structure element contained a null pointer.

* Split a condition check for memory allocation failures.

* Adjust jump targets according to the Linux coding style convention.

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

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 26f3737..b65a894 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -785,35 +785,39 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	ret = get_user_pages_fast(cfg->array, num_pages, 1, pages);
 	if (ret < 0)
-		goto err_pages;
+		goto free_pages;
 
 	if (ret != num_pages) {
 		num_pages = ret;
 		ret = -EFAULT;
-		goto err_put_page;
+		goto put_pages;
 	}
 
 	virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL);
 	if (!virt) {
 		ret = -ENOMEM;
-		goto err_put_page;
+		goto put_pages;
 	}
 
 	privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
 			   GFP_KERNEL);
+	if (!privs[0]) {
+		ret = -ENOMEM;
+		goto put_pages;
+	}
+
 	privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
 			   GFP_KERNEL);
-
-	if (!privs[0] || !privs[1]) {
+	if (!privs[1]) {
 		ret = -ENOMEM;
-		goto err_privs;
+		goto free_privs_first;
 	}
 
 	g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
 	                     GFP_KERNEL);
 	if (!g2h_bitmap) {
 		ret = -ENOMEM;
-		goto err_privs;
+		goto free_privs_second;
 	}
 
 	free_gtlb(vcpu_e500);
@@ -845,16 +849,14 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err_privs:
-	kfree(privs[0]);
+ free_privs_second:
 	kfree(privs[1]);
-
-err_put_page:
+ free_privs_first:
+	kfree(privs[0]);
+ put_pages:
 	for (i = 0; i < num_pages; i++)
 		put_page(pages[i]);
-
-err_pages:
+ free_pages:
 	kfree(pages);
 	return ret;
 }
-- 
2.9.3

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

* [PATCH 3/6] KVM: PPC: e500: Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb()
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
  2016-08-28 17:12   ` [PATCH 1/6] KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
  2016-08-28 17:14   ` [PATCH 2/6] KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection SF Markus Elfring
@ 2016-08-28 17:15   ` SF Markus Elfring
  2016-08-28 17:16   ` [PATCH 4/6] KVM: PPC: e500: Replace kzalloc() calls by kcalloc() in two functions SF Markus Elfring
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:15 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 17:37:10 +0200

The local variable "g2h_bitmap" will be set to an appropriate value
a bit later. Thus omit the explicit initialisation at the beginning.

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

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index b65a894..e9c19e9 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -743,7 +743,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 	char *virt;
 	struct page **pages;
 	struct tlbe_priv *privs[2] = {};
-	u64 *g2h_bitmap = NULL;
+	u64 *g2h_bitmap;
 	size_t array_len;
 	u32 sets;
 	int num_pages, ret, i;
-- 
2.9.3

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

* [PATCH 4/6] KVM: PPC: e500: Replace kzalloc() calls by kcalloc() in two functions
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
                     ` (2 preceding siblings ...)
  2016-08-28 17:15   ` [PATCH 3/6] KVM: PPC: e500: Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
@ 2016-08-28 17:16   ` SF Markus Elfring
  2016-08-28 17:18   ` [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init() SF Markus Elfring
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:16 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 18:30:38 +0200

* 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".

  Suggested-by: Paolo Bonzini <pbonzini@redhat.com>

  This issue was detected also by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
  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.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index e9c19e9..2be2afc4 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -799,22 +799,21 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 		goto put_pages;
 	}
 
-	privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
-			   GFP_KERNEL);
+	privs[0] = kcalloc(params.tlb_sizes[0], sizeof(*privs[0]), GFP_KERNEL);
 	if (!privs[0]) {
 		ret = -ENOMEM;
 		goto put_pages;
 	}
 
-	privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
-			   GFP_KERNEL);
+	privs[1] = kcalloc(params.tlb_sizes[1], sizeof(*privs[1]), GFP_KERNEL);
 	if (!privs[1]) {
 		ret = -ENOMEM;
 		goto free_privs_first;
 	}
 
-	g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
-	                     GFP_KERNEL);
+	g2h_bitmap = kcalloc(params.tlb_sizes[1],
+			     sizeof(*g2h_bitmap),
+			     GFP_KERNEL);
 	if (!g2h_bitmap) {
 		ret = -ENOMEM;
 		goto free_privs_second;
@@ -929,20 +928,20 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_offset[0] = 0;
 	vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
 
-	vcpu_e500->gtlb_priv[0] = kzalloc(sizeof(struct tlbe_ref) *
-					  vcpu_e500->gtlb_params[0].entries,
+	vcpu_e500->gtlb_priv[0] = kcalloc(vcpu_e500->gtlb_params[0].entries,
+					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
 		goto err;
 
-	vcpu_e500->gtlb_priv[1] = kzalloc(sizeof(struct tlbe_ref) *
-					  vcpu_e500->gtlb_params[1].entries,
+	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
+					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
 		goto err;
 
-	vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(u64) *
-					  vcpu_e500->gtlb_params[1].entries,
+	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
+					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
 		goto err;
-- 
2.9.3

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

* [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init()
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
                     ` (3 preceding siblings ...)
  2016-08-28 17:16   ` [PATCH 4/6] KVM: PPC: e500: Replace kzalloc() calls by kcalloc() in two functions SF Markus Elfring
@ 2016-08-28 17:18   ` SF Markus Elfring
  2016-08-28 17:46     ` Julia Lawall
  2016-08-28 17:19   ` [PATCH 6/6] KVM: PPC: e500: Rename jump labels " SF Markus Elfring
  2016-09-12  0:54   ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations Paul Mackerras
  6 siblings, 1 reply; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:18 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 18:40:08 +0200

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

* 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/e500_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 2be2afc4..0a2eeb1 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -905,8 +905,6 @@ static int vcpu_mmu_init(struct kvm_vcpu *vcpu,
 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
 	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
-	int entry_size = sizeof(struct kvm_book3e_206_tlb_entry);
-	int entries = KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE;
 
 	if (e500_mmu_host_init(vcpu_e500))
 		goto err;
@@ -921,7 +919,10 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_params[1].ways = KVM_E500_TLB1_SIZE;
 	vcpu_e500->gtlb_params[1].sets = 1;
 
-	vcpu_e500->gtlb_arch = kmalloc(entries * entry_size, GFP_KERNEL);
+	vcpu_e500->gtlb_arch = kmalloc_array(KVM_E500_TLB0_SIZE +
+					     KVM_E500_TLB1_SIZE,
+					     sizeof(*vcpu_e500->gtlb_arch),
+					     GFP_KERNEL);
 	if (!vcpu_e500->gtlb_arch)
 		return -ENOMEM;
 
-- 
2.9.3

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

* [PATCH 6/6] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
                     ` (4 preceding siblings ...)
  2016-08-28 17:18   ` [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init() SF Markus Elfring
@ 2016-08-28 17:19   ` SF Markus Elfring
  2016-08-28 17:48     ` Julia Lawall
  2016-09-11 23:25     ` Paul Mackerras
  2016-09-12  0:54   ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations Paul Mackerras
  6 siblings, 2 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-08-28 17:19 UTC (permalink / raw)
  To: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Aug 2016 18:45:26 +0200

Adjust jump labels according to the current Linux coding style convention.

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

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 0a2eeb1..da8f22b 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
-		goto err;
+		goto free_vcpu;
 
 	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err:
+ free_vcpu:
 	free_gtlb(vcpu_e500);
 	return -1;
 }
-- 
2.9.3

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

* Re: [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init()
  2016-08-28 17:18   ` [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init() SF Markus Elfring
@ 2016-08-28 17:46     ` Julia Lawall
  0 siblings, 0 replies; 12+ messages in thread
From: Julia Lawall @ 2016-08-28 17:46 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář, LKML,
	kernel-janitors



On Sun, 28 Aug 2016, SF Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Aug 2016 18:40:08 +0200
>
> * A multiplication for the size determination of a memory allocation
>   indicated that an array data structure should be processed.
>   Thus use the corresponding function "kmalloc_array".
>
> * 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/e500_mmu.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
> index 2be2afc4..0a2eeb1 100644
> --- a/arch/powerpc/kvm/e500_mmu.c
> +++ b/arch/powerpc/kvm/e500_mmu.c
> @@ -905,8 +905,6 @@ static int vcpu_mmu_init(struct kvm_vcpu *vcpu,
>  int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
>  {
>  	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
> -	int entry_size = sizeof(struct kvm_book3e_206_tlb_entry);
> -	int entries = KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE;
>
>  	if (e500_mmu_host_init(vcpu_e500))
>  		goto err;
> @@ -921,7 +919,10 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
>  	vcpu_e500->gtlb_params[1].ways = KVM_E500_TLB1_SIZE;
>  	vcpu_e500->gtlb_params[1].sets = 1;
>
> -	vcpu_e500->gtlb_arch = kmalloc(entries * entry_size, GFP_KERNEL);
> +	vcpu_e500->gtlb_arch = kmalloc_array(KVM_E500_TLB0_SIZE +
> +					     KVM_E500_TLB1_SIZE,
> +					     sizeof(*vcpu_e500->gtlb_arch),
> +					     GFP_KERNEL);

There are changes here that are not mentioned in the commit log.

julia

>  	if (!vcpu_e500->gtlb_arch)
>  		return -ENOMEM;
>
> --
> 2.9.3
>
> --
> 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] 12+ messages in thread

* Re: [PATCH 6/6] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()
  2016-08-28 17:19   ` [PATCH 6/6] KVM: PPC: e500: Rename jump labels " SF Markus Elfring
@ 2016-08-28 17:48     ` Julia Lawall
  2016-09-11 23:25     ` Paul Mackerras
  1 sibling, 0 replies; 12+ messages in thread
From: Julia Lawall @ 2016-08-28 17:48 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Paul Mackerras, Radim Krčmář, LKML,
	kernel-janitors



On Sun, 28 Aug 2016, SF Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Aug 2016 18:45:26 +0200
>
> Adjust jump labels according to the current Linux coding style convention.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kvm/e500_mmu.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
> index 0a2eeb1..da8f22b 100644
> --- a/arch/powerpc/kvm/e500_mmu.c
> +++ b/arch/powerpc/kvm/e500_mmu.c
> @@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
>  					  sizeof(struct tlbe_ref),
>  					  GFP_KERNEL);
>  	if (!vcpu_e500->gtlb_priv[0])
> -		goto err;
> +		goto free_vcpu;
>
>  	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
>  					  sizeof(struct tlbe_ref),
>  					  GFP_KERNEL);
>  	if (!vcpu_e500->gtlb_priv[1])
> -		goto err;
> +		goto free_vcpu;
>
>  	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
>  					  sizeof(*vcpu_e500->g2h_tlb1_map),
>  					  GFP_KERNEL);
>  	if (!vcpu_e500->g2h_tlb1_map)
> -		goto err;
> +		goto free_vcpu;
>
>  	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
>
>  	kvmppc_recalc_tlb1map_range(vcpu_e500);
>  	return 0;
> -
> -err:
> + free_vcpu:
>  	free_gtlb(vcpu_e500);
>  	return -1;

I doubt that -1 is the best return value.  One could guess that it should
be -ENOMEM.  But see what the call sites expect.

julia

>  }
> --
> 2.9.3
>
> --
> 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] 12+ messages in thread

* Re: [PATCH 6/6] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()
  2016-08-28 17:19   ` [PATCH 6/6] KVM: PPC: e500: Rename jump labels " SF Markus Elfring
  2016-08-28 17:48     ` Julia Lawall
@ 2016-09-11 23:25     ` Paul Mackerras
  2016-09-12 21:00       ` [PATCH] " SF Markus Elfring
  1 sibling, 1 reply; 12+ messages in thread
From: Paul Mackerras @ 2016-09-11 23:25 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář, LKML, kernel-janitors, Julia Lawall

On Sun, Aug 28, 2016 at 07:19:22PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Aug 2016 18:45:26 +0200
> 
> Adjust jump labels according to the current Linux coding style convention.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

With this I get a compile error:

  CC      arch/powerpc/kvm/e500_mmu.o
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c: In function ‘kvmppc_e500_tlb_init’:
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c:910:3: error: label ‘err’ used but not defined
   goto err;
   ^
/home/paulus/kernel/kvm/scripts/Makefile.build:289: recipe for target 'arch/powerpc/kvm/e500_mmu.o' failed
make[2]: *** [arch/powerpc/kvm/e500_mmu.o] Error 1

Paul.

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

* Re: [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
                     ` (5 preceding siblings ...)
  2016-08-28 17:19   ` [PATCH 6/6] KVM: PPC: e500: Rename jump labels " SF Markus Elfring
@ 2016-09-12  0:54   ` Paul Mackerras
  6 siblings, 0 replies; 12+ messages in thread
From: Paul Mackerras @ 2016-09-12  0:54 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kvm, kvm-ppc, linuxppc-dev, Alexander Graf,
	Benjamin Herrenschmidt, Michael Ellerman, Paolo Bonzini,
	Radim Krčmář, LKML, kernel-janitors, Julia Lawall

On Sun, Aug 28, 2016 at 07:09:57PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Aug 2016 19:01:02 +0200
> 
> Several update suggestions were taken into account
> from static source code analysis.
> 
> Markus Elfring (6):
>   Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()
>   Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection
>   Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb()
>   Replace kzalloc() calls by kcalloc() in two functions
>   Use kmalloc_array() in kvmppc_e500_tlb_init()
>   Rename jump labels in kvmppc_e500_tlb_init()

Thanks, patches 1-5 applied to my kvm-ppc-next branch.

Paul.

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

* [PATCH] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()
  2016-09-11 23:25     ` Paul Mackerras
@ 2016-09-12 21:00       ` SF Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2016-09-12 21:00 UTC (permalink / raw)
  To: Paul Mackerras, kvm, kvm-ppc, linuxppc-dev
  Cc: Alexander Graf, Benjamin Herrenschmidt, Michael Ellerman,
	Paolo Bonzini, Radim Krčmář, LKML, kernel-janitors,
	Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 12 Sep 2016 22:33:53 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

Thanks that five update steps could be integrated into the branch "kvm-ppc-next"
of another source code repository.


> With this I get a compile error:
> 
>   CC      arch/powerpc/kvm/e500_mmu.o
> /home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c: In function ‘kvmppc_e500_tlb_init’:
> /home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c:910:3: error: label ‘err’ used but not defined
>    goto err;
>    ^
> /home/paulus/kernel/kvm/scripts/Makefile.build:289: recipe for target 'arch/powerpc/kvm/e500_mmu.o' failed
> make[2]: *** [arch/powerpc/kvm/e500_mmu.o] Error 1

I overlooked a single goto statement there somehow.

I hope that you like my second approach for this function implementation better.


 arch/powerpc/kvm/e500_mmu.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 0a2eeb1..ddbf8f0 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -907,7 +907,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
 
 	if (e500_mmu_host_init(vcpu_e500))
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_params[0].entries = KVM_E500_TLB0_SIZE;
 	vcpu_e500->gtlb_params[1].entries = KVM_E500_TLB1_SIZE;
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
-		goto err;
+		goto free_vcpu;
 
 	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err:
+ free_vcpu:
 	free_gtlb(vcpu_e500);
 	return -1;
 }
-- 
2.10.0



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

end of thread, other threads:[~2016-09-12 21:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
2016-08-28 17:12   ` [PATCH 1/6] KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
2016-08-28 17:14   ` [PATCH 2/6] KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection SF Markus Elfring
2016-08-28 17:15   ` [PATCH 3/6] KVM: PPC: e500: Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb() SF Markus Elfring
2016-08-28 17:16   ` [PATCH 4/6] KVM: PPC: e500: Replace kzalloc() calls by kcalloc() in two functions SF Markus Elfring
2016-08-28 17:18   ` [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init() SF Markus Elfring
2016-08-28 17:46     ` Julia Lawall
2016-08-28 17:19   ` [PATCH 6/6] KVM: PPC: e500: Rename jump labels " SF Markus Elfring
2016-08-28 17:48     ` Julia Lawall
2016-09-11 23:25     ` Paul Mackerras
2016-09-12 21:00       ` [PATCH] " SF Markus Elfring
2016-09-12  0:54   ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations Paul Mackerras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox