From: Peter Dinda Date: Wed, 1 Jul 2015 22:42:43 +0000 (-0500) Subject: Cleanup based on cppcheck pass (Core) X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=c0ecfba627c1d6c3f46d59bd4e5e6f883a494dc4 Cleanup based on cppcheck pass (Core) --- diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 0a281ab..eef2d3d 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -359,7 +359,7 @@ struct v3_vm_info * v3_create_vm(void * cfg, void * priv_data, char * name, unsi PrintDebug(vm, VCORE_NONE, "Creating virtual core %u on logical core %u\n", vcore_id, core->pcpu_id); - sprintf(core->exec_name, "%s-%u", vm->name, vcore_id); + sprintf(core->exec_name, "%s-%d", vm->name, vcore_id); PrintDebug(vm, VCORE_NONE, "run: core=%u, func=0x%p, arg=0x%p, name=%s\n", core->pcpu_id, start_core, core, core->exec_name); @@ -537,8 +537,12 @@ int v3_reset_vm_extended(struct v3_vm_info *vm, v3_vm_reset_type t, void *data) #endif break; case V3_VM_RESET_CORE_RANGE: - start = ((uint32_t*)data)[0]; - end = ((uint32_t*)data)[1]; + if (data) { + start = ((uint32_t*)data)[0]; + end = ((uint32_t*)data)[1]; + } else { + return -1; + } break; default: PrintError(vm,VCORE_NONE,"Unsupported reset type %d for this VM\n",t); diff --git a/palacios/src/palacios/vmm_checkpoint.c b/palacios/src/palacios/vmm_checkpoint.c index 82c505b..a67560e 100644 --- a/palacios/src/palacios/vmm_checkpoint.c +++ b/palacios/src/palacios/vmm_checkpoint.c @@ -260,7 +260,7 @@ int v3_chkpt_close_ctx(struct v3_chkpt_ctx * ctx) { int v3_chkpt_save(struct v3_chkpt_ctx * ctx, char * tag, uint64_t len, void * buf) { - struct v3_chkpt * chkpt = ctx->chkpt; + struct v3_chkpt * chkpt; int rc; if (!ctx) { @@ -268,6 +268,8 @@ int v3_chkpt_save(struct v3_chkpt_ctx * ctx, char * tag, uint64_t len, void * bu return -1; } + chkpt = ctx->chkpt; + if (chkpt->current_ctx != ctx) { PrintError(VM_NONE, VCORE_NONE, "Attempt to save on context that is not the current context for the store\n"); return -1; @@ -285,13 +287,15 @@ int v3_chkpt_save(struct v3_chkpt_ctx * ctx, char * tag, uint64_t len, void * bu int v3_chkpt_load(struct v3_chkpt_ctx * ctx, char * tag, uint64_t len, void * buf) { - struct v3_chkpt * chkpt = ctx->chkpt; + struct v3_chkpt * chkpt; int rc; if (!ctx) { PrintError(VM_NONE, VCORE_NONE, "Attempt to load tag %s from null context\n",tag); return -1; } + + chkpt = ctx->chkpt; if (chkpt->current_ctx != ctx) { PrintError(VM_NONE, VCORE_NONE, "Attempt to load from context that is not the current context for the store\n"); diff --git a/palacios/src/palacios/vmm_ctrl_regs.c b/palacios/src/palacios/vmm_ctrl_regs.c index 2a3ebbd..add91ff 100644 --- a/palacios/src/palacios/vmm_ctrl_regs.c +++ b/palacios/src/palacios/vmm_ctrl_regs.c @@ -49,6 +49,11 @@ int v3_handle_cr0_write(struct guest_info * info) { } else { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); @@ -229,7 +234,11 @@ int v3_handle_cr0_read(struct guest_info * info) { } else { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } - + + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); @@ -304,6 +313,11 @@ int v3_handle_cr3_write(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; @@ -381,6 +395,11 @@ int v3_handle_cr3_read(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; @@ -440,6 +459,11 @@ int v3_handle_cr4_read(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; @@ -496,6 +520,12 @@ int v3_handle_cr4_write(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; @@ -639,6 +669,11 @@ int v3_handle_cr8_write(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; @@ -681,6 +716,11 @@ int v3_handle_cr8_read(struct guest_info * info) { ret = v3_read_gva_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } + if (ret!=15) { + PrintError(info->vm_info, info, "Could not read instruction\n"); + return -1; + } + if (v3_decode(info, (addr_t)instr, &dec_instr) == -1) { PrintError(info->vm_info, info, "Could not decode instruction\n"); return -1; diff --git a/palacios/src/palacios/vmm_hashtable.c b/palacios/src/palacios/vmm_hashtable.c index fd8f3a2..8400416 100644 --- a/palacios/src/palacios/vmm_hashtable.c +++ b/palacios/src/palacios/vmm_hashtable.c @@ -222,6 +222,10 @@ struct hashtable * v3_create_htable(uint_t min_size, } } + if (prime_index==prime_table_length) { + return NULL; + } + htable = (struct hashtable *)V3_Malloc(sizeof(struct hashtable)); if (htable == NULL) { diff --git a/palacios/src/palacios/vmm_paging.c b/palacios/src/palacios/vmm_paging.c index 70d6730..c44f461 100644 --- a/palacios/src/palacios/vmm_paging.c +++ b/palacios/src/palacios/vmm_paging.c @@ -797,7 +797,7 @@ int v3_drill_host_pt_32(struct guest_info * info, v3_reg_t host_cr3, addr_t vadd } return 0; case PT_ENTRY_PAGE: - if ((ret = callback(info, PAGE_PT32, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT32, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT32; } @@ -834,7 +834,7 @@ int v3_drill_host_pt_32pae(struct guest_info * info, v3_reg_t host_cr3, addr_t v return -1; case PT_ENTRY_PAGE: - if ((ret = callback(info, PAGE_PD32PAE, vaddr, (addr_t)V3_VAddr((void *)host_pde_pa), host_pde_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PD32PAE, vaddr, (addr_t)V3_VAddr((void *)host_pde_pa), host_pde_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PD32PAE; } @@ -847,7 +847,7 @@ int v3_drill_host_pt_32pae(struct guest_info * info, v3_reg_t host_cr3, addr_t v } return 0; case PT_ENTRY_PAGE: - if ((ret = callback(info, PAGE_PT32PAE, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT32PAE, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT32PAE; } @@ -904,7 +904,7 @@ int v3_drill_host_pt_64(struct guest_info * info, v3_reg_t host_cr3, addr_t vadd return 0; case PT_ENTRY_PAGE: - if ((ret = callback(info, PAGE_PD64, vaddr, (addr_t)V3_VAddr((void *)host_pde_pa), host_pde_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PD64, vaddr, (addr_t)V3_VAddr((void *)host_pde_pa), host_pde_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PD64; } @@ -918,7 +918,7 @@ int v3_drill_host_pt_64(struct guest_info * info, v3_reg_t host_cr3, addr_t vadd return 0; case PT_ENTRY_PAGE: - if ((ret = callback(info, PAGE_PT64, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT64, vaddr, (addr_t)V3_VAddr((void *)host_pte_pa), host_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT64; } @@ -993,7 +993,7 @@ int v3_drill_guest_pt_32(struct guest_info * info, v3_reg_t guest_cr3, addr_t va return -1; } - if ((ret = callback(info, PAGE_PT32, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT32, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT32; } @@ -1087,7 +1087,7 @@ int v3_drill_guest_pt_32pae(struct guest_info * info, v3_reg_t guest_cr3, addr_t return -1; } - if ((ret = callback(info, PAGE_PT32PAE, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT32PAE, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT32PAE; } @@ -1215,7 +1215,7 @@ int v3_drill_guest_pt_64(struct guest_info * info, v3_reg_t guest_cr3, addr_t va return -1; } - if ((ret = callback(info, PAGE_PT64, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data) != 0)) { + if ((ret = callback(info, PAGE_PT64, vaddr, (addr_t)guest_pte, guest_pte_pa, private_data)) != 0) { return (ret == -1) ? -1 : PAGE_PT64; } diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index f7cbb9e..a88b978 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -388,7 +388,7 @@ handle_time_configuration(struct v3_vm_info * vm, v3_cfg_tree_t *cfg) { int v3_init_time_vm(struct v3_vm_info * vm) { v3_cfg_tree_t * cfg_tree = vm->cfg_data->cfg; - int ret; + int ret=0; PrintDebug(vm, VCORE_NONE, "Installing TSC MSR hook.\n"); ret = v3_hook_msr(vm, TSC_MSR, @@ -409,10 +409,19 @@ int v3_init_time_vm(struct v3_vm_info * vm) { PrintDebug(vm, VCORE_NONE, "Registering TIME_CPUFREQ hypercall.\n"); ret = v3_register_hypercall(vm, TIME_CPUFREQ_HCALL, handle_cpufreq_hcall, NULL); + + if (ret!=0) { + return ret; + } + PrintDebug(vm, VCORE_NONE, "Registering TIME_RDHTSC hypercall.\n"); ret = v3_register_hypercall(vm, TIME_RDHTSC_HCALL, handle_rdhtsc_hcall, NULL); + if (ret!=0) { + return ret; + } + handle_time_configuration(vm, v3_cfg_subtree(cfg_tree, "time")); return ret; diff --git a/palacios/src/palacios/vmm_xml.c b/palacios/src/palacios/vmm_xml.c index a797e63..755ed59 100644 --- a/palacios/src/palacios/vmm_xml.c +++ b/palacios/src/palacios/vmm_xml.c @@ -1111,7 +1111,7 @@ static char *toxml_r(struct v3_xml * xml, char **s, size_t *len, size_t *max, *len += sprintf(*s + *len, "", xml->name); // close tag - while (txt[off] && off < xml->off) off++; // make sure off is within bounds + while (off < xml->off && txt[off]) off++; // make sure off is within bounds return (xml->ordered) ? toxml_r(xml->ordered, s, len, max, off) : ampencode(txt + off, -1, s, len, max, 0); } diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index 3a23032..544b848 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -546,7 +546,10 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) vmx_ret |= check_vmcs_write(VMCS_LINK_PTR_HIGH, (addr_t)0xffffffffUL); #endif - + if (vmx_ret != VMX_SUCCESS) { + PrintError(core->vm_info, core, "Error configuring VMX\n"); + return -1; + } @@ -621,6 +624,11 @@ static void __init_vmx_vmcs(void * arg) { PrintDebug(core->vm_info, core, "Serializing VMCS: %p\n", (void *)vmx_state->vmcs_ptr_phys); vmx_ret = vmcs_clear(vmx_state->vmcs_ptr_phys); + if (vmx_ret != VMX_SUCCESS) { + PrintError(core->vm_info,core,"VMCS Clear failed\n"); + return; + } + core->core_run_state = CORE_STOPPED; return; } diff --git a/palacios/src/palacios/vmx_hw_info.c b/palacios/src/palacios/vmx_hw_info.c index cbd34da..da00093 100644 --- a/palacios/src/palacios/vmx_hw_info.c +++ b/palacios/src/palacios/vmx_hw_info.c @@ -112,8 +112,8 @@ int v3_init_vmx_hw(struct vmx_hw_info * hw_info) { /* Get secondary PROCBASED controls if secondary controls are available (optional or required) */ /* Intel Manual 3B. Sect. G.3.3 */ - if ( ((hw_info->proc_ctrls.req_mask & 0x80000000) == 0) || - ((hw_info->proc_ctrls.req_val & 0x80000000) == 1) ) { + if ( (!(hw_info->proc_ctrls.req_mask & 0x80000000)) || + (hw_info->proc_ctrls.req_val & 0x80000000) ) { get_ctrl_caps(&(hw_info->sec_proc_ctrls), VMX_PROCBASED_CTLS2_MSR);