From: SF Markus Elfring <hidden> Date: 2016-08-28 17:10:25
From: Markus Elfring <redacted>
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
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:13:19
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:14:53
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:16:34
From: Markus Elfring <redacted>
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 [off-list ref]
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:18:26
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:20:07
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-08-28 17:21:58
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Julia Lawall <hidden> Date: 2016-08-28 17:47:05
On Sun, 28 Aug 2016, SF Markus Elfring wrote:
quoted hunk
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
@@ -905,8 +905,6 @@ static int vcpu_mmu_init(struct kvm_vcpu *vcpu,intkvmppc_e500_tlb_init(structkvmppc_vcpu_e500*vcpu_e500){structkvm_vcpu*vcpu=&vcpu_e500->vcpu;-intentry_size=sizeof(structkvm_book3e_206_tlb_entry);-intentries=KVM_E500_TLB0_SIZE+KVM_E500_TLB1_SIZE;if(e500_mmu_host_init(vcpu_e500))gotoerr;
@@ -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
From: Julia Lawall <hidden> Date: 2016-08-28 17:48:31
On Sun, 28 Aug 2016, SF Markus Elfring wrote:
quoted hunk
From: Markus Elfring <redacted>
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 <redacted>
---
arch/powerpc/kvm/e500_mmu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)sizeof(structtlbe_ref),GFP_KERNEL);if(!vcpu_e500->gtlb_priv[0])-gotoerr;+gotofree_vcpu;vcpu_e500->gtlb_priv[1]=kcalloc(vcpu_e500->gtlb_params[1].entries,sizeof(structtlbe_ref),GFP_KERNEL);if(!vcpu_e500->gtlb_priv[1])-gotoerr;+gotofree_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)-gotoerr;+gotofree_vcpu;vcpu_mmu_init(vcpu,vcpu_e500->gtlb_params);kvmppc_recalc_tlb1map_range(vcpu_e500);return0;--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
From: Paul Mackerras <hidden> Date: 2016-09-11 23:29:01
On Sun, Aug 28, 2016 at 07:19:22PM +0200, SF Markus Elfring wrote:
From: Markus Elfring <redacted>
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 <redacted>
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.
From: Paul Mackerras <hidden> Date: 2016-09-12 00:58:52
On Sun, Aug 28, 2016 at 07:09:57PM +0200, SF Markus Elfring wrote:
From: Markus Elfring <redacted>
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.
From: SF Markus Elfring <hidden> Date: 2016-09-12 21:00:44
From: Markus Elfring <redacted>
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 <redacted>
---
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(-)