Commit 3ec88e80365c889f824d9a171fbf197b46a7c03f

Authored by aliguori
1 parent 8a1d02ab

block: remove error handling from qemu_malloc() callers (Avi Kivity)

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6527 c046a42c-6fe2-441c-8c8c-71466251a162
block-bochs.c
@@ -149,8 +149,6 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags) @@ -149,8 +149,6 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
149 149
150 s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog); 150 s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
151 s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); 151 s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
152 - if (!s->catalog_bitmap)  
153 - goto fail;  
154 if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) != 152 if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
155 s->catalog_size * 4) 153 s->catalog_size * 4)
156 goto fail; 154 goto fail;
block-cloop.c
@@ -75,8 +75,7 @@ cloop_close: @@ -75,8 +75,7 @@ cloop_close:
75 75
76 /* read offsets */ 76 /* read offsets */
77 offsets_size=s->n_blocks*sizeof(uint64_t); 77 offsets_size=s->n_blocks*sizeof(uint64_t);
78 - if(!(s->offsets=(uint64_t*)malloc(offsets_size)))  
79 - goto cloop_close; 78 + s->offsets=(uint64_t*)qemu_malloc(offsets_size);
80 if(read(s->fd,s->offsets,offsets_size)<offsets_size) 79 if(read(s->fd,s->offsets,offsets_size)<offsets_size)
81 goto cloop_close; 80 goto cloop_close;
82 for(i=0;i<s->n_blocks;i++) { 81 for(i=0;i<s->n_blocks;i++) {
@@ -89,10 +88,8 @@ cloop_close: @@ -89,10 +88,8 @@ cloop_close:
89 } 88 }
90 89
91 /* initialize zlib engine */ 90 /* initialize zlib engine */
92 - if(!(s->compressed_block = malloc(max_compressed_block_size+1)))  
93 - goto cloop_close;  
94 - if(!(s->uncompressed_block = malloc(s->block_size)))  
95 - goto cloop_close; 91 + s->compressed_block = qemu_malloc(max_compressed_block_size+1);
  92 + s->uncompressed_block = qemu_malloc(s->block_size);
96 if(inflateInit(&s->zstream) != Z_OK) 93 if(inflateInit(&s->zstream) != Z_OK)
97 goto cloop_close; 94 goto cloop_close;
98 s->current_block=s->n_blocks; 95 s->current_block=s->n_blocks;
block-dmg.c
@@ -159,10 +159,8 @@ dmg_close: @@ -159,10 +159,8 @@ dmg_close:
159 } 159 }
160 160
161 /* initialize zlib engine */ 161 /* initialize zlib engine */
162 - if(!(s->compressed_chunk = malloc(max_compressed_size+1)))  
163 - goto dmg_close;  
164 - if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk)))  
165 - goto dmg_close; 162 + s->compressed_chunk = qemu_malloc(max_compressed_size+1);
  163 + s->uncompressed_chunk = qemu_malloc(512*max_sectors_per_chunk);
166 if(inflateInit(&s->zstream) != Z_OK) 164 if(inflateInit(&s->zstream) != Z_OK)
167 goto dmg_close; 165 goto dmg_close;
168 166
block-parallels.c
@@ -101,8 +101,6 @@ static int parallels_open(BlockDriverState *bs, const char *filename, int flags) @@ -101,8 +101,6 @@ static int parallels_open(BlockDriverState *bs, const char *filename, int flags)
101 101
102 s->catalog_size = le32_to_cpu(ph.catalog_entries); 102 s->catalog_size = le32_to_cpu(ph.catalog_entries);
103 s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); 103 s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
104 - if (!s->catalog_bitmap)  
105 - goto fail;  
106 if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) != 104 if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
107 s->catalog_size * 4) 105 s->catalog_size * 4)
108 goto fail; 106 goto fail;
block-qcow2.c
@@ -259,8 +259,6 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) @@ -259,8 +259,6 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
259 goto fail; 259 goto fail;
260 s->l1_table_offset = header.l1_table_offset; 260 s->l1_table_offset = header.l1_table_offset;
261 s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); 261 s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
262 - if (!s->l1_table)  
263 - goto fail;  
264 if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) != 262 if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
265 s->l1_size * sizeof(uint64_t)) 263 s->l1_size * sizeof(uint64_t))
266 goto fail; 264 goto fail;
@@ -269,16 +267,10 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) @@ -269,16 +267,10 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
269 } 267 }
270 /* alloc L2 cache */ 268 /* alloc L2 cache */
271 s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); 269 s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
272 - if (!s->l2_cache)  
273 - goto fail;  
274 s->cluster_cache = qemu_malloc(s->cluster_size); 270 s->cluster_cache = qemu_malloc(s->cluster_size);
275 - if (!s->cluster_cache)  
276 - goto fail;  
277 /* one more sector for decompressed data alignment */ 271 /* one more sector for decompressed data alignment */
278 s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size 272 s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
279 + 512); 273 + 512);
280 - if (!s->cluster_data)  
281 - goto fail;  
282 s->cluster_cache_offset = -1; 274 s->cluster_cache_offset = -1;
283 275
284 if (refcount_init(bs) < 0) 276 if (refcount_init(bs) < 0)
@@ -459,8 +451,6 @@ static int grow_l1_table(BlockDriverState *bs, int min_size) @@ -459,8 +451,6 @@ static int grow_l1_table(BlockDriverState *bs, int min_size)
459 451
460 new_l1_size2 = sizeof(uint64_t) * new_l1_size; 452 new_l1_size2 = sizeof(uint64_t) * new_l1_size;
461 new_l1_table = qemu_mallocz(new_l1_size2); 453 new_l1_table = qemu_mallocz(new_l1_size2);
462 - if (!new_l1_table)  
463 - return -ENOMEM;  
464 memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); 454 memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
465 455
466 /* write new table (align to cluster) */ 456 /* write new table (align to cluster) */
@@ -893,8 +883,7 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, @@ -893,8 +883,7 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
893 if (m->nb_clusters == 0) 883 if (m->nb_clusters == 0)
894 return 0; 884 return 0;
895 885
896 - if (!(old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t))))  
897 - return -ENOMEM; 886 + old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t));
898 887
899 /* copy content of unmodified sectors */ 888 /* copy content of unmodified sectors */
900 start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9; 889 start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9;
@@ -1393,10 +1382,6 @@ static void qcow_aio_write_cb(void *opaque, int ret) @@ -1393,10 +1382,6 @@ static void qcow_aio_write_cb(void *opaque, int ret)
1393 if (!acb->cluster_data) { 1382 if (!acb->cluster_data) {
1394 acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * 1383 acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS *
1395 s->cluster_size); 1384 s->cluster_size);
1396 - if (!acb->cluster_data) {  
1397 - ret = -ENOMEM;  
1398 - goto fail;  
1399 - }  
1400 } 1385 }
1401 encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, 1386 encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
1402 acb->n, 1, &s->aes_encrypt_key); 1387 acb->n, 1, &s->aes_encrypt_key);
@@ -1521,11 +1506,7 @@ static int qcow_create(const char *filename, int64_t total_size, @@ -1521,11 +1506,7 @@ static int qcow_create(const char *filename, int64_t total_size,
1521 offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size); 1506 offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);
1522 1507
1523 s->refcount_table = qemu_mallocz(s->cluster_size); 1508 s->refcount_table = qemu_mallocz(s->cluster_size);
1524 - if (!s->refcount_table)  
1525 - goto fail;  
1526 s->refcount_block = qemu_mallocz(s->cluster_size); 1509 s->refcount_block = qemu_mallocz(s->cluster_size);
1527 - if (!s->refcount_block)  
1528 - goto fail;  
1529 1510
1530 s->refcount_table_offset = offset; 1511 s->refcount_table_offset = offset;
1531 header.refcount_table_offset = cpu_to_be64(offset); 1512 header.refcount_table_offset = cpu_to_be64(offset);
@@ -1562,11 +1543,6 @@ static int qcow_create(const char *filename, int64_t total_size, @@ -1562,11 +1543,6 @@ static int qcow_create(const char *filename, int64_t total_size,
1562 qemu_free(s->refcount_block); 1543 qemu_free(s->refcount_block);
1563 close(fd); 1544 close(fd);
1564 return 0; 1545 return 0;
1565 - fail:  
1566 - qemu_free(s->refcount_table);  
1567 - qemu_free(s->refcount_block);  
1568 - close(fd);  
1569 - return -ENOMEM;  
1570 } 1546 }
1571 1547
1572 static int qcow_make_empty(BlockDriverState *bs) 1548 static int qcow_make_empty(BlockDriverState *bs)
@@ -1613,8 +1589,6 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, @@ -1613,8 +1589,6 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
1613 return -EINVAL; 1589 return -EINVAL;
1614 1590
1615 out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); 1591 out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
1616 - if (!out_buf)  
1617 - return -ENOMEM;  
1618 1592
1619 /* best compression, small window, no zlib header */ 1593 /* best compression, small window, no zlib header */
1620 memset(&strm, 0, sizeof(strm)); 1594 memset(&strm, 0, sizeof(strm));
@@ -1699,8 +1673,6 @@ static int update_snapshot_refcount(BlockDriverState *bs, @@ -1699,8 +1673,6 @@ static int update_snapshot_refcount(BlockDriverState *bs,
1699 l1_allocated = 0; 1673 l1_allocated = 0;
1700 if (l1_table_offset != s->l1_table_offset) { 1674 if (l1_table_offset != s->l1_table_offset) {
1701 l1_table = qemu_malloc(l1_size2); 1675 l1_table = qemu_malloc(l1_size2);
1702 - if (!l1_table)  
1703 - goto fail;  
1704 l1_allocated = 1; 1676 l1_allocated = 1;
1705 if (bdrv_pread(s->hd, l1_table_offset, 1677 if (bdrv_pread(s->hd, l1_table_offset,
1706 l1_table, l1_size2) != l1_size2) 1678 l1_table, l1_size2) != l1_size2)
@@ -1715,8 +1687,6 @@ static int update_snapshot_refcount(BlockDriverState *bs, @@ -1715,8 +1687,6 @@ static int update_snapshot_refcount(BlockDriverState *bs,
1715 1687
1716 l2_size = s->l2_size * sizeof(uint64_t); 1688 l2_size = s->l2_size * sizeof(uint64_t);
1717 l2_table = qemu_malloc(l2_size); 1689 l2_table = qemu_malloc(l2_size);
1718 - if (!l2_table)  
1719 - goto fail;  
1720 l1_modified = 0; 1690 l1_modified = 0;
1721 for(i = 0; i < l1_size; i++) { 1691 for(i = 0; i < l1_size; i++) {
1722 l2_offset = l1_table[i]; 1692 l2_offset = l1_table[i];
@@ -1827,8 +1797,6 @@ static int qcow_read_snapshots(BlockDriverState *bs) @@ -1827,8 +1797,6 @@ static int qcow_read_snapshots(BlockDriverState *bs)
1827 1797
1828 offset = s->snapshots_offset; 1798 offset = s->snapshots_offset;
1829 s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot)); 1799 s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot));
1830 - if (!s->snapshots)  
1831 - goto fail;  
1832 for(i = 0; i < s->nb_snapshots; i++) { 1800 for(i = 0; i < s->nb_snapshots; i++) {
1833 offset = align_offset(offset, 8); 1801 offset = align_offset(offset, 8);
1834 if (bdrv_pread(s->hd, offset, &h, sizeof(h)) != sizeof(h)) 1802 if (bdrv_pread(s->hd, offset, &h, sizeof(h)) != sizeof(h))
@@ -1849,16 +1817,12 @@ static int qcow_read_snapshots(BlockDriverState *bs) @@ -1849,16 +1817,12 @@ static int qcow_read_snapshots(BlockDriverState *bs)
1849 offset += extra_data_size; 1817 offset += extra_data_size;
1850 1818
1851 sn->id_str = qemu_malloc(id_str_size + 1); 1819 sn->id_str = qemu_malloc(id_str_size + 1);
1852 - if (!sn->id_str)  
1853 - goto fail;  
1854 if (bdrv_pread(s->hd, offset, sn->id_str, id_str_size) != id_str_size) 1820 if (bdrv_pread(s->hd, offset, sn->id_str, id_str_size) != id_str_size)
1855 goto fail; 1821 goto fail;
1856 offset += id_str_size; 1822 offset += id_str_size;
1857 sn->id_str[id_str_size] = '\0'; 1823 sn->id_str[id_str_size] = '\0';
1858 1824
1859 sn->name = qemu_malloc(name_size + 1); 1825 sn->name = qemu_malloc(name_size + 1);
1860 - if (!sn->name)  
1861 - goto fail;  
1862 if (bdrv_pread(s->hd, offset, sn->name, name_size) != name_size) 1826 if (bdrv_pread(s->hd, offset, sn->name, name_size) != name_size)
1863 goto fail; 1827 goto fail;
1864 offset += name_size; 1828 offset += name_size;
@@ -2024,8 +1988,6 @@ static int qcow_snapshot_create(BlockDriverState *bs, @@ -2024,8 +1988,6 @@ static int qcow_snapshot_create(BlockDriverState *bs,
2024 sn->l1_size = s->l1_size; 1988 sn->l1_size = s->l1_size;
2025 1989
2026 l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); 1990 l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
2027 - if (!l1_table)  
2028 - goto fail;  
2029 for(i = 0; i < s->l1_size; i++) { 1991 for(i = 0; i < s->l1_size; i++) {
2030 l1_table[i] = cpu_to_be64(s->l1_table[i]); 1992 l1_table[i] = cpu_to_be64(s->l1_table[i]);
2031 } 1993 }
@@ -2037,8 +1999,6 @@ static int qcow_snapshot_create(BlockDriverState *bs, @@ -2037,8 +1999,6 @@ static int qcow_snapshot_create(BlockDriverState *bs,
2037 l1_table = NULL; 1999 l1_table = NULL;
2038 2000
2039 snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); 2001 snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));
2040 - if (!snapshots1)  
2041 - goto fail;  
2042 if (s->snapshots) { 2002 if (s->snapshots) {
2043 memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot)); 2003 memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
2044 qemu_free(s->snapshots); 2004 qemu_free(s->snapshots);
@@ -2145,8 +2105,6 @@ static int qcow_snapshot_list(BlockDriverState *bs, @@ -2145,8 +2105,6 @@ static int qcow_snapshot_list(BlockDriverState *bs,
2145 int i; 2105 int i;
2146 2106
2147 sn_tab = qemu_mallocz(s->nb_snapshots * sizeof(QEMUSnapshotInfo)); 2107 sn_tab = qemu_mallocz(s->nb_snapshots * sizeof(QEMUSnapshotInfo));
2148 - if (!sn_tab)  
2149 - goto fail;  
2150 for(i = 0; i < s->nb_snapshots; i++) { 2108 for(i = 0; i < s->nb_snapshots; i++) {
2151 sn_info = sn_tab + i; 2109 sn_info = sn_tab + i;
2152 sn = s->snapshots + i; 2110 sn = s->snapshots + i;
@@ -2161,10 +2119,6 @@ static int qcow_snapshot_list(BlockDriverState *bs, @@ -2161,10 +2119,6 @@ static int qcow_snapshot_list(BlockDriverState *bs,
2161 } 2119 }
2162 *psn_tab = sn_tab; 2120 *psn_tab = sn_tab;
2163 return s->nb_snapshots; 2121 return s->nb_snapshots;
2164 - fail:  
2165 - qemu_free(sn_tab);  
2166 - *psn_tab = NULL;  
2167 - return -ENOMEM;  
2168 } 2122 }
2169 2123
2170 /*********************************************************/ 2124 /*********************************************************/
@@ -2176,12 +2130,8 @@ static int refcount_init(BlockDriverState *bs) @@ -2176,12 +2130,8 @@ static int refcount_init(BlockDriverState *bs)
2176 int ret, refcount_table_size2, i; 2130 int ret, refcount_table_size2, i;
2177 2131
2178 s->refcount_block_cache = qemu_malloc(s->cluster_size); 2132 s->refcount_block_cache = qemu_malloc(s->cluster_size);
2179 - if (!s->refcount_block_cache)  
2180 - goto fail;  
2181 refcount_table_size2 = s->refcount_table_size * sizeof(uint64_t); 2133 refcount_table_size2 = s->refcount_table_size * sizeof(uint64_t);
2182 s->refcount_table = qemu_malloc(refcount_table_size2); 2134 s->refcount_table = qemu_malloc(refcount_table_size2);
2183 - if (!s->refcount_table)  
2184 - goto fail;  
2185 if (s->refcount_table_size > 0) { 2135 if (s->refcount_table_size > 0) {
2186 ret = bdrv_pread(s->hd, s->refcount_table_offset, 2136 ret = bdrv_pread(s->hd, s->refcount_table_offset,
2187 s->refcount_table, refcount_table_size2); 2137 s->refcount_table, refcount_table_size2);
@@ -2384,8 +2334,6 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size) @@ -2384,8 +2334,6 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
2384 #endif 2334 #endif
2385 new_table_size2 = new_table_size * sizeof(uint64_t); 2335 new_table_size2 = new_table_size * sizeof(uint64_t);
2386 new_table = qemu_mallocz(new_table_size2); 2336 new_table = qemu_mallocz(new_table_size2);
2387 - if (!new_table)  
2388 - return -ENOMEM;  
2389 memcpy(new_table, s->refcount_table, 2337 memcpy(new_table, s->refcount_table,
2390 s->refcount_table_size * sizeof(uint64_t)); 2338 s->refcount_table_size * sizeof(uint64_t));
2391 for(i = 0; i < s->refcount_table_size; i++) 2339 for(i = 0; i < s->refcount_table_size; i++)
@@ -2556,8 +2504,6 @@ static int check_refcounts_l1(BlockDriverState *bs, @@ -2556,8 +2504,6 @@ static int check_refcounts_l1(BlockDriverState *bs,
2556 l1_table_offset, l1_size2); 2504 l1_table_offset, l1_size2);
2557 2505
2558 l1_table = qemu_malloc(l1_size2); 2506 l1_table = qemu_malloc(l1_size2);
2559 - if (!l1_table)  
2560 - goto fail;  
2561 if (bdrv_pread(s->hd, l1_table_offset, 2507 if (bdrv_pread(s->hd, l1_table_offset,
2562 l1_table, l1_size2) != l1_size2) 2508 l1_table, l1_size2) != l1_size2)
2563 goto fail; 2509 goto fail;
@@ -2566,8 +2512,6 @@ static int check_refcounts_l1(BlockDriverState *bs, @@ -2566,8 +2512,6 @@ static int check_refcounts_l1(BlockDriverState *bs,
2566 2512
2567 l2_size = s->l2_size * sizeof(uint64_t); 2513 l2_size = s->l2_size * sizeof(uint64_t);
2568 l2_table = qemu_malloc(l2_size); 2514 l2_table = qemu_malloc(l2_size);
2569 - if (!l2_table)  
2570 - goto fail;  
2571 for(i = 0; i < l1_size; i++) { 2515 for(i = 0; i < l1_size; i++) {
2572 l2_offset = l1_table[i]; 2516 l2_offset = l1_table[i];
2573 if (l2_offset) { 2517 if (l2_offset) {
block-raw-posix.c
@@ -533,8 +533,6 @@ static int posix_aio_init(void) @@ -533,8 +533,6 @@ static int posix_aio_init(void)
533 return 0; 533 return 0;
534 534
535 s = qemu_malloc(sizeof(PosixAioState)); 535 s = qemu_malloc(sizeof(PosixAioState));
536 - if (s == NULL)  
537 - return -ENOMEM;  
538 536
539 sigfillset(&act.sa_mask); 537 sigfillset(&act.sa_mask);
540 act.sa_flags = 0; /* do not restart syscalls to interrupt select() */ 538 act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
block-vmdk.c
@@ -276,8 +276,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) @@ -276,8 +276,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
276 276
277 /* write RGD */ 277 /* write RGD */
278 rgd_buf = qemu_malloc(gd_size); 278 rgd_buf = qemu_malloc(gd_size);
279 - if (!rgd_buf)  
280 - goto fail;  
281 if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) 279 if (lseek(p_fd, rgd_offset, SEEK_SET) == -1)
282 goto fail_rgd; 280 goto fail_rgd;
283 if (read(p_fd, rgd_buf, gd_size) != gd_size) 281 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) @@ -290,8 +288,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
290 288
291 /* write GD */ 289 /* write GD */
292 gd_buf = qemu_malloc(gd_size); 290 gd_buf = qemu_malloc(gd_size);
293 - if (!gd_buf)  
294 - goto fail_rgd;  
295 if (lseek(p_fd, gd_offset, SEEK_SET) == -1) 291 if (lseek(p_fd, gd_offset, SEEK_SET) == -1)
296 goto fail_gd; 292 goto fail_gd;
297 if (read(p_fd, gd_buf, gd_size) != gd_size) 293 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) @@ -430,8 +426,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
430 /* read the L1 table */ 426 /* read the L1 table */
431 l1_size = s->l1_size * sizeof(uint32_t); 427 l1_size = s->l1_size * sizeof(uint32_t);
432 s->l1_table = qemu_malloc(l1_size); 428 s->l1_table = qemu_malloc(l1_size);
433 - if (!s->l1_table)  
434 - goto fail;  
435 if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size) 429 if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size)
436 goto fail; 430 goto fail;
437 for(i = 0; i < s->l1_size; i++) { 431 for(i = 0; i < s->l1_size; i++) {
@@ -440,8 +434,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) @@ -440,8 +434,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
440 434
441 if (s->l1_backup_table_offset) { 435 if (s->l1_backup_table_offset) {
442 s->l1_backup_table = qemu_malloc(l1_size); 436 s->l1_backup_table = qemu_malloc(l1_size);
443 - if (!s->l1_backup_table)  
444 - goto fail;  
445 if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size) 437 if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size)
446 goto fail; 438 goto fail;
447 for(i = 0; i < s->l1_size; i++) { 439 for(i = 0; i < s->l1_size; i++) {
@@ -450,8 +442,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) @@ -450,8 +442,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
450 } 442 }
451 443
452 s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t)); 444 s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
453 - if (!s->l2_cache)  
454 - goto fail;  
455 return 0; 445 return 0;
456 fail: 446 fail:
457 qemu_free(s->l1_backup_table); 447 qemu_free(s->l1_backup_table);
block-vpc.c
@@ -196,8 +196,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags) @@ -196,8 +196,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
196 196
197 s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries); 197 s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries);
198 s->pagetable = qemu_malloc(s->max_table_entries * 4); 198 s->pagetable = qemu_malloc(s->max_table_entries * 4);
199 - if (!s->pagetable)  
200 - goto fail;  
201 199
202 s->bat_offset = be64_to_cpu(dyndisk_header->table_offset); 200 s->bat_offset = be64_to_cpu(dyndisk_header->table_offset);
203 if (bdrv_pread(s->hd, s->bat_offset, s->pagetable, 201 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) @@ -222,8 +220,6 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
222 220
223 #ifdef CACHE 221 #ifdef CACHE
224 s->pageentry_u8 = qemu_malloc(512); 222 s->pageentry_u8 = qemu_malloc(512);
225 - if (!s->pageentry_u8)  
226 - goto fail;  
227 s->pageentry_u32 = s->pageentry_u8; 223 s->pageentry_u32 = s->pageentry_u8;
228 s->pageentry_u16 = s->pageentry_u8; 224 s->pageentry_u16 = s->pageentry_u8;
229 s->last_pagetable = -1; 225 s->last_pagetable = -1;
block-vvfat.c
@@ -159,7 +159,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun @@ -159,7 +159,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun
159 is=array->item_size; 159 is=array->item_size;
160 from=array->pointer+index_from*is; 160 from=array->pointer+index_from*is;
161 to=array->pointer+index_to*is; 161 to=array->pointer+index_to*is;
162 - buf=malloc(is*count); 162 + buf=qemu_malloc(is*count);
163 memcpy(buf,from,is*count); 163 memcpy(buf,from,is*count);
164 164
165 if(index_to<index_from) 165 if(index_to<index_from)
@@ -725,8 +725,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) @@ -725,8 +725,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
725 if(first_cluster == 0 && (is_dotdot || is_dot)) 725 if(first_cluster == 0 && (is_dotdot || is_dot))
726 continue; 726 continue;
727 727
728 - buffer=(char*)malloc(length);  
729 - assert(buffer); 728 + buffer=(char*)qemu_malloc(length);
730 snprintf(buffer,length,"%s/%s",dirname,entry->d_name); 729 snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
731 730
732 if(stat(buffer,&st)<0) { 731 if(stat(buffer,&st)<0) {
@@ -847,8 +846,7 @@ static int init_directories(BDRVVVFATState* s, @@ -847,8 +846,7 @@ static int init_directories(BDRVVVFATState* s,
847 memset(&(s->first_sectors[0]),0,0x40*0x200); 846 memset(&(s->first_sectors[0]),0,0x40*0x200);
848 847
849 s->cluster_size=s->sectors_per_cluster*0x200; 848 s->cluster_size=s->sectors_per_cluster*0x200;
850 - s->cluster_buffer=malloc(s->cluster_size);  
851 - assert(s->cluster_buffer); 849 + s->cluster_buffer=qemu_malloc(s->cluster_size);
852 850
853 /* 851 /*
854 * The formula: sc = spf+1+spf*spc*(512*8/fat_type), 852 * The formula: sc = spf+1+spf*spc*(512*8/fat_type),
@@ -1728,7 +1726,7 @@ static int check_directory_consistency(BDRVVVFATState *s, @@ -1728,7 +1726,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
1728 int cluster_num, const char* path) 1726 int cluster_num, const char* path)
1729 { 1727 {
1730 int ret = 0; 1728 int ret = 0;
1731 - unsigned char* cluster = malloc(s->cluster_size); 1729 + unsigned char* cluster = qemu_malloc(s->cluster_size);
1732 direntry_t* direntries = (direntry_t*)cluster; 1730 direntry_t* direntries = (direntry_t*)cluster;
1733 mapping_t* mapping = find_mapping_for_cluster(s, cluster_num); 1731 mapping_t* mapping = find_mapping_for_cluster(s, cluster_num);
1734 1732
@@ -1869,7 +1867,7 @@ DLOG(checkpoint()); @@ -1869,7 +1867,7 @@ DLOG(checkpoint());
1869 */ 1867 */
1870 if (s->fat2 == NULL) { 1868 if (s->fat2 == NULL) {
1871 int size = 0x200 * s->sectors_per_fat; 1869 int size = 0x200 * s->sectors_per_fat;
1872 - s->fat2 = malloc(size); 1870 + s->fat2 = qemu_malloc(size);
1873 memcpy(s->fat2, s->fat.pointer, size); 1871 memcpy(s->fat2, s->fat.pointer, size);
1874 } 1872 }
1875 check = vvfat_read(s->bs, 1873 check = vvfat_read(s->bs,
@@ -2211,7 +2209,7 @@ static int commit_one_file(BDRVVVFATState* s, @@ -2211,7 +2209,7 @@ static int commit_one_file(BDRVVVFATState* s,
2211 uint32_t first_cluster = c; 2209 uint32_t first_cluster = c;
2212 mapping_t* mapping = find_mapping_for_cluster(s, c); 2210 mapping_t* mapping = find_mapping_for_cluster(s, c);
2213 uint32_t size = filesize_of_direntry(direntry); 2211 uint32_t size = filesize_of_direntry(direntry);
2214 - char* cluster = malloc(s->cluster_size); 2212 + char* cluster = qemu_malloc(s->cluster_size);
2215 uint32_t i; 2213 uint32_t i;
2216 int fd = 0; 2214 int fd = 0;
2217 2215
@@ -2373,7 +2371,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s) @@ -2373,7 +2371,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
2373 mapping_t* m = find_mapping_for_cluster(s, 2371 mapping_t* m = find_mapping_for_cluster(s,
2374 begin_of_direntry(d)); 2372 begin_of_direntry(d));
2375 int l = strlen(m->path); 2373 int l = strlen(m->path);
2376 - char* new_path = malloc(l + diff + 1); 2374 + char* new_path = qemu_malloc(l + diff + 1);
2377 2375
2378 assert(!strncmp(m->path, mapping->path, l2)); 2376 assert(!strncmp(m->path, mapping->path, l2));
2379 2377
@@ -2774,7 +2772,7 @@ static int enable_write_target(BDRVVVFATState *s) @@ -2774,7 +2772,7 @@ static int enable_write_target(BDRVVVFATState *s)
2774 2772
2775 array_init(&(s->commits), sizeof(commit_t)); 2773 array_init(&(s->commits), sizeof(commit_t));
2776 2774
2777 - s->qcow_filename = malloc(1024); 2775 + s->qcow_filename = qemu_malloc(1024);
2778 get_tmp_filename(s->qcow_filename, 1024); 2776 get_tmp_filename(s->qcow_filename, 1024);
2779 if (bdrv_create(&bdrv_qcow, 2777 if (bdrv_create(&bdrv_qcow,
2780 s->qcow_filename, s->sector_count, "fat:", 0) < 0) 2778 s->qcow_filename, s->sector_count, "fat:", 0) < 0)
@@ -151,8 +151,6 @@ BlockDriverState *bdrv_new(const char *device_name) @@ -151,8 +151,6 @@ BlockDriverState *bdrv_new(const char *device_name)
151 BlockDriverState **pbs, *bs; 151 BlockDriverState **pbs, *bs;
152 152
153 bs = qemu_mallocz(sizeof(BlockDriverState)); 153 bs = qemu_mallocz(sizeof(BlockDriverState));
154 - if(!bs)  
155 - return NULL;  
156 pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); 154 pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
157 if (device_name[0] != '\0') { 155 if (device_name[0] != '\0') {
158 /* insert at the end */ 156 /* insert at the end */
@@ -395,8 +393,6 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, @@ -395,8 +393,6 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
395 } 393 }
396 bs->drv = drv; 394 bs->drv = drv;
397 bs->opaque = qemu_mallocz(drv->instance_size); 395 bs->opaque = qemu_mallocz(drv->instance_size);
398 - if (bs->opaque == NULL && drv->instance_size > 0)  
399 - return -1;  
400 /* Note: for compatibility, we open disk image files as RDWR, and 396 /* Note: for compatibility, we open disk image files as RDWR, and
401 RDONLY as fallback */ 397 RDONLY as fallback */
402 if (!(flags & BDRV_O_FILE)) 398 if (!(flags & BDRV_O_FILE))
@@ -1498,8 +1494,6 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb, @@ -1498,8 +1494,6 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
1498 drv->free_aiocb = acb->next; 1494 drv->free_aiocb = acb->next;
1499 } else { 1495 } else {
1500 acb = qemu_mallocz(drv->aiocb_size); 1496 acb = qemu_mallocz(drv->aiocb_size);
1501 - if (!acb)  
1502 - return NULL;  
1503 } 1497 }
1504 acb->bs = bs; 1498 acb->bs = bs;
1505 acb->cb = cb; 1499 acb->cb = cb;