linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
       [not found] <566ABCD9.1060404@users.sourceforge.net>
@ 2015-12-14 22:10 ` SF Markus Elfring
  2015-12-14 22:20   ` Scott Wood
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: SF Markus Elfring @ 2015-12-14 22:10 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Michael Ellerman, Paul Mackerras, linuxppc-dev
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 14 Dec 2015 23:01:32 +0100

A status check was performed by the fsl_get_immr() function even if it
was known already that a system setting did not fit to the expectations.

This implementation detail could be improved by an adjustment for
a jump label according to the Linux coding style convention.

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

diff --git a/arch/powerpc/boot/fsl-soc.c b/arch/powerpc/boot/fsl-soc.c
index b835ed6..ff1dae3 100644
--- a/arch/powerpc/boot/fsl-soc.c
+++ b/arch/powerpc/boot/fsl-soc.c
@@ -34,24 +34,24 @@ u32 *fsl_get_immr(void)
 			naddr = 2;
 
 		if (naddr != 1 && naddr != 2)
-			goto err;
+			goto report_failure;
 
 		size = getprop(soc, "ranges", prop_buf, MAX_PROP_LEN);
 
 		if (size < 12)
-			goto err;
+			goto report_failure;
 		if (prop_buf[0] != 0)
-			goto err;
+			goto report_failure;
 		if (naddr == 2 && prop_buf[1] != 0)
-			goto err;
+			goto report_failure;
 
 		if (!dt_xlate_addr(soc, prop_buf + naddr, 8, &ret))
 			ret = 0;
 	}
 
-err:
-	if (!ret)
+	if (!ret) {
+report_failure:
 		printf("fsl_get_immr: Failed to find immr base\r\n");
-
+	}
 	return (u32 *)ret;
 }
-- 
2.6.3

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

* Re: [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection
  2015-12-14 22:10 ` [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection SF Markus Elfring
@ 2015-12-14 22:20   ` Scott Wood
  0 siblings, 0 replies; 21+ messages in thread
From: Scott Wood @ 2015-12-14 22:20 UTC (permalink / raw)
  To: SF Markus Elfring, Benjamin Herrenschmidt, Michael Ellerman,
	Paul Mackerras, linuxppc-dev
  Cc: LKML, kernel-janitors, Julia Lawall

On Mon, 2015-12-14 at 23:10 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 14 Dec 2015 23:01:32 +0100
> 
> A status check was performed by the fsl_get_immr() function even if it
> was known already that a system setting did not fit to the expectations.
> 
> This implementation detail could be improved by an adjustment for
> a jump label according to the Linux coding style convention.

What is the actual problem you're trying to solve?  Cluttering the code to
micro-optimize an error path is not an improvement.

-Scott

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

* [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations
       [not found] <566ABCD9.1060404@users.sourceforge.net>
  2015-12-14 22:10 ` [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection SF Markus Elfring
@ 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)
  2016-08-29 11:00 ` [PATCH 0/5] PowerPC: Fine-tuning for three " SF Markus Elfring
  2016-08-29 11:00 ` SF Markus Elfring
  3 siblings, 7 replies; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ messages in thread

* [PATCH 0/5] PowerPC: Fine-tuning for three function implementations
       [not found] <566ABCD9.1060404@users.sourceforge.net>
  2015-12-14 22:10 ` [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection SF Markus Elfring
  2016-08-28 17:09 ` [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations SF Markus Elfring
@ 2016-08-29 11:00 ` SF Markus Elfring
  2016-08-29 11:00 ` SF Markus Elfring
  3 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:00 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:44:22 +0200

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

Markus Elfring (5):
  Use kmalloc_array() in mpic_init()
  Use kmalloc_array() in ppc4xx_setup_msi_irqs()
  Use kmalloc_array() in hsta_msi_probe()
  Rename jump labels in hsta_msi_probe()
  Move three assignments in hsta_msi_probe()

 arch/powerpc/sysdev/mpic.c            |  5 +++--
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 26 +++++++++++++-------------
 arch/powerpc/sysdev/ppc4xx_msi.c      |  4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)

-- 
2.9.3

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

* [PATCH 0/5] PowerPC: Fine-tuning for three function implementations
       [not found] <566ABCD9.1060404@users.sourceforge.net>
                   ` (2 preceding siblings ...)
  2016-08-29 11:00 ` [PATCH 0/5] PowerPC: Fine-tuning for three " SF Markus Elfring
@ 2016-08-29 11:00 ` SF Markus Elfring
  2016-08-29 11:07   ` [PATCH 1/5] powerpc-mpic: Use kmalloc_array() in mpic_init() SF Markus Elfring
                     ` (4 more replies)
  3 siblings, 5 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:00 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:44:22 +0200

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

Markus Elfring (5):
  Use kmalloc_array() in mpic_init()
  Use kmalloc_array() in ppc4xx_setup_msi_irqs()
  Use kmalloc_array() in hsta_msi_probe()
  Rename jump labels in hsta_msi_probe()
  Move three assignments in hsta_msi_probe()

 arch/powerpc/sysdev/mpic.c            |  5 +++--
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 26 +++++++++++++-------------
 arch/powerpc/sysdev/ppc4xx_msi.c      |  4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)

-- 
2.9.3

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

* [PATCH 1/5] powerpc-mpic: Use kmalloc_array() in mpic_init()
  2016-08-29 11:00 ` SF Markus Elfring
@ 2016-08-29 11:07   ` SF Markus Elfring
  2016-08-29 11:09   ` [PATCH 2/5] powerpc-MSI: Use kmalloc_array() in ppc4xx_setup_msi_irqs() SF Markus Elfring
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:07 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:00:11 +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.

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

diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 7de45b2..5e79c0d24 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1641,8 +1641,9 @@ void __init mpic_init(struct mpic *mpic)
 
 #ifdef CONFIG_PM
 	/* allocate memory to save mpic state */
-	mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
-				  GFP_KERNEL);
+	mpic->save_data = kmalloc_array(mpic->num_sources,
+					sizeof(*mpic->save_data),
+					GFP_KERNEL);
 	BUG_ON(mpic->save_data == NULL);
 #endif
 
-- 
2.9.3

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

* [PATCH 2/5] powerpc-MSI: Use kmalloc_array() in ppc4xx_setup_msi_irqs()
  2016-08-29 11:00 ` SF Markus Elfring
  2016-08-29 11:07   ` [PATCH 1/5] powerpc-mpic: Use kmalloc_array() in mpic_init() SF Markus Elfring
@ 2016-08-29 11:09   ` SF Markus Elfring
  2016-08-29 11:10   ` [PATCH 3/5] powerpc-MSI-HSTA: Use kmalloc_array() in hsta_msi_probe() SF Markus Elfring
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:09 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:11:24 +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/sysdev/ppc4xx_msi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/sysdev/ppc4xx_msi.c b/arch/powerpc/sysdev/ppc4xx_msi.c
index 8fb8061..0bd5e4b 100644
--- a/arch/powerpc/sysdev/ppc4xx_msi.c
+++ b/arch/powerpc/sysdev/ppc4xx_msi.c
@@ -89,7 +89,9 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
 	if (type == PCI_CAP_ID_MSIX)
 		pr_debug("ppc4xx msi: MSI-X untested, trying anyway.\n");
 
-	msi_data->msi_virqs = kmalloc((msi_irqs) * sizeof(int), GFP_KERNEL);
+	msi_data->msi_virqs = kmalloc_array(msi_irqs,
+					    sizeof(*msi_data->msi_virqs),
+					    GFP_KERNEL);
 	if (!msi_data->msi_virqs)
 		return -ENOMEM;
 
-- 
2.9.3

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

* [PATCH 3/5] powerpc-MSI-HSTA: Use kmalloc_array() in hsta_msi_probe()
  2016-08-29 11:00 ` SF Markus Elfring
  2016-08-29 11:07   ` [PATCH 1/5] powerpc-mpic: Use kmalloc_array() in mpic_init() SF Markus Elfring
  2016-08-29 11:09   ` [PATCH 2/5] powerpc-MSI: Use kmalloc_array() in ppc4xx_setup_msi_irqs() SF Markus Elfring
@ 2016-08-29 11:10   ` SF Markus Elfring
  2016-08-29 11:12   ` [PATCH 4/5] powerpc-MSI-HSTA: Rename jump labels " SF Markus Elfring
  2016-08-29 11:13   ` [PATCH 5/5] powerpc-MSI-HSTA: Move three assignments " SF Markus Elfring
  4 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:10 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:20:39 +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/sysdev/ppc4xx_hsta_msi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
index 52a93dc..691db9a 100644
--- a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
+++ b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
@@ -156,7 +156,9 @@ static int hsta_msi_probe(struct platform_device *pdev)
 	if (ret)
 		goto out;
 
-	ppc4xx_hsta_msi.irq_map = kmalloc(sizeof(int) * irq_count, GFP_KERNEL);
+	ppc4xx_hsta_msi.irq_map = kmalloc_array(irq_count,
+						sizeof(*ppc4xx_hsta_msi.irq_map),
+						GFP_KERNEL);
 	if (!ppc4xx_hsta_msi.irq_map) {
 		ret = -ENOMEM;
 		goto out1;
-- 
2.9.3

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

* [PATCH 4/5] powerpc-MSI-HSTA: Rename jump labels in hsta_msi_probe()
  2016-08-29 11:00 ` SF Markus Elfring
                     ` (2 preceding siblings ...)
  2016-08-29 11:10   ` [PATCH 3/5] powerpc-MSI-HSTA: Use kmalloc_array() in hsta_msi_probe() SF Markus Elfring
@ 2016-08-29 11:12   ` SF Markus Elfring
  2016-08-29 11:13   ` [PATCH 5/5] powerpc-MSI-HSTA: Move three assignments " SF Markus Elfring
  4 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:12 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:22:19 +0200

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

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
index 691db9a..3097ddd 100644
--- a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
+++ b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
@@ -154,14 +154,14 @@ static int hsta_msi_probe(struct platform_device *pdev)
 
 	ret = msi_bitmap_alloc(&ppc4xx_hsta_msi.bmp, irq_count, dev->of_node);
 	if (ret)
-		goto out;
+		goto unmap_io;
 
 	ppc4xx_hsta_msi.irq_map = kmalloc_array(irq_count,
 						sizeof(*ppc4xx_hsta_msi.irq_map),
 						GFP_KERNEL);
 	if (!ppc4xx_hsta_msi.irq_map) {
 		ret = -ENOMEM;
-		goto out1;
+		goto free_bitmap;
 	}
 
 	/* Setup a mapping from irq offsets to hardware irq numbers */
@@ -171,7 +171,7 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		if (ppc4xx_hsta_msi.irq_map[irq] == NO_IRQ) {
 			dev_err(dev, "Unable to map IRQ\n");
 			ret = -EINVAL;
-			goto out2;
+			goto free_irq_map;
 		}
 	}
 
@@ -180,14 +180,11 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		phb->controller_ops.teardown_msi_irqs = hsta_teardown_msi_irqs;
 	}
 	return 0;
-
-out2:
+ free_irq_map:
 	kfree(ppc4xx_hsta_msi.irq_map);
-
-out1:
+ free_bitmap:
 	msi_bitmap_free(&ppc4xx_hsta_msi.bmp);
-
-out:
+ unmap_io:
 	iounmap(ppc4xx_hsta_msi.data);
 	return ret;
 }
-- 
2.9.3

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

* [PATCH 5/5] powerpc-MSI-HSTA: Move three assignments in hsta_msi_probe()
  2016-08-29 11:00 ` SF Markus Elfring
                     ` (3 preceding siblings ...)
  2016-08-29 11:12   ` [PATCH 4/5] powerpc-MSI-HSTA: Rename jump labels " SF Markus Elfring
@ 2016-08-29 11:13   ` SF Markus Elfring
  4 siblings, 0 replies; 21+ messages in thread
From: SF Markus Elfring @ 2016-08-29 11:13 UTC (permalink / raw)
  To: linuxppc-dev, Adam Buchbinder, Andrew Donnellan,
	Benjamin Herrenschmidt, Marc Zyngier, Michael Ellerman,
	Paul Mackerras, Scott Wood, Sudeep Holla, Thomas Gleixner
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Aug 2016 11:30:48 +0200

Move the assignments for three data structure members to the end
so that they will only be performed if the desired resource allocations
succeeded by this function.

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

diff --git a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
index 3097ddd..57014ce 100644
--- a/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
+++ b/arch/powerpc/sysdev/ppc4xx_hsta_msi.c
@@ -143,10 +143,7 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ppc4xx_hsta_msi.dev = dev;
-	ppc4xx_hsta_msi.address = mem->start;
 	ppc4xx_hsta_msi.data = ioremap(mem->start, resource_size(mem));
-	ppc4xx_hsta_msi.irq_count = irq_count;
 	if (!ppc4xx_hsta_msi.data) {
 		dev_err(dev, "Unable to map memory\n");
 		return -ENOMEM;
@@ -179,6 +176,10 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		phb->controller_ops.setup_msi_irqs = hsta_setup_msi_irqs;
 		phb->controller_ops.teardown_msi_irqs = hsta_teardown_msi_irqs;
 	}
+
+	ppc4xx_hsta_msi.dev = dev;
+	ppc4xx_hsta_msi.address = mem->start;
+	ppc4xx_hsta_msi.irq_count = irq_count;
 	return 0;
  free_irq_map:
 	kfree(ppc4xx_hsta_msi.irq_map);
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ messages in thread

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

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-14 22:10 ` [POWERPC] bootwrapper: One check less in fsl_get_immr() after error detection SF Markus Elfring
2015-12-14 22:20   ` Scott Wood
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
2016-08-29 11:00 ` [PATCH 0/5] PowerPC: Fine-tuning for three " SF Markus Elfring
2016-08-29 11:00 ` SF Markus Elfring
2016-08-29 11:07   ` [PATCH 1/5] powerpc-mpic: Use kmalloc_array() in mpic_init() SF Markus Elfring
2016-08-29 11:09   ` [PATCH 2/5] powerpc-MSI: Use kmalloc_array() in ppc4xx_setup_msi_irqs() SF Markus Elfring
2016-08-29 11:10   ` [PATCH 3/5] powerpc-MSI-HSTA: Use kmalloc_array() in hsta_msi_probe() SF Markus Elfring
2016-08-29 11:12   ` [PATCH 4/5] powerpc-MSI-HSTA: Rename jump labels " SF Markus Elfring
2016-08-29 11:13   ` [PATCH 5/5] powerpc-MSI-HSTA: Move three assignments " SF Markus Elfring

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