X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fswapbypass_cache2.c;h=776c34ae72c60430ad710853b39ef8b71c16ebc7;hb=e61e0890e6f13b1362cfffdcd287e90f1d41e443;hp=dfd51ba2d6fa0f58dba114dfe42632e3aa477012;hpb=94f67717b6461df514dc225ed84f03b44c44061b;p=palacios.git diff --git a/palacios/src/devices/swapbypass_cache2.c b/palacios/src/devices/swapbypass_cache2.c index dfd51ba..776c34a 100644 --- a/palacios/src/devices/swapbypass_cache2.c +++ b/palacios/src/devices/swapbypass_cache2.c @@ -540,6 +540,11 @@ static int connect_fn(struct v3_vm_info * vm, swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state)); + if (!swap) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + swap->vm = vm; swap->cache_size = cache_size; swap->io_flag = 0; @@ -561,6 +566,12 @@ static int connect_fn(struct v3_vm_info * vm, INIT_LIST_HEAD(&(swap->entry_list)); INIT_LIST_HEAD(&(swap->free_list)); swap->entry_map = (struct cache_entry *)V3_Malloc(sizeof(struct cache_entry) * (cache_size / 4096)); + + if (!swap->entry_map) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + for (i = 0; i < (cache_size / 4096); i++) { list_add(&(swap->entry_map[i].cache_node), &(swap->free_list)); @@ -571,6 +582,14 @@ static int connect_fn(struct v3_vm_info * vm, swap->active = 0; swap->cache_base_addr = (addr_t)V3_AllocPages(swap->cache_size / 4096); + + if (!swap->cache_base_addr) { + PrintError("Cannot allocate cache space\n"); + V3_Free(swap); + return -1; + } + + swap->cache = (uint8_t *)V3_VAddr((void *)(addr_t)(swap->cache_base_addr)); memset(swap->cache, 0, swap->cache_size); }