From: Peter Dinda Date: Wed, 1 Jul 2015 22:33:41 +0000 (-0500) Subject: Cleanup based on cppcheck pass (Linux module and user) X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=471edd59ca70371e97cbad759e1710433f35990d;p=palacios.git Cleanup based on cppcheck pass (Linux module and user) --- diff --git a/linux_module/buddy.c b/linux_module/buddy.c index f21c95d..9cc89f1 100644 --- a/linux_module/buddy.c +++ b/linux_module/buddy.c @@ -613,7 +613,7 @@ void buddy_deinit(struct buddy_memzone * zone, int (*free_callback)(void *user_m char proc_file_name[128]; memset(proc_file_name, 0, 128); - snprintf(proc_file_name, 128, "v3-mem%d", zone->node_id); + snprintf(proc_file_name, 128, "v3-mem%u", zone->node_id); remove_proc_entry(proc_file_name, palacios_get_procdir()); } diff --git a/linux_module/iface-pmu.c b/linux_module/iface-pmu.c index 990fb29..948e5f1 100644 --- a/linux_module/iface-pmu.c +++ b/linux_module/iface-pmu.c @@ -124,7 +124,6 @@ static int amd_get_slot(void) { } return slot; - return -1; } /* diff --git a/linux_module/palacios-vnet-brg.c b/linux_module/palacios-vnet-brg.c index 829c069..945909a 100644 --- a/linux_module/palacios-vnet-brg.c +++ b/linux_module/palacios-vnet-brg.c @@ -173,7 +173,7 @@ static uint32_t _create_link(struct vnet_link * link) { link->sock_addr.sin_port = htons(link->dst_port); - if ((err = link->sock->ops->connect(link->sock, (struct sockaddr *)&(link->sock_addr), sizeof(struct sockaddr), 0) < 0)) { + if ((err = link->sock->ops->connect(link->sock, (struct sockaddr *)&(link->sock_addr), sizeof(struct sockaddr), 0)) < 0) { WARNING("Could not connect to remote VNET Server, error %d\n", err); return -1; } diff --git a/linux_module/palacios-vnet.c b/linux_module/palacios-vnet.c index 014d191..d4f09b0 100644 --- a/linux_module/palacios-vnet.c +++ b/linux_module/palacios-vnet.c @@ -116,7 +116,7 @@ host_start_timer(void * vnet_timer){ static void host_reset_timer(void * vnet_timer, unsigned long interval){ - struct host_timer * timer = (struct host_timer *)timer; + struct host_timer * timer = (struct host_timer *)vnet_timer; timer->interval = interval; } diff --git a/linux_module/util-hashtable.c b/linux_module/util-hashtable.c index beb7bbe..9ee832b 100644 --- a/linux_module/util-hashtable.c +++ b/linux_module/util-hashtable.c @@ -203,6 +203,11 @@ struct hashtable * palacios_create_htable(uint_t min_size, } } + if (prime_index==prime_table_len) { + // cannot build large enough hash table + return NULL; + } + htable = (struct hashtable *)palacios_alloc(sizeof(struct hashtable)); if (htable == NULL) { diff --git a/linux_usr/v3_devfile_shadow.c b/linux_usr/v3_devfile_shadow.c index dc4cddc..629dbef 100644 --- a/linux_usr/v3_devfile_shadow.c +++ b/linux_usr/v3_devfile_shadow.c @@ -191,7 +191,6 @@ int main(int argc, char** argv) uint64_t sys_rc, sys_errno, sys_code, a1,a2,a3,a4,a5,a6, bit_vec; int host_mod_fd, fd_shared, i, val; long long zero = 0; - void* region; void* unbacked_region; fd_set readset; int select_rc; @@ -236,8 +235,8 @@ int main(int argc, char** argv) sprintf(unbacked_region,"helloworldhelloworldhelloworld"); DEBUG_PRINT("unbacked_region ptr: %p contents: %s\n",unbacked_region,(char*)unbacked_region); - DEBUG_PRINT("Vadrr : %p ; Paddr : %p\n", unbacked_region, vtop((uint64_t)unbacked_region)); - DEBUG_PRINT("Persisting as a userspace for VM %s with address %p\n",argv[1], region); + DEBUG_PRINT("Vaddr : %p ; Paddr : %p\n", unbacked_region, vtop((uint64_t)unbacked_region)); + DEBUG_PRINT("Persisting as a userspace for VM %s with address %p\n",argv[1], unbacked_region); if (ioctl(host_mod_fd,INIT_IOCTL,vtop((uint64_t)unbacked_region))) { perror("init ioctl"); @@ -279,7 +278,7 @@ int main(int argc, char** argv) perror("Failed Syscall: "); } - DEBUG_PRINT("Device File: System call rc %d, %016llu %016llx %016lld\n",(int)sys_rc,sys_rc); + DEBUG_PRINT("Device File: System call rc %d, errno %d\n",(int)sys_rc,sys_errno); //put return value into shared region store_args_to_shared_page((uint64_t*)unbacked_region, &sys_rc, &sys_errno); diff --git a/linux_usr/v3_guest_mem.c b/linux_usr/v3_guest_mem.c index f1fe9de..b0798a6 100644 --- a/linux_usr/v3_guest_mem.c +++ b/linux_usr/v3_guest_mem.c @@ -67,6 +67,7 @@ struct v3_guest_mem_map * v3_guest_mem_get_map(char *vmdev) // Now collect the region info guest_cur=0; + i=0; while (iblock[i].hpa = (void*)start; m->block[i].numpages = (end-start) / 4096 + !!((end-start) % 4096); if ((end-start)%4096) { - fprintf(stderr,"Odd, region %d is a non-integral number of pages"); + fprintf(stderr,"Odd, region %d is a non-integral number of pages",i); } guest_cur+=end-start; m->block[i].cumgpa=(void*)(guest_cur-1); diff --git a/linux_usr/v3_mem.c b/linux_usr/v3_mem.c index 93a511f..b30b344 100644 --- a/linux_usr/v3_mem.c +++ b/linux_usr/v3_mem.c @@ -655,7 +655,7 @@ static int offline_memory(unsigned long long mem_size_bytes, return -1; } - status_buf[BUF_SIZE]=0; + status_buf[BUF_SIZE-1]=0; VPRINTF("Checking offlined block %d (%s)...", i + reg_start, fname); @@ -814,7 +814,7 @@ static int write_offlined() fclose(off); if (!(off=fopen(offname,"w+"))) { // truncate - EPRINTF("Cannot open %s for writing!\n"); + EPRINTF("Cannot open %s for writing!\n",offname); return -1; } diff --git a/linux_usr/v3_reset.c b/linux_usr/v3_reset.c index 7335b78..944e658 100644 --- a/linux_usr/v3_reset.c +++ b/linux_usr/v3_reset.c @@ -52,6 +52,9 @@ int main(int argc, char* argv[]) { cmd.first_core = atoi(argv[3]); cmd.num_cores = atoi(argv[4]); } + } else { + usage(); + return -1; } printf("Doing VM reset: %s ", diff --git a/linux_usr/v3_user_host_dev_example.c b/linux_usr/v3_user_host_dev_example.c index ea6cdc7..043811b 100644 --- a/linux_usr/v3_user_host_dev_example.c +++ b/linux_usr/v3_user_host_dev_example.c @@ -17,7 +17,7 @@ void usage() int do_work(struct palacios_host_dev_host_request_response *req, struct palacios_host_dev_host_request_response **resp) { - uint64_t datasize; + uint64_t datasize=0; // // diff --git a/linux_usr/v3_user_keyed_stream_example.c b/linux_usr/v3_user_keyed_stream_example.c index 6068b0c..9a2b0f3 100644 --- a/linux_usr/v3_user_keyed_stream_example.c +++ b/linux_usr/v3_user_keyed_stream_example.c @@ -19,7 +19,7 @@ void usage() int do_work(struct palacios_user_keyed_stream_op *req, struct palacios_user_keyed_stream_op **resp) { - uint64_t datasize; + uint64_t datasize=0; // // @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) // if (strncmp(url,"user:",5)) { - fprintf(stderr, "URL %s is not a user: url\n"); + fprintf(stderr, "URL %s is not a user: url\n",url); exit(-1); }