aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--block-bochs.c2
-rw-r--r--block-cloop.c9
-rw-r--r--block-dmg.c6
-rw-r--r--block-parallels.c2
-rw-r--r--block-qcow2.c58
-rw-r--r--block-raw-posix.c2
-rw-r--r--block-vmdk.c10
-rw-r--r--block-vpc.c4
-rw-r--r--block-vvfat.c18
-rw-r--r--block.c6
10 files changed, 14 insertions, 103 deletions
diff --git a/block-bochs.c b/block-bochs.c
index b167e0bbfd..593cf697c1 100644
--- a/block-bochs.c
+++ b/block-bochs.c
@@ -149,8 +149,6 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (!s->catalog_bitmap)
- goto fail;
if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
s->catalog_size * 4)
goto fail;
diff --git a/block-cloop.c b/block-cloop.c
index ad0e65d970..6985084bae 100644
--- a/block-cloop.c
+++ b/block-cloop.c
@@ -75,8 +75,7 @@ cloop_close:
/* read offsets */
offsets_size=s->n_blocks*sizeof(uint64_t);
- if(!(s->offsets=(uint64_t*)malloc(offsets_size)))
- goto cloop_close;
+ s->offsets=(uint64_t*)qemu_malloc(offsets_size);
if(read(s->fd,s->offsets,offsets_size)<offsets_size)
goto cloop_close;
for(i=0;i<s->n_blocks;i++) {
@@ -89,10 +88,8 @@ cloop_close:
}
/* initialize zlib engine */
- if(!(s->compressed_block = malloc(max_compressed_block_size+1)))
- goto cloop_close;
- if(!(s->uncompressed_block = malloc(s->block_size)))
- goto cloop_close;
+ s->compressed_block = qemu_malloc(max_compressed_block_size+1);
+ s->uncompressed_block = qemu_malloc(s->block_size);
if(inflateInit(&s->zstream) != Z_OK)
goto cloop_close;
s->current_block=s->n_blocks;
diff --git a/block-dmg.c b/block-dmg.c
index 4320c5dcb3..74454c7c54 100644
--- a/block-dmg.c
+++ b/block-dmg.c
@@ -159,10 +159,8 @@ dmg_close:
}
/* initialize zlib engine */
- if(!(s->compressed_chunk = malloc(max_compressed_size+1)))
- goto dmg_close;
- if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk)))
- goto dmg_close;
+ s->compressed_chunk = qemu_malloc(max_compressed_size+1);
+ s->uncompressed_chunk = qemu_malloc(512*max_sectors_per_chunk);
if(inflateInit(&s->zstream) != Z_OK)
goto dmg_close;
diff --git a/block-parallels.c b/block-parallels.c
index 4654b07b15..8a8ec63da6 100644
--- a/block-parallels.c
+++ b/block-parallels.c
@@ -101,8 +101,6 @@ static int parallels_open(BlockDriverState *bs, const char *filename, int flags)
s->catalog_size = le32_to_cpu(ph.catalog_entries);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (!s->catalog_bitmap)
- goto fail;
if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
s->catalog_size * 4)
goto fail;
diff --git a/block-qcow2.c b/block-qcow2.c
index 8a5b621deb..465dcd6d42 100644
--- a/block-qcow2.c
+++ b/block-qcow2.c
@@ -259,8 +259,6 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
goto fail;
s->l1_table_offset = header.l1_table_offset;
s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
- if (!s->l1_table)
- goto fail;
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
s->l1_size * sizeof(uint64_t))
goto fail;
@@ -269,16 +267,10 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
}
/* alloc L2 cache */
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
- if (!s->l2_cache)
- goto fail;
s->cluster_cache = qemu_malloc(s->cluster_size);
- if (!s->cluster_cache)
- goto fail;
/* one more sector for decompressed data alignment */
s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
+ 512);
- if (!s->cluster_data)
- goto fail;
s->cluster_cache_offset = -1;
if (refcount_init(bs) < 0)
@@ -459,8 +451,6 @@ static int grow_l1_table(BlockDriverState *bs, int min_size)
new_l1_size2 = sizeof(uint64_t) * new_l1_size;
new_l1_table = qemu_mallocz(new_l1_size2);
- if (!new_l1_table)
- return -ENOMEM;
memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
/* write new table (align to cluster) */
@@ -893,8 +883,7 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
if (m->nb_clusters == 0)
return 0;
- if (!(old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t))))
- return -ENOMEM;
+ old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t));
/* copy content of unmodified sectors */
start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9;
@@ -1393,10 +1382,6 @@ static void qcow_aio_write_cb(void *opaque, int ret)
if (!acb->cluster_data) {
acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS *
s->cluster_size);
- if (!acb->cluster_data) {
- ret = -ENOMEM;
- goto fail;
- }
}
encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
acb->n, 1, &s->aes_encrypt_key);
@@ -1521,11 +1506,7 @@ static int qcow_create(const char *filename, int64_t total_size,
offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);
s->refcount_table = qemu_mallocz(s->cluster_size);
- if (!s->refcount_table)
- goto fail;
s->refcount_block = qemu_mallocz(s->cluster_size);
- if (!s->refcount_block)
- goto fail;
s->refcount_table_offset = offset;
header.refcount_table_offset = cpu_to_be64(offset);
@@ -1562,11 +1543,6 @@ static int qcow_create(const char *filename, int64_t total_size,
qemu_free(s->refcount_block);
close(fd);
return 0;
- fail:
- qemu_free(s->refcount_table);
- qemu_free(s->refcount_block);
- close(fd);
- return -ENOMEM;
}
static int qcow_make_empty(BlockDriverState *bs)
@@ -1613,8 +1589,6 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
return -EINVAL;
out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
- if (!out_buf)
- return -ENOMEM;
/* best compression, small window, no zlib header */
memset(&strm, 0, sizeof(strm));
@@ -1699,8 +1673,6 @@ static int update_snapshot_refcount(BlockDriverState *bs,
l1_allocated = 0;
if (l1_table_offset != s->l1_table_offset) {
l1_table = qemu_malloc(l1_size2);
- if (!l1_table)
- goto fail;
l1_allocated = 1;
if (bdrv_pread(s->hd, l1_table_offset,
l1_table, l1_size2) != l1_size2)
@@ -1715,8 +1687,6 @@ static int update_snapshot_refcount(BlockDriverState *bs,
l2_size = s->l2_size * sizeof(uint64_t);
l2_table = qemu_malloc(l2_size);
- if (!l2_table)
- goto fail;
l1_modified = 0;
for(i = 0; i < l1_size; i++) {
l2_offset = l1_table[i];
@@ -1827,8 +1797,6 @@ static int qcow_read_snapshots(BlockDriverState *bs)
offset = s->snapshots_offset;
s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot));
- if (!s->snapshots)
- goto fail;
for(i = 0; i < s->nb_snapshots; i++) {
offset = align_offset(offset, 8);
if (bdrv_pread(s->hd, offset, &h, sizeof(h)) != sizeof(h))
@@ -1849,16 +1817,12 @@ static int qcow_read_snapshots(BlockDriverState *bs)
offset += extra_data_size;
sn->id_str = qemu_malloc(id_str_size + 1);
- if (!sn->id_str)
- goto fail;
if (bdrv_pread(s->hd, offset, sn->id_str, id_str_size) != id_str_size)
goto fail;
offset += id_str_size;
sn->id_str[id_str_size] = '\0';
sn->name = qemu_malloc(name_size + 1);
- if (!sn->name)
- goto fail;
if (bdrv_pread(s->hd, offset, sn->name, name_size) != name_size)
goto fail;
offset += name_size;
@@ -2024,8 +1988,6 @@ static int qcow_snapshot_create(BlockDriverState *bs,
sn->l1_size = s->l1_size;
l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
- if (!l1_table)
- goto fail;
for(i = 0; i < s->l1_size; i++) {
l1_table[i] = cpu_to_be64(s->l1_table[i]);
}
@@ -2037,8 +1999,6 @@ static int qcow_snapshot_create(BlockDriverState *bs,
l1_table = NULL;
snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));
- if (!snapshots1)
- goto fail;
if (s->snapshots) {
memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
qemu_free(s->snapshots);
@@ -2145,8 +2105,6 @@ static int qcow_snapshot_list(BlockDriverState *bs,
int i;
sn_tab = qemu_mallocz(s->nb_snapshots * sizeof(QEMUSnapshotInfo));
- if (!sn_tab)
- goto fail;
for(i = 0; i < s->nb_snapshots; i++) {
sn_info = sn_tab + i;
sn = s->snapshots + i;
@@ -2161,10 +2119,6 @@ static int qcow_snapshot_list(BlockDriverState *bs,
}
*psn_tab = sn_tab;
return s->nb_snapshots;
- fail:
- qemu_free(sn_tab);
- *psn_tab = NULL;
- return -ENOMEM;
}
/*********************************************************/
@@ -2176,12 +2130,8 @@ static int refcount_init(BlockDriverState *bs)
int ret, refcount_table_size2, i;
s->refcount_block_cache = qemu_malloc(s->cluster_size);
- if (!s->refcount_block_cache)
- goto fail;
refcount_table_size2 = s->refcount_table_size * sizeof(uint64_t);
s->refcount_table = qemu_malloc(refcount_table_size2);
- if (!s->refcount_table)
- goto fail;
if (s->refcount_table_size > 0) {
ret = bdrv_pread(s->hd, s->refcount_table_offset,
s->refcount_table, refcount_table_size2);
@@ -2384,8 +2334,6 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
#endif
new_table_size2 = new_table_size * sizeof(uint64_t);
new_table = qemu_mallocz(new_table_size2);
- if (!new_table)
- return -ENOMEM;
memcpy(new_table, s->refcount_table,
s->refcount_table_size * sizeof(uint64_t));
for(i = 0; i < s->refcount_table_size; i++)
@@ -2556,8 +2504,6 @@ static int check_refcounts_l1(BlockDriverState *bs,
l1_table_offset, l1_size2);
l1_table = qemu_malloc(l1_size2);
- if (!l1_table)
- goto fail;
if (bdrv_pread(s->hd, l1_table_offset,
l1_table, l1_size2) != l1_size2)
goto fail;
@@ -2566,8 +2512,6 @@ static int check_refcounts_l1(BlockDriverState *bs,
l2_size = s->l2_size * sizeof(uint64_t);
l2_table = qemu_malloc(l2_size);
- if (!l2_table)
- goto fail;
for(i = 0; i < l1_size; i++) {
l2_offset = l1_table[i];
if (l2_offset) {
diff --git a/block-raw-posix.c b/block-raw-posix.c
index ac88fc36e2..620791b70c 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -533,8 +533,6 @@ static int posix_aio_init(void)
return 0;
s = qemu_malloc(sizeof(PosixAioState));
- if (s == NULL)
- return -ENOMEM;
sigfillset(&act.sa_mask);
act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
diff --git a/block-vmdk.c b/block-vmdk.c
index eefd76beac..71d7504bda 100644
--- a/block-vmdk.c
+++ b/block-vmdk.c
@@ -276,8 +276,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
/* write RGD */
rgd_buf = qemu_malloc(gd_size);
- if (!rgd_buf)
- goto fail;
if (lseek(p_fd, rgd_offset, SEEK_SET) == -1)
goto fail_rgd;
if (read(p_fd, rgd_buf, gd_size) != gd_size)
@@ -290,8 +288,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
/* write GD */
gd_buf = qemu_malloc(gd_size);
- if (!gd_buf)
- goto fail_rgd;
if (lseek(p_fd, gd_offset, SEEK_SET) == -1)
goto fail_gd;
if (read(p_fd, gd_buf, gd_size) != gd_size)
@@ -430,8 +426,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
/* read the L1 table */
l1_size = s->l1_size * sizeof(uint32_t);
s->l1_table = qemu_malloc(l1_size);
- if (!s->l1_table)
- goto fail;
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size)
goto fail;
for(i = 0; i < s->l1_size; i++) {
@@ -440,8 +434,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
if (s->l1_backup_table_offset) {
s->l1_backup_table = qemu_malloc(l1_size);
- if (!s->l1_backup_table)
- goto fail;
if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size)
goto fail;
for(i = 0; i < s->l1_size; i++) {
@@ -450,8 +442,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
}
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
- if (!s->l2_cache)
- goto fail;
return 0;
fail:
qemu_free(s->l1_backup_table);
diff --git a/block-vpc.c b/block-vpc.c
index 3eea506e7c..e353e31a8e 100644
--- a/block-vpc.c
+++ b/block-vpc.c
@@ -196,8 +196,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries);
s->pagetable = qemu_malloc(s->max_table_entries * 4);
- if (!s->pagetable)
- goto fail;
s->bat_offset = be64_to_cpu(dyndisk_header->table_offset);
if (bdrv_pread(s->hd, s->bat_offset, s->pagetable,
@@ -222,8 +220,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
#ifdef CACHE
s->pageentry_u8 = qemu_malloc(512);
- if (!s->pageentry_u8)
- goto fail;
s->pageentry_u32 = s->pageentry_u8;
s->pageentry_u16 = s->pageentry_u8;
s->last_pagetable = -1;
diff --git a/block-vvfat.c b/block-vvfat.c
index 1ac4472ae8..623ba986a6 100644
--- a/block-vvfat.c
+++ b/block-vvfat.c
@@ -159,7 +159,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun
is=array->item_size;
from=array->pointer+index_from*is;
to=array->pointer+index_to*is;
- buf=malloc(is*count);
+ buf=qemu_malloc(is*count);
memcpy(buf,from,is*count);
if(index_to<index_from)
@@ -725,8 +725,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
if(first_cluster == 0 && (is_dotdot || is_dot))
continue;
- buffer=(char*)malloc(length);
- assert(buffer);
+ buffer=(char*)qemu_malloc(length);
snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
if(stat(buffer,&st)<0) {
@@ -847,8 +846,7 @@ static int init_directories(BDRVVVFATState* s,
memset(&(s->first_sectors[0]),0,0x40*0x200);
s->cluster_size=s->sectors_per_cluster*0x200;
- s->cluster_buffer=malloc(s->cluster_size);
- assert(s->cluster_buffer);
+ s->cluster_buffer=qemu_malloc(s->cluster_size);
/*
* The formula: sc = spf+1+spf*spc*(512*8/fat_type),
@@ -1728,7 +1726,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
int cluster_num, const char* path)
{
int ret = 0;
- unsigned char* cluster = malloc(s->cluster_size);
+ unsigned char* cluster = qemu_malloc(s->cluster_size);
direntry_t* direntries = (direntry_t*)cluster;
mapping_t* mapping = find_mapping_for_cluster(s, cluster_num);
@@ -1869,7 +1867,7 @@ DLOG(checkpoint());
*/
if (s->fat2 == NULL) {
int size = 0x200 * s->sectors_per_fat;
- s->fat2 = malloc(size);
+ s->fat2 = qemu_malloc(size);
memcpy(s->fat2, s->fat.pointer, size);
}
check = vvfat_read(s->bs,
@@ -2211,7 +2209,7 @@ static int commit_one_file(BDRVVVFATState* s,
uint32_t first_cluster = c;
mapping_t* mapping = find_mapping_for_cluster(s, c);
uint32_t size = filesize_of_direntry(direntry);
- char* cluster = malloc(s->cluster_size);
+ char* cluster = qemu_malloc(s->cluster_size);
uint32_t i;
int fd = 0;
@@ -2373,7 +2371,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
mapping_t* m = find_mapping_for_cluster(s,
begin_of_direntry(d));
int l = strlen(m->path);
- char* new_path = malloc(l + diff + 1);
+ char* new_path = qemu_malloc(l + diff + 1);
assert(!strncmp(m->path, mapping->path, l2));
@@ -2774,7 +2772,7 @@ static int enable_write_target(BDRVVVFATState *s)
array_init(&(s->commits), sizeof(commit_t));
- s->qcow_filename = malloc(1024);
+ s->qcow_filename = qemu_malloc(1024);
get_tmp_filename(s->qcow_filename, 1024);
if (bdrv_create(&bdrv_qcow,
s->qcow_filename, s->sector_count, "fat:", 0) < 0)
diff --git a/block.c b/block.c
index b3d2f12090..4f4bf7ceef 100644
--- a/block.c
+++ b/block.c
@@ -151,8 +151,6 @@ BlockDriverState *bdrv_new(const char *device_name)
BlockDriverState **pbs, *bs;
bs = qemu_mallocz(sizeof(BlockDriverState));
- if(!bs)
- return NULL;
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
if (device_name[0] != '\0') {
/* insert at the end */
@@ -395,8 +393,6 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
}
bs->drv = drv;
bs->opaque = qemu_mallocz(drv->instance_size);
- if (bs->opaque == NULL && drv->instance_size > 0)
- return -1;
/* Note: for compatibility, we open disk image files as RDWR, and
RDONLY as fallback */
if (!(flags & BDRV_O_FILE))
@@ -1498,8 +1494,6 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
drv->free_aiocb = acb->next;
} else {
acb = qemu_mallocz(drv->aiocb_size);
- if (!acb)
- return NULL;
}
acb->bs = bs;
acb->cb = cb;