mp = palacios_alloc_extended(sizeof(struct buddy_mempool), GFP_KERNEL, zone->node_id);
- if (IS_ERR(mp)) {
+ if (!mp) {
ERROR("Could not allocate mempool\n");
return -1;
}
BITS_TO_LONGS(mp->num_blocks) * sizeof(long), GFP_KERNEL, zone->node_id
);
+ if (!(mp->tag_bits)) {
+ ERROR("Could not allocate tag_bits\n");
+ palacios_free(mp);
+ return -1;
+ }
+
+
/* Initially mark all minimum-sized blocks as allocated */
bitmap_zero(mp->tag_bits, mp->num_blocks);
struct top_half_data * top;
top = palacios_alloc(sizeof(struct top_half_data));
- if (IS_ERR(top)) {
+ if (!top) {
ERROR("Palacios Error: could not allocate space for top half data\n");
return -EFAULT;
}
DEBUG("Palacios: Allocating %lu B of kernel memory for ELF binary data...\n", top->elf_size);
top->elf_data = palacios_alloc(top->elf_size);
- if (IS_ERR(top->elf_data)) {
+ if (!(top->elf_data)) {
ERROR("Palacios Error: could not allocate space for binary image\n");
palacios_free(top);
return -EFAULT;
}
env = palacios_alloc(sizeof(struct env_data));
- if (IS_ERR(env)) {
+ if (!env) {
ERROR("Palacios Error: could not allocate space for environment data\n");
return -EFAULT;
}
//DEBUG("Palacios: Allocating space for %u env var string ptrs...\n", env->num_strings);
env->strings = palacios_alloc(env->num_strings*sizeof(char*));
- if (IS_ERR(env->strings)) {
+ if (!(env->strings)) {
ERROR("Palacios Error: could not allocate space for env var strings\n");
return -EFAULT;
}
for (i = 0; i < env->num_strings; i++) {
char * tmp = palacios_alloc(MAX_STRING_LEN);
- if (IS_ERR(tmp)) {
+ if (!(tmp)) {
ERROR("Palacios Error: could not allocate space for env var string #%d\n", i);
return -EFAULT;
}
{
dentry = kern_path_create(AT_FDCWD, pathname, &tmp_path, 1);
- if (IS_ERR(dentry)) {
+ if (!dentry || IS_ERR(dentry)) {
return 0;
}
#endif
- if (!IS_ERR(dentry)) {
+ if (!(!dentry || IS_ERR(dentry))) {
ret = vfs_mkdir(path_ptr->dentry->d_inode, dentry, perms);
}
pfile->filp = filp_open(path, pfile->mode, 0);
- if (IS_ERR(pfile->filp)) {
+ if (!pfile->filp || IS_ERR(pfile->filp)) {
ERROR("Cannot open file: %s\n", path);
palacios_free(pfile);
return NULL;
de = lookup_create(&nd,1);
- if (IS_ERR(de)) {
+ if (!de || IS_ERR(de)) {
ERROR("cannot allocate dentry\n");
goto fail_out;
}
strcat(path,"/");
strcat(path,key);
- fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream *));
+ fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream));
if (!fs) {
ERROR("cannot allocate file keyed stream for key %s\n",key);
fs->f = filp_open(path,O_RDWR|O_CREAT|O_LARGEFILE,0600);
- if (IS_ERR(fs->f)) {
+ if (!fs->f || IS_ERR(fs->f)) {
ERROR("cannot open relevent file \"%s\" for stream \"file:%s\" and key \"%s\"\n",path,fks->path,key);
palacios_free(fs);
palacios_free(path);
guest_dir = debugfs_create_dir(guest->name, v3_dir);
- if (IS_ERR(guest_dir)) {
+ if (!guest_dir || IS_ERR(guest_dir)) {
ERROR("Error Creating inspector tree for VM \"%s\"\n", guest->name);
return -1;
}
v3_dir = debugfs_create_dir("v3vee", NULL);
- if (IS_ERR(v3_dir)) {
+ if (!v3_dir || IS_ERR(v3_dir)) {
ERROR("Error creating v3vee debugfs directory\n");
return -1;
}
struct v3_guest_img user_image;
struct v3_guest * guest = palacios_alloc(sizeof(struct v3_guest));
- if (IS_ERR(guest)) {
+ if (!(guest)) {
ERROR("Palacios: Error allocating Kernel guest_image\n");
return -EFAULT;
}
DEBUG("Palacios: Allocating kernel memory for guest image (%llu bytes)\n", user_image.size);
guest->img = palacios_valloc(guest->img_size);
- if (IS_ERR(guest->img)) {
+ if (!guest->img) {
ERROR("Palacios Error: Could not allocate space for guest image\n");
goto out_err1;
}
v3_class = class_create(THIS_MODULE, "vms");
- if (IS_ERR(v3_class)) {
+ if (!v3_class || IS_ERR(v3_class)) {
ERROR("Failed to register V3 VM device class\n");
ret = PTR_ERR(v3_class);
goto failure3;
-// The following can be used to track heap bugs
-// zero memory after allocation
-#define ALLOC_ZERO_MEM 0
-// pad allocations by this many bytes on both ends of block
+// The following can be used to track memory bugs
+// zero memory after allocation (now applies to valloc and page alloc as well)
+#define ALLOC_ZERO_MEM 1
+// pad allocations by this many bytes on both ends of block (heap only)
#define ALLOC_PAD 0
pg_allocs += num_pages;
+#if ALLOC_ZERO_MEM
+ memset(__va(pg_addr),0,num_pages*4096);
+#endif
+
MEMCHECK_ALLOC_PAGES(pg_addr,num_pages*4096);
return pg_addr;
addr = kmalloc_node(size+2*ALLOC_PAD, flags, node);
}
- if (!addr) {
+ if (!addr || IS_ERR(addr)) {
ERROR("ALERT ALERT kmalloc has FAILED FAILED FAILED\n");
return NULL;
}
addr = vmalloc(size);
- if (!addr) {
+ if (!addr || IS_ERR(addr)) {
ERROR("ALERT ALERT vmalloc has FAILED FAILED FAILED\n");
return NULL;
}
vmallocs++;
+#if ALLOC_ZERO_MEM
+ memset(addr,0,size);
+#endif
+
MEMCHECK_VMALLOC(addr,size);
return addr;
thread = kthread_create( lnx_thread_target, thread_info, thread_info->name );
- if (IS_ERR(thread)) {
+ if (!thread || IS_ERR(thread)) {
WARNING("Palacios error creating thread: %s\n", thread_info->name);
palacios_free(thread_info);
return NULL;
ctx = v3_chkpt_open_ctx(chkpt, "header");
+ if (!ctx) {
+ PrintError(vm, VCORE_NONE, "Cannot open context to load header\n");
+ return -1;
+ }
+
switch (v3_mach_type) {
case V3_SVM_CPU:
case V3_SVM_REV3_CPU: {
void v3_dump_mem(uint8_t * start, int n) {
int i, j;
char buf[128];
-
+ if (!start) {
+ return;
+ }
+
for (i = 0; i < n; i += 16) {
snprintf(buf, 128, "%p ", (void *)(start + i));
for (j = i; (j < (i + 16)) && (j < n); j++) {