From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LVCM9-0005ot-GW for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LVCM8-0005oC-Jk for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:57 -0500 Received: from [199.232.76.173] (port=44906 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LVCM8-0005o5-Bx for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:56 -0500 Received: from savannah.gnu.org ([199.232.41.3]:35483 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LVCM7-0002Q0-Je for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:56 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LVCM6-0007gn-Fl for qemu-devel@nongnu.org; Thu, 05 Feb 2009 22:05:54 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LVCM6-0007gj-6u for qemu-devel@nongnu.org; Thu, 05 Feb 2009 22:05:54 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Feb 2009 22:05:54 +0000 Subject: [Qemu-devel] [6527] block: remove error handling from qemu_malloc() callers (Avi Kivity) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6527 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6527 Author: aliguori Date: 2009-02-05 22:05:53 +0000 (Thu, 05 Feb 2009) Log Message: ----------- block: remove error handling from qemu_malloc() callers (Avi Kivity) Signed-off-by: Avi Kivity Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block-bochs.c trunk/block-cloop.c trunk/block-dmg.c trunk/block-parallels.c trunk/block-qcow2.c trunk/block-raw-posix.c trunk/block-vmdk.c trunk/block-vpc.c trunk/block-vvfat.c trunk/block.c Modified: trunk/block-bochs.c =================================================================== --- trunk/block-bochs.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-bochs.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -149,8 +149,6 @@ 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; Modified: trunk/block-cloop.c =================================================================== --- trunk/block-cloop.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-cloop.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -75,8 +75,7 @@ /* 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)n_blocks;i++) { @@ -89,10 +88,8 @@ } /* 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; Modified: trunk/block-dmg.c =================================================================== --- trunk/block-dmg.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-dmg.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -159,10 +159,8 @@ } /* 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; Modified: trunk/block-parallels.c =================================================================== --- trunk/block-parallels.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-parallels.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -101,8 +101,6 @@ 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; Modified: trunk/block-qcow2.c =================================================================== --- trunk/block-qcow2.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-qcow2.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -259,8 +259,6 @@ 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 @@ } /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } *psn_tab = sn_tab; return s->nb_snapshots; - fail: - qemu_free(sn_tab); - *psn_tab = NULL; - return -ENOMEM; } /*********************************************************/ @@ -2176,12 +2130,8 @@ 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 @@ #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 @@ 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 @@ 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) { Modified: trunk/block-raw-posix.c =================================================================== --- trunk/block-raw-posix.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-raw-posix.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -533,8 +533,6 @@ 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() */ Modified: trunk/block-vmdk.c =================================================================== --- trunk/block-vmdk.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-vmdk.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -276,8 +276,6 @@ /* 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 @@ /* 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 @@ /* 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 @@ 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 @@ } 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); Modified: trunk/block-vpc.c =================================================================== --- trunk/block-vpc.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-vpc.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -196,8 +196,6 @@ 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 @@ #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; Modified: trunk/block-vvfat.c =================================================================== --- trunk/block-vvfat.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block-vvfat.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -159,7 +159,7 @@ 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_tod_name); if(stat(buffer,&st)<0) { @@ -847,8 +846,7 @@ 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 @@ 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 @@ */ 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 @@ 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 @@ 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 @@ 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) Modified: trunk/block.c =================================================================== --- trunk/block.c 2009-02-05 22:05:49 UTC (rev 6526) +++ trunk/block.c 2009-02-05 22:05:53 UTC (rev 6527) @@ -151,8 +151,6 @@ 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 @@ } 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 @@ drv->free_aiocb = acb->next; } else { acb = qemu_mallocz(drv->aiocb_size); - if (!acb) - return NULL; } acb->bs = bs; acb->cb = cb;