PowerPC-KVM: Fine-tuning for some function implementations
Subsystems (4)
cover PowerPC-KVM: Fine-tuning for some function implementations
From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.11.0
PATCH 1/11 KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
From: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +13 -11
@@ -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:
Signature · 1 line
2.11.0
PATCH 2/11 KVM: PPC: Book3S HV: Improve a size determination in kvmppc_alloc_hpt()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -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;
Signature · 1 line
2.11.0
PATCH 3/11 KVM: PPC: Book3S HV: Move error code assignments in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
arch/powerpc/kvm/book3s_hv.c +15 -10
@@ -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 (¤t->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 |
Signature · 1 line
2.11.0
PATCH 4/11 KVM: PPC: Book3S HV: Use common error handling code in kvmppc_clr_passthru_irq()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_hv.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_hv.c +3 -5
@@ -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 ; }
Signature · 1 line
2.11.0
PATCH 5/11 KVM: PPC: Book3S HV: Adjust nine checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_hv.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
arch/powerpc/kvm/book3s_hv.c +9 -10
@@ -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 ; }
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 6/11 KVM: PPC: Book3S HV: Use kcalloc() in kvmppc_alloc_host_rm_ops()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_hv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_hv.c +3 -4
@@ -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 ;
Signature · 1 line
2.11.0
PATCH 7/11 KVM: PPC: Book3S HV: Improve size determinations in five functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_hv.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/kvm/book3s_hv.c +7 -6
@@ -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;
Signature · 1 line
2.11.0
PATCH 8/11 KVM: PPC: Book3S: Use seq_puts() in xics_debug_show()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_xics.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kvm/book3s_xics.c +1 -2
@@ -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;
Signature · 1 line
2.11.0
PATCH 9/11 KVM: PPC: Book3S: Improve a size determination in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/book3s_xics.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_xics.c +2 -2
@@ -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 ;
Signature · 1 line
2.11.0
PATCH 10/11 KVM: PPC: e500: Use kcalloc() in e500_mmu_host_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/e500_mmu_host.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/kvm/e500_mmu_host.c +2 -3
@@ -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 ;
Signature · 1 line
2.11.0
PATCH 11/11 KVM: PPC: Return directly after a failed copy_from_user() in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- arch/powerpc/kvm/powerpc.c | 48 ++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
arch/powerpc/kvm/powerpc.c +19 -29
@@ -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 (®, argp,sizeof (reg))) - goto out; +return -EFAULT ;if (ioctl =KVM_SET_ONE_REG ) r =kvm_vcpu_ioctl_set_one_reg (vcpu, ®);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; }
Signature · 1 line
2.11.0
kbuild test robot
build botRe: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
In reply to SF Markus Elfringurl: 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…
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 ')' tokenvim +/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
kbuild test robot
build botRe: [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions
In reply to SF Markus Elfringurl: 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…
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
Re: [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
In reply to SF Markus ElfringQuoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
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.
Quoted 6 lines
This issue was detected by using the Coccinelle software.
* Delete two zero assignments which became unnecessary with this refactoring.
Signed-off-by Markus Elfring <[email protected]>
NACK, current code uses consistent style.
Quoted 80 lines
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)arch/powerpc/kvm/book3s_64_mmu_hv.c +13
-11@@ -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:
Re: [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions
In reply to SF Markus ElfringQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 20 Jan 2017 10:30:26 +0100A 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.
Quoted 6 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
NACK, current code uses consistent style.
Paolo
Quoted 67 lines
arch/powerpc/kvm/book3s_hv.c +15
-10@@ -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 (¤t->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 |
Re: [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 20 Jan 2017 11:25:48 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThe 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
Quoted 78 lines
Signed-off-by Markus Elfring <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)arch/powerpc/kvm/book3s_hv.c +7
-8@@ -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);
arch/powerpc/kvm/book3s_hv.c static int kvmppc_set_passthru_irq(struct kvm *kvm, int host_irq, int guest_gsi) · line 3438
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +2
-2pimap = 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html