From: Peter Dinda Date: Fri, 3 Jun 2016 21:43:03 +0000 (-0500) Subject: Cleanup and fixes based on Coverity pass X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=210c49c1f9b523ff94fd5b6791961d242d5bbae4 Cleanup and fixes based on Coverity pass --- diff --git a/nautilus/palacios-stubs.c b/nautilus/palacios-stubs.c index a1b8183..45d8e7b 100644 --- a/nautilus/palacios-stubs.c +++ b/nautilus/palacios-stubs.c @@ -198,14 +198,17 @@ void *palacios_allocate_pages(int num_pages, unsigned int alignment, int node_id * a single call while palacios_free_page() only frees a single page. */ -void palacios_free_pages(void * page_paddr, int num_pages) { +void palacios_free_pages(void * page_paddr, int num_pages) +{ + //INFO("freepages: %p (%llu pages) alignment=%u\n", page_paddr, num_pages); + if (!page_paddr) { ERROR("Ignoring free pages: 0x%p (0x%lx)for %d pages\n", page_paddr, (uintptr_t)page_paddr, num_pages); return; } + free(page_paddr); - INFO("freepages: %p (%llu pages) alignment=%u\n", page_paddr, num_pages); } @@ -244,6 +247,7 @@ palacios_valloc(unsigned int size) { void * addr = NULL; + if (size==0) { ERROR("ALERT ALERT attempt to vmalloc zero bytes rejected\n"); return NULL; @@ -268,14 +272,15 @@ palacios_valloc(unsigned int size) void palacios_vfree(void *p) { + //INFO("vfree: 0x%p\n",p); + if (!p) { ERROR("Ignoring vfree: 0x%p\n",p); return; } - // no vfree currently + free(p); - //INFO("vfree: 0x%p\n",p); } /** @@ -294,14 +299,14 @@ palacios_alloc(unsigned int size) void palacios_free(void *addr) { - return; + //INFO("free: %p\n",addr-ALLOC_PAD); + if (!addr) { ERROR("Ignoring free : 0x%p\n", addr); return; } - // no kfree + free(addr-ALLOC_PAD); - //INFO("free: %p\n",addr-ALLOC_PAD); } /** @@ -312,8 +317,11 @@ palacios_vaddr_to_paddr( void * vaddr ) { - return vaddr; // our memory mapping is identity - + // our memory mapping is identity + // this currently does not include Nautilus PA offsetting + // as in Multiverse, but we don't envision running a VM + // within an HRT either, so we should be fine + return vaddr; } /** @@ -324,7 +332,7 @@ palacios_paddr_to_vaddr( void * paddr ) { - return paddr; // our memory mapping is identity + return paddr; // our memory mapping is identity, see v->p comment } /** @@ -756,6 +764,9 @@ int palacios_vmm_init(char * options) *(cpu_mask + major) |= (0x1 << minor); } + } else { + ERROR("Must initialize at least one CPU\n"); + return -1; } @@ -788,6 +799,8 @@ int palacios_vmm_init(char * options) nautilus_console_init(); #endif + palacios_free(cpu_mask); + return 0; @@ -817,6 +830,7 @@ void palacios_inform_new_vm_pre(char *name) for (i=0;ipcpu_id = core_idx; - vcore_id--; + core->pcpu_id = core_idx; + vcore_id--; } - if (vcore_id >= 0) { // dead code... - v3_stop_vm(vm); - return -1; - } + // if (vcore_id >= 0) { // dead code... + //v3_stop_vm(vm); + //return -1; + //} return 0; } diff --git a/palacios/src/palacios/vmm_xml.c b/palacios/src/palacios/vmm_xml.c index f3cf7e3..a9c6659 100644 --- a/palacios/src/palacios/vmm_xml.c +++ b/palacios/src/palacios/vmm_xml.c @@ -480,8 +480,12 @@ static struct v3_xml * parse_str(char * buf, size_t len) { char ** attr; int attr_idx; - if (!buf) { - return NULL; + if (buf==NULL) { + return NULL; + } + + if (root==NULL) { + return NULL; } root->str_ptr = buf; @@ -692,7 +696,8 @@ static struct v3_xml * parse_str(char * buf, size_t len) { return NULL; } - if (! buf || ! *buf) { + // at this point, buf cannot be NULL + if (!*buf) { break; }