qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling
@ 2009-02-05 11:08 Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure Avi Kivity
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Memory allocation failures are a very rare condition on virtual-memory
hosts.  They are also very difficult to handle correctly (especially in a
hardware emulation context).  Because of this, it is better to gracefully
terminate emulation rather than executing untested or even unwritten recovery
code paths.

This patchset modifies qemu_malloc() and related functions to terminate
on error, and updates callers not to perform their own error handling.  In
many cases error handling was already missing or incorrect.

Avi Kivity (6):
  Terminate emulation on memory allocation failure
  block: remove error handling from qemu_malloc() callers
  audio: remove error handling from qemu_malloc() callers
  hw: remove error handling from qemu_malloc() callers
  targets: remove error handling from qemu_malloc() callers
  toplevel: remove error handling from qemu_malloc() callers

 aio.c                       |    2 -
 audio/audio.c               |   23 +--
 audio/wavcapture.c          |    5 -
 block-bochs.c               |    2 -
 block-cloop.c               |    9 +-
 block-dmg.c                 |    6 +-
 block-parallels.c           |    2 -
 block-qcow2.c               |   58 +------
 block-raw-posix.c           |    2 -
 block-vmdk.c                |   10 -
 block-vpc.c                 |    4 -
 block-vvfat.c               |   18 +-
 block.c                     |    6 -
 buffered_file.c             |    2 -
 console.c                   |   23 ---
 cris-dis.c                  |   26 +--
 curses.c                    |    2 -
 device_tree.c               |    4 -
 exec.c                      |   25 +--
 gdbstub.c                   |    8 -
 hw/adlib.c                  |    7 -
 hw/apic.c                   |    4 -
 hw/arm_gic.c                |    2 -
 hw/arm_sysctl.c             |    2 -
 hw/baum.c                   |   10 -
 hw/cs4231.c                 |    2 -
 hw/cs4231a.c                |    5 -
 hw/ds1225y.c                |    5 -
 hw/eccmemctl.c              |    2 -
 hw/escc.c                   |    4 -
 hw/esp.c                    |    2 -
 hw/etraxfs_dma.c            |    8 -
 hw/etraxfs_eth.c            |    8 -
 hw/etraxfs_pic.c            |    6 -
 hw/etraxfs_ser.c            |    2 -
 hw/etraxfs_timer.c          |    2 -
 hw/fdc.c                    |    6 -
 hw/fmopl.c                  |   27 +---
 hw/fw_cfg.c                 |    8 -
 hw/g364fb.c                 |    2 -
 hw/gus.c                    |   11 -
 hw/i8259.c                  |    2 -
 hw/ide.c                    |    2 -
 hw/integratorcp.c           |    2 -
 hw/iommu.c                  |    2 -
 hw/jazz_led.c               |    2 -
 hw/m48t59.c                 |    6 -
 hw/mac_dbdma.c              |    2 -
 hw/mac_nvram.c              |    6 -
 hw/mc146818rtc.c            |    4 -
 hw/mipsnet.c                |    2 -
 hw/mpcore.c                 |    2 -
 hw/mst_fpga.c               |    2 -
 hw/musicpal.c               |   14 --
 hw/ne2000.c                 |    2 -
 hw/parallel.c               |    4 -
 hw/pci.c                    |    2 -
 hw/pcnet.c                  |    2 -
 hw/pflash_cfi01.c           |    2 -
 hw/pflash_cfi02.c           |    2 -
 hw/pl031.c                  |    2 -
 hw/ppc.c                    |    7 -
 hw/ppc405_boards.c          |   24 +--
 hw/ppc405_uc.c              |  422 ++++++++++++++++++++-----------------------
 hw/ppc440_bamboo.c          |    2 -
 hw/ppc4xx_devs.c            |   72 ++++----
 hw/ppc4xx_pci.c             |    2 -
 hw/ppc_prep.c               |    2 -
 hw/r2d.c                    |    2 -
 hw/rc4030.c                 |    2 -
 hw/sb16.c                   |    5 -
 hw/sbi.c                    |    2 -
 hw/serial.c                 |    4 -
 hw/sh_intc.c                |    4 +-
 hw/sh_serial.c              |    2 -
 hw/slavio_intctl.c          |    4 -
 hw/slavio_misc.c            |    2 -
 hw/slavio_timer.c           |    2 -
 hw/sparc32_dma.c            |    2 -
 hw/sun4c_intctl.c           |    2 -
 hw/tcx.c                    |    2 -
 hw/usb-bt.c                 |    2 -
 hw/usb-hid.c                |    6 -
 hw/usb-hub.c                |    2 -
 hw/usb-msd.c                |    2 -
 hw/usb-net.c                |    2 -
 hw/usb-serial.c             |    2 -
 hw/usb-uhci.c               |   15 +-
 hw/usb-wacom.c              |    2 -
 hw/versatilepb.c            |    2 -
 hw/vga.c                    |    4 -
 hw/virtio-blk.c             |    3 +-
 hw/virtio.c                 |    3 +-
 hw/vmmouse.c                |    2 -
 keymaps.c                   |   10 +-
 kvm-all.c                   |    7 -
 loader.c                    |    4 -
 migration-exec.c            |    5 -
 migration-tcp.c             |    2 -
 monitor.c                   |    4 -
 net.c                       |   14 --
 qemu-char.c                 |   59 ------
 qemu-malloc.c               |   16 +-
 qemu-nbd.c                  |    2 -
 qemu-tool.c                 |    6 +-
 readline.c                  |    2 -
 savevm.c                    |   19 --
 sdl.c                       |    2 -
 target-alpha/translate.c    |    2 -
 target-arm/helper.c         |    4 -
 target-cris/translate.c     |    2 -
 target-i386/helper.c        |    2 -
 target-i386/kvm.c           |    2 -
 target-m68k/helper.c        |    2 -
 target-mips/translate.c     |    2 -
 target-ppc/helper.c         |    2 -
 target-ppc/kvm_ppc.c        |    4 -
 target-ppc/translate_init.c |    2 -
 target-sh4/translate.c      |    2 -
 target-sparc/helper.c       |    2 -
 usb-bsd.c                   |    2 -
 usb-linux.c                 |   24 +---
 vl.c                        |   16 --
 vnc.c                       |    9 +-
 124 files changed, 314 insertions(+), 956 deletions(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 12:01   ` Daniel P. Berrange
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 2/6] block: remove error handling from qemu_malloc() callers Avi Kivity
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Memory allocation failures are a very rare condition on virtual-memory
hosts.  They are also very difficult to handle correctly (especially in a
hardware emulation context).  Because of this, it is better to gracefully
terminate emulation rather than executing untested or even unwritten recovery
code paths.

This patch changes the qemu memory allocation routines to terminate emulation
if an allocation failure is encountered.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 qemu-malloc.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/qemu-malloc.c b/qemu-malloc.c
index dc74efe..1d00f26 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -22,6 +22,14 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
+#include <stdlib.h>
+
+static void *oom_check(void *ptr)
+{
+    if (ptr == NULL)
+        exit(13);
+    return ptr;
+}
 
 void *get_mmap_addr(unsigned long size)
 {
@@ -35,20 +43,18 @@ void qemu_free(void *ptr)
 
 void *qemu_malloc(size_t size)
 {
-    return malloc(size);
+    return oom_check(malloc(size));
 }
 
 void *qemu_realloc(void *ptr, size_t size)
 {
-    return realloc(ptr, size);
+    return oom_check(realloc(ptr, size));
 }
 
 void *qemu_mallocz(size_t size)
 {
     void *ptr;
     ptr = qemu_malloc(size);
-    if (!ptr)
-        return NULL;
     memset(ptr, 0, size);
     return ptr;
 }
@@ -58,8 +64,6 @@ char *qemu_strdup(const char *str)
     char *ptr;
     size_t len = strlen(str);
     ptr = qemu_malloc(len + 1);
-    if (!ptr)
-        return NULL;
     memcpy(ptr, str, len + 1);
     return ptr;
 }
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 2/6] block: remove error handling from qemu_malloc() callers
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 3/6] audio: " Avi Kivity
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 block-bochs.c     |    2 -
 block-cloop.c     |    9 ++-----
 block-dmg.c       |    6 +---
 block-parallels.c |    2 -
 block-qcow2.c     |   58 +----------------------------------------------------
 block-raw-posix.c |    2 -
 block-vmdk.c      |   10 ---------
 block-vpc.c       |    4 ---
 block-vvfat.c     |   18 +++++++---------
 block.c           |    6 -----
 10 files changed, 14 insertions(+), 103 deletions(-)

diff --git a/block-bochs.c b/block-bochs.c
index b167e0b..593cf69 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 ad0e65d..6985084 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 4320c5d..74454c7 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 4654b07..8a8ec63 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 8a5b621..465dcd6 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 ac88fc3..620791b 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 eefd76b..71d7504 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 3eea506..e353e31 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 1ac4472..623ba98 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 b3d2f12..4f4bf7c 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;
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 3/6] audio: remove error handling from qemu_malloc() callers
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 2/6] block: remove error handling from qemu_malloc() callers Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 4/6] hw: " Avi Kivity
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 audio/audio.c      |   23 ++++++++---------------
 audio/wavcapture.c |    5 -----
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index e2635c0..b0a5f3b 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -197,8 +197,8 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
 static char *audio_alloc_prefix (const char *s)
 {
     const char qemu_prefix[] = "QEMU_";
-    size_t len;
-    char *r;
+    size_t len, i;
+    char *r, *u;
 
     if (!s) {
         return NULL;
@@ -207,17 +207,15 @@ static char *audio_alloc_prefix (const char *s)
     len = strlen (s);
     r = qemu_malloc (len + sizeof (qemu_prefix));
 
-    if (r) {
-        size_t i;
-        char *u = r + sizeof (qemu_prefix) - 1;
+    u = r + sizeof (qemu_prefix) - 1;
 
-        pstrcpy (r, len + sizeof (qemu_prefix), qemu_prefix);
-        pstrcat (r, len + sizeof (qemu_prefix), s);
+    pstrcpy (r, len + sizeof (qemu_prefix), qemu_prefix);
+    pstrcat (r, len + sizeof (qemu_prefix), s);
 
-        for (i = 0; i < len; ++i) {
-            u[i] = qemu_toupper(u[i]);
-        }
+    for (i = 0; i < len; ++i) {
+        u[i] = qemu_toupper(u[i]);
     }
+
     return r;
 }
 
@@ -460,11 +458,6 @@ static void audio_process_options (const char *prefix,
          * sizeof) */
         optlen = len + preflen + sizeof (qemu_prefix) + 1;
         optname = qemu_malloc (optlen);
-        if (!optname) {
-            dolog ("Could not allocate memory for option name `%s'\n",
-                   opt->name);
-            continue;
-        }
 
         pstrcpy (optname, optlen, qemu_prefix);
 
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 9919171..6d1c441 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -120,11 +120,6 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
     ops.destroy = wav_destroy;
 
     wav = qemu_mallocz (sizeof (*wav));
-    if (!wav) {
-        term_printf ("Could not allocate memory for wav capture (%zu bytes)",
-                     sizeof (*wav));
-        return -1;
-    }
 
     shift = bits16 + stereo;
     hdr[34] = bits16 ? 0x10 : 0x08;
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 4/6] hw: remove error handling from qemu_malloc() callers
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
                   ` (2 preceding siblings ...)
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 3/6] audio: " Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 5/6] targets: " Avi Kivity
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 hw/adlib.c         |    7 -
 hw/apic.c          |    4 -
 hw/arm_gic.c       |    2 -
 hw/arm_sysctl.c    |    2 -
 hw/baum.c          |   10 --
 hw/cs4231.c        |    2 -
 hw/cs4231a.c       |    5 -
 hw/ds1225y.c       |    5 -
 hw/eccmemctl.c     |    2 -
 hw/escc.c          |    4 -
 hw/esp.c           |    2 -
 hw/etraxfs_dma.c   |    8 -
 hw/etraxfs_eth.c   |    8 -
 hw/etraxfs_pic.c   |    6 -
 hw/etraxfs_ser.c   |    2 -
 hw/etraxfs_timer.c |    2 -
 hw/fdc.c           |    6 -
 hw/fmopl.c         |   27 +---
 hw/fw_cfg.c        |    8 -
 hw/g364fb.c        |    2 -
 hw/gus.c           |   11 --
 hw/i8259.c         |    2 -
 hw/ide.c           |    2 -
 hw/integratorcp.c  |    2 -
 hw/iommu.c         |    2 -
 hw/jazz_led.c      |    2 -
 hw/m48t59.c        |    6 -
 hw/mac_dbdma.c     |    2 -
 hw/mac_nvram.c     |    6 -
 hw/mc146818rtc.c   |    4 -
 hw/mipsnet.c       |    2 -
 hw/mpcore.c        |    2 -
 hw/mst_fpga.c      |    2 -
 hw/musicpal.c      |   14 --
 hw/ne2000.c        |    2 -
 hw/parallel.c      |    4 -
 hw/pci.c           |    2 -
 hw/pcnet.c         |    2 -
 hw/pflash_cfi01.c  |    2 -
 hw/pflash_cfi02.c  |    2 -
 hw/pl031.c         |    2 -
 hw/ppc.c           |    7 -
 hw/ppc405_boards.c |   24 ++--
 hw/ppc405_uc.c     |  422 ++++++++++++++++++++++++---------------------------
 hw/ppc440_bamboo.c |    2 -
 hw/ppc4xx_devs.c   |   72 ++++-----
 hw/ppc4xx_pci.c    |    2 -
 hw/ppc_prep.c      |    2 -
 hw/r2d.c           |    2 -
 hw/rc4030.c        |    2 -
 hw/sb16.c          |    5 -
 hw/sbi.c           |    2 -
 hw/serial.c        |    4 -
 hw/sh_intc.c       |    4 +-
 hw/sh_serial.c     |    2 -
 hw/slavio_intctl.c |    4 -
 hw/slavio_misc.c   |    2 -
 hw/slavio_timer.c  |    2 -
 hw/sparc32_dma.c   |    2 -
 hw/sun4c_intctl.c  |    2 -
 hw/tcx.c           |    2 -
 hw/usb-bt.c        |    2 -
 hw/usb-hid.c       |    6 -
 hw/usb-hub.c       |    2 -
 hw/usb-msd.c       |    2 -
 hw/usb-net.c       |    2 -
 hw/usb-serial.c    |    2 -
 hw/usb-uhci.c      |   15 +-
 hw/usb-wacom.c     |    2 -
 hw/versatilepb.c   |    2 -
 hw/vga.c           |    4 -
 hw/virtio-blk.c    |    3 +-
 hw/virtio.c        |    3 +-
 hw/vmmouse.c       |    2 -
 74 files changed, 257 insertions(+), 545 deletions(-)

diff --git a/hw/adlib.c b/hw/adlib.c
index 3c14360..9f8f6f2 100644
--- a/hw/adlib.c
+++ b/hw/adlib.c
@@ -331,13 +331,6 @@ int Adlib_init (AudioState *audio, qemu_irq *pic)
     s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT;
     s->mixbuf = qemu_mallocz (s->samples << SHIFT);
 
-    if (!s->mixbuf) {
-        dolog ("Could not allocate mixing buffer, %d samples (each %d bytes)\n",
-               s->samples, 1 << SHIFT);
-        Adlib_fini (s);
-        return -1;
-    }
-
     register_ioport_read (0x388, 4, 1, adlib_read, s);
     register_ioport_write (0x388, 4, 1, adlib_write, s);
 
diff --git a/hw/apic.c b/hw/apic.c
index 3052843..5a7654d 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -898,8 +898,6 @@ int apic_init(CPUState *env)
     if (last_apic_id >= MAX_APICS)
         return -1;
     s = qemu_mallocz(sizeof(APICState));
-    if (!s)
-        return -1;
     env->apic_state = s;
     s->id = last_apic_id++;
     env->cpuid_apic_id = s->id;
@@ -1124,8 +1122,6 @@ IOAPICState *ioapic_init(void)
     int io_memory;
 
     s = qemu_mallocz(sizeof(IOAPICState));
-    if (!s)
-        return NULL;
     ioapic_reset(s);
     s->id = last_apic_id++;
 
diff --git a/hw/arm_gic.c b/hw/arm_gic.c
index f36f147..fef3113 100644
--- a/hw/arm_gic.c
+++ b/hw/arm_gic.c
@@ -725,8 +725,6 @@ static gic_state *gic_init(uint32_t dist_base, qemu_irq *parent_irq)
     int i;
 
     s = (gic_state *)qemu_mallocz(sizeof(gic_state));
-    if (!s)
-        return NULL;
     s->in = qemu_allocate_irqs(gic_set_irq, s, GIC_NIRQ);
     for (i = 0; i < NCPU; i++) {
         s->parent_irq[i] = parent_irq[i];
diff --git a/hw/arm_sysctl.c b/hw/arm_sysctl.c
index ca668ca..62222a1 100644
--- a/hw/arm_sysctl.c
+++ b/hw/arm_sysctl.c
@@ -194,8 +194,6 @@ void arm_sysctl_init(uint32_t base, uint32_t sys_id)
     int iomemtype;
 
     s = (arm_sysctl_state *)qemu_mallocz(sizeof(arm_sysctl_state));
-    if (!s)
-        return;
     s->sys_id = sys_id;
     /* The MPcore bootloader uses these flags to start secondary CPUs.
        We don't use a bootloader, so do this here.  */
diff --git a/hw/baum.c b/hw/baum.c
index 925ad2a..565484e 100644
--- a/hw/baum.c
+++ b/hw/baum.c
@@ -575,12 +575,7 @@ CharDriverState *chr_baum_init(void)
     int tty;
 
     baum = qemu_mallocz(sizeof(BaumDriverState));
-    if (!baum)
-        return NULL;
-
     baum->chr = chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        goto fail_baum;
 
     chr->opaque = baum;
     chr->chr_write = baum_write;
@@ -588,8 +583,6 @@ CharDriverState *chr_baum_init(void)
     chr->chr_accept_input = baum_accept_input;
 
     handle = qemu_mallocz(brlapi_getHandleSize());
-    if (!handle)
-        goto fail_chr;
     baum->brlapi = handle;
 
     baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL);
@@ -628,11 +621,8 @@ CharDriverState *chr_baum_init(void)
 fail:
     qemu_free_timer(baum->cellCount_timer);
     brlapi__closeConnection(handle);
-fail_handle:
     free(handle);
-fail_chr:
     free(chr);
-fail_baum:
     free(baum);
     return NULL;
 }
diff --git a/hw/cs4231.c b/hw/cs4231.c
index d53f194..59d83e0 100644
--- a/hw/cs4231.c
+++ b/hw/cs4231.c
@@ -171,8 +171,6 @@ void cs_init(target_phys_addr_t base, int irq, void *intctl)
     CSState *s;
 
     s = qemu_mallocz(sizeof(CSState));
-    if (!s)
-        return;
 
     cs_io_memory = cpu_register_io_memory(0, cs_mem_read, cs_mem_write, s);
     cpu_register_physical_memory(base, CS_SIZE, cs_io_memory);
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 6d04d36..25ad409 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -647,11 +647,6 @@ int cs4231a_init (AudioState *audio, qemu_irq *pic)
     }
 
     s = qemu_mallocz (sizeof (*s));
-    if (!s) {
-        lerr ("Could not allocate memory for cs4231a (%zu bytes)\n",
-               sizeof (*s));
-        return -1;
-    }
 
     s->pic = pic;
     s->irq = conf.irq;
diff --git a/hw/ds1225y.c b/hw/ds1225y.c
index 64c21b7..458a7d5 100644
--- a/hw/ds1225y.c
+++ b/hw/ds1225y.c
@@ -152,13 +152,8 @@ void *ds1225y_init(target_phys_addr_t mem_base, const char *filename)
     QEMUFile *file;
 
     s = qemu_mallocz(sizeof(ds1225y_t));
-    if (!s)
-        return NULL;
     s->chip_size = 0x2000; /* Fixed for ds1225y chip: 8 KiB */
     s->contents = qemu_mallocz(s->chip_size);
-    if (!s->contents) {
-        return NULL;
-    }
     s->protection = 7;
 
     /* Read current file */
diff --git a/hw/eccmemctl.c b/hw/eccmemctl.c
index 434f49e..28519c8 100644
--- a/hw/eccmemctl.c
+++ b/hw/eccmemctl.c
@@ -320,8 +320,6 @@ void * ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
     ECCState *s;
 
     s = qemu_mallocz(sizeof(ECCState));
-    if (!s)
-        return NULL;
 
     s->version = version;
     s->regs[0] = version;
diff --git a/hw/escc.c b/hw/escc.c
index 372ad5a..4c299ff 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -727,8 +727,6 @@ int escc_init(target_phys_addr_t base, qemu_irq irqA, qemu_irq irqB,
     SerialState *s;
 
     s = qemu_mallocz(sizeof(SerialState));
-    if (!s)
-        return 0;
 
     escc_io_memory = cpu_register_io_memory(0, escc_mem_read,
                                             escc_mem_write,
@@ -909,8 +907,6 @@ void slavio_serial_ms_kbd_init(target_phys_addr_t base, qemu_irq irq,
     SerialState *s;
 
     s = qemu_mallocz(sizeof(SerialState));
-    if (!s)
-        return;
 
     s->it_shift = it_shift;
     for (i = 0; i < 2; i++) {
diff --git a/hw/esp.c b/hw/esp.c
index c3dbae0..aa1a76e 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -653,8 +653,6 @@ void *esp_init(target_phys_addr_t espaddr, int it_shift,
     int esp_io_memory;
 
     s = qemu_mallocz(sizeof(ESPState));
-    if (!s)
-        return NULL;
 
     s->irq = irq;
     s->it_shift = it_shift;
diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c
index 513b5b8..4723637 100644
--- a/hw/etraxfs_dma.c
+++ b/hw/etraxfs_dma.c
@@ -756,22 +756,14 @@ void *etraxfs_dmac_init(CPUState *env,
 	struct fs_dma_ctrl *ctrl = NULL;
 
 	ctrl = qemu_mallocz(sizeof *ctrl);
-	if (!ctrl)
-		return NULL;
 
         ctrl->bh = qemu_bh_new(DMA_run, ctrl);
 
 	ctrl->env = env;
 	ctrl->nr_channels = nr_channels;
 	ctrl->channels = qemu_mallocz(sizeof ctrl->channels[0] * nr_channels);
-	if (!ctrl->channels)
-		goto err;
 
 	ctrl->map = cpu_register_io_memory(0, dma_read, dma_write, ctrl);
 	cpu_register_physical_memory(base, nr_channels * 0x2000, ctrl->map);
 	return ctrl;
-  err:
-	qemu_free(ctrl->channels);
-	qemu_free(ctrl);
-	return NULL;
 }
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index cce8917..13d1900 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -564,12 +564,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	qemu_check_nic_model(nd, "fseth");
 
 	dma = qemu_mallocz(sizeof *dma * 2);
-	if (!dma)
-		return NULL;
 
 	eth = qemu_mallocz(sizeof *eth);
-	if (!eth)
-		goto err;
 
 	dma[0].client.push = eth_tx_push;
 	dma[0].client.opaque = eth;
@@ -595,8 +591,4 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	eth->vc->link_status_changed = eth_set_link;
 
 	return dma;
-  err:
-	qemu_free(eth);
-	qemu_free(dma);
-	return NULL;
 }
diff --git a/hw/etraxfs_pic.c b/hw/etraxfs_pic.c
index 6d4e55a..7aa0568 100644
--- a/hw/etraxfs_pic.c
+++ b/hw/etraxfs_pic.c
@@ -192,8 +192,6 @@ struct etraxfs_pic *etraxfs_pic_init(CPUState *env, target_phys_addr_t base)
 
 	pic = qemu_mallocz(sizeof *pic);
 	pic->internal = fs = qemu_mallocz(sizeof *fs);
-	if (!fs || !pic)
-		goto err;
 
 	fs->env = env;
 	pic->irq = qemu_allocate_irqs(irq_handler, fs, 30);
@@ -204,8 +202,4 @@ struct etraxfs_pic *etraxfs_pic_init(CPUState *env, target_phys_addr_t base)
 	cpu_register_physical_memory(base, 0x14, intr_vect_regs);
 
 	return pic;
-  err:
-	free(pic);
-	free(fs);
-	return NULL;
 }
diff --git a/hw/etraxfs_ser.c b/hw/etraxfs_ser.c
index 4b9545f..e32e2eb 100644
--- a/hw/etraxfs_ser.c
+++ b/hw/etraxfs_ser.c
@@ -233,8 +233,6 @@ void etraxfs_ser_init(CPUState *env, qemu_irq *irq, CharDriverState *chr,
 	int ser_regs;
 
 	s = qemu_mallocz(sizeof *s);
-	if (!s)
-		return;
 
 	s->env = env;
 	s->irq = irq;
diff --git a/hw/etraxfs_timer.c b/hw/etraxfs_timer.c
index 04bdede..ebb06e1 100644
--- a/hw/etraxfs_timer.c
+++ b/hw/etraxfs_timer.c
@@ -321,8 +321,6 @@ void etraxfs_timer_init(CPUState *env, qemu_irq *irqs, qemu_irq *nmi,
 	int timer_regs;
 
 	t = qemu_mallocz(sizeof *t);
-	if (!t)
-		return;
 
 	t->bh_t0 = qemu_bh_new(timer0_hit, t);
 	t->bh_t1 = qemu_bh_new(timer1_hit, t);
diff --git a/hw/fdc.c b/hw/fdc.c
index 5913be7..b00a4ec 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1866,13 +1866,7 @@ static fdctrl_t *fdctrl_init_common (qemu_irq irq, int dma_chann,
 
     FLOPPY_DPRINTF("init controller\n");
     fdctrl = qemu_mallocz(sizeof(fdctrl_t));
-    if (!fdctrl)
-        return NULL;
     fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
-    if (fdctrl->fifo == NULL) {
-        qemu_free(fdctrl);
-        return NULL;
-    }
     fdctrl->result_timer = qemu_new_timer(vm_clock,
                                           fdctrl_result_timer, fdctrl);
 
diff --git a/hw/fmopl.c b/hw/fmopl.c
index 52cf35e..b45b9c8 100644
--- a/hw/fmopl.c
+++ b/hw/fmopl.c
@@ -619,26 +619,10 @@ static int OPLOpenTable( void )
 	double pom;
 
 	/* allocate dynamic tables */
-	if( (TL_TABLE = malloc(TL_MAX*2*sizeof(INT32))) == NULL)
-		return 0;
-	if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL)
-	{
-		free(TL_TABLE);
-		return 0;
-	}
-	if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(INT32))) == NULL)
-	{
-		free(TL_TABLE);
-		free(SIN_TABLE);
-		return 0;
-	}
-	if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(INT32))) == NULL)
-	{
-		free(TL_TABLE);
-		free(SIN_TABLE);
-		free(AMS_TABLE);
-		return 0;
-	}
+	TL_TABLE = qemu_malloc(TL_MAX*2*sizeof(INT32));
+	SIN_TABLE = qemu_malloc(SIN_ENT*4 *sizeof(INT32 *));
+	AMS_TABLE = qemu_malloc(AMS_ENT*2 *sizeof(INT32));
+	VIB_TABLE = qemu_malloc(VIB_ENT*2 *sizeof(INT32));
 	/* make total level table */
 	for (t = 0;t < EG_ENT-1 ;t++){
 		rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20);	/* dB -> voltage */
@@ -1221,8 +1205,7 @@ FM_OPL *OPLCreate(int type, int clock, int rate)
 	if(type&OPL_TYPE_ADPCM) state_size+= sizeof(YM_DELTAT);
 #endif
 	/* allocate memory block */
-	ptr = malloc(state_size);
-	if(ptr==NULL) return NULL;
+	ptr = qemu_malloc(state_size);
 	/* clear */
 	memset(ptr,0,state_size);
 	OPL        = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 4333ed9..e324e8d 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -206,8 +206,6 @@ int fw_cfg_add_i16(void *opaque, uint16_t key, uint16_t value)
     uint16_t *copy;
 
     copy = qemu_malloc(sizeof(value));
-    if (!copy)
-        return 0;
     *copy = cpu_to_le16(value);
     return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
 }
@@ -217,8 +215,6 @@ int fw_cfg_add_i32(void *opaque, uint16_t key, uint32_t value)
     uint32_t *copy;
 
     copy = qemu_malloc(sizeof(value));
-    if (!copy)
-        return 0;
     *copy = cpu_to_le32(value);
     return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
 }
@@ -228,8 +224,6 @@ int fw_cfg_add_i64(void *opaque, uint16_t key, uint64_t value)
     uint64_t *copy;
 
     copy = qemu_malloc(sizeof(value));
-    if (!copy)
-        return 0;
     *copy = cpu_to_le64(value);
     return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
 }
@@ -263,8 +257,6 @@ void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     int io_ctl_memory, io_data_memory;
 
     s = qemu_mallocz(sizeof(FWCfgState));
-    if (!s)
-        return NULL;
 
     if (ctl_port) {
         register_ioport_write(ctl_port, 2, 2, fw_cfg_io_writew, s);
diff --git a/hw/g364fb.c b/hw/g364fb.c
index fc76b4a..8bfd134 100644
--- a/hw/g364fb.c
+++ b/hw/g364fb.c
@@ -593,8 +593,6 @@ int g364fb_mm_init(uint8_t *vram, ram_addr_t vram_offset,
     int io_ctrl;
 
     s = qemu_mallocz(sizeof(G364State));
-    if (!s)
-        return -1;
 
     s->vram = vram;
     s->vram_offset = vram_offset;
diff --git a/hw/gus.c b/hw/gus.c
index 860a47c..070aa99 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -261,11 +261,6 @@ int GUS_init (AudioState *audio, qemu_irq *pic)
     }
 
     s = qemu_mallocz (sizeof (*s));
-    if (!s) {
-        dolog ("Could not allocate memory for GUS (%zu bytes)\n",
-               sizeof (*s));
-        return -1;
-    }
 
     AUD_register_card (audio, "gus", &s->card);
 
@@ -292,12 +287,6 @@ int GUS_init (AudioState *audio, qemu_irq *pic)
     s->shift = 2;
     s->samples = AUD_get_buffer_size_out (s->voice) >> s->shift;
     s->mixbuf = qemu_mallocz (s->samples << s->shift);
-    if (!s->mixbuf) {
-        AUD_close_out (&s->card, s->voice);
-        AUD_remove_card (&s->card);
-        qemu_free (s);
-        return -1;
-    }
 
     register_ioport_write (conf.port, 1, 1, gus_writeb, s);
     register_ioport_write (conf.port, 1, 2, gus_writew, s);
diff --git a/hw/i8259.c b/hw/i8259.c
index 750a76c..933289b 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -550,8 +550,6 @@ qemu_irq *i8259_init(qemu_irq parent_irq)
     PicState2 *s;
 
     s = qemu_mallocz(sizeof(PicState2));
-    if (!s)
-        return NULL;
     pic_init1(0x20, 0x4d0, &s->pics[0]);
     pic_init1(0xa0, 0x4d1, &s->pics[1]);
     s->pics[0].elcr_mask = 0xf8;
diff --git a/hw/ide.c b/hw/ide.c
index bcaee46..03765cd 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -2951,8 +2951,6 @@ void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
     IDEState *ide_state;
 
     ide_state = qemu_mallocz(sizeof(IDEState) * 2);
-    if (!ide_state)
-        return;
 
     ide_init2(ide_state, hd0, hd1, irq);
     ide_init_ioport(ide_state, iobase, iobase2);
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index 4c5623a..f990afe 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -378,8 +378,6 @@ static qemu_irq *icp_pic_init(uint32_t base,
     qemu_irq *qi;
 
     s = (icp_pic_state *)qemu_mallocz(sizeof(icp_pic_state));
-    if (!s)
-        return NULL;
     qi = qemu_allocate_irqs(icp_pic_set_irq, s, 32);
     s->parent_irq = parent_irq;
     s->parent_fiq = parent_fiq;
diff --git a/hw/iommu.c b/hw/iommu.c
index 82a4932..cde5f1f 100644
--- a/hw/iommu.c
+++ b/hw/iommu.c
@@ -371,8 +371,6 @@ void *iommu_init(target_phys_addr_t addr, uint32_t version, qemu_irq irq)
     int iommu_io_memory;
 
     s = qemu_mallocz(sizeof(IOMMUState));
-    if (!s)
-        return NULL;
 
     s->version = version;
     s->irq = irq;
diff --git a/hw/jazz_led.c b/hw/jazz_led.c
index fdef9d8..8e20369 100644
--- a/hw/jazz_led.c
+++ b/hw/jazz_led.c
@@ -304,8 +304,6 @@ void jazz_led_init(target_phys_addr_t base)
     int io;
 
     s = qemu_mallocz(sizeof(LedState));
-    if (!s)
-        return;
 
     s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
 
diff --git a/hw/m48t59.c b/hw/m48t59.c
index c4107dd..0cfdab3 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -622,13 +622,7 @@ m48t59_t *m48t59_init (qemu_irq IRQ, target_phys_addr_t mem_base,
     target_phys_addr_t save_base;
 
     s = qemu_mallocz(sizeof(m48t59_t));
-    if (!s)
-	return NULL;
     s->buffer = qemu_mallocz(size);
-    if (!s->buffer) {
-        qemu_free(s);
-        return NULL;
-    }
     s->IRQ = IRQ;
     s->size = size;
     s->io_base = io_base;
diff --git a/hw/mac_dbdma.c b/hw/mac_dbdma.c
index a6ef479..f52868e 100644
--- a/hw/mac_dbdma.c
+++ b/hw/mac_dbdma.c
@@ -865,8 +865,6 @@ void* DBDMA_init (int *dbdma_mem_index)
     DBDMA_channel *s;
 
     s = qemu_mallocz(sizeof(DBDMA_channel) * DBDMA_CHANNELS);
-    if (!s)
-        return NULL;
 
     *dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, s);
     register_savevm("dbdma", -1, 1, dbdma_save, dbdma_load, s);
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 2c90061..3d3e557 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -132,13 +132,7 @@ MacIONVRAMState *macio_nvram_init (int *mem_index, target_phys_addr_t size)
     MacIONVRAMState *s;
 
     s = qemu_mallocz(sizeof(MacIONVRAMState));
-    if (!s)
-        return NULL;
     s->data = qemu_mallocz(size);
-    if (!s->data) {
-        qemu_free(s);
-	return NULL;
-    }
     s->size = size;
 
     s->mem_index = cpu_register_io_memory(0, nvram_read, nvram_write, s);
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 74d9e1f..5b08d72 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -532,8 +532,6 @@ RTCState *rtc_init(int base, qemu_irq irq, int base_year)
     RTCState *s;
 
     s = qemu_mallocz(sizeof(RTCState));
-    if (!s)
-        return NULL;
 
     s->irq = irq;
     s->cmos_data[RTC_REG_A] = 0x26;
@@ -644,8 +642,6 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     int io_memory;
 
     s = qemu_mallocz(sizeof(RTCState));
-    if (!s)
-        return NULL;
 
     s->irq = irq;
     s->cmos_data[RTC_REG_A] = 0x26;
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 04ce322..29bd9b8 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -239,8 +239,6 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
     qemu_check_nic_model(nd, "mipsnet");
 
     s = qemu_mallocz(sizeof(MIPSnetState));
-    if (!s)
-        return;
 
     register_ioport_write(base, 36, 1, mipsnet_ioport_write, s);
     register_ioport_read(base, 36, 1, mipsnet_ioport_read, s);
diff --git a/hw/mpcore.c b/hw/mpcore.c
index 914087a..1d5fcc7 100644
--- a/hw/mpcore.c
+++ b/hw/mpcore.c
@@ -265,8 +265,6 @@ static qemu_irq *mpcore_priv_init(uint32_t base, qemu_irq *pic_irq)
     int i;
 
     s = (mpcore_priv_state *)qemu_mallocz(sizeof(mpcore_priv_state));
-    if (!s)
-        return NULL;
     s->gic = gic_init(base + 0x1000, pic_irq);
     if (!s->gic)
         return NULL;
diff --git a/hw/mst_fpga.c b/hw/mst_fpga.c
index 9327952..c7bda34 100644
--- a/hw/mst_fpga.c
+++ b/hw/mst_fpga.c
@@ -225,8 +225,6 @@ qemu_irq *mst_irq_init(struct pxa2xx_state_s *cpu, uint32_t base, int irq)
 	s = (mst_irq_state  *)
 		qemu_mallocz(sizeof(mst_irq_state));
 
-	if (!s)
-		return NULL;
 	s->parent = &cpu->pic[irq];
 
 	/* alloc the external 16 irqs */
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 09eafb0..75c8887 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -443,13 +443,9 @@ static i2c_interface *musicpal_audio_init(uint32_t base, qemu_irq irq)
     }
 
     s = qemu_mallocz(sizeof(musicpal_audio_state));
-    if (!s)
-        return NULL;
     s->irq = irq;
 
     i2c = qemu_mallocz(sizeof(i2c_interface));
-    if (!i2c)
-        return NULL;
     i2c->bus = i2c_init_bus();
     i2c->current_addr = -1;
 
@@ -717,8 +713,6 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     qemu_check_nic_model(nd, "mv88w8618");
 
     s = qemu_mallocz(sizeof(mv88w8618_eth_state));
-    if (!s)
-        return;
     s->irq = irq;
     s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
                                  eth_receive, eth_can_receive, s);
@@ -911,8 +905,6 @@ static void musicpal_lcd_init(uint32_t base)
     int iomemtype;
 
     s = qemu_mallocz(sizeof(musicpal_lcd_state));
-    if (!s)
-        return;
     iomemtype = cpu_register_io_memory(0, musicpal_lcd_readfn,
                                        musicpal_lcd_writefn, s);
     cpu_register_physical_memory(base, MP_LCD_SIZE, iomemtype);
@@ -1008,8 +1000,6 @@ static qemu_irq *mv88w8618_pic_init(uint32_t base, qemu_irq parent_irq)
     qemu_irq *qi;
 
     s = qemu_mallocz(sizeof(mv88w8618_pic_state));
-    if (!s)
-        return NULL;
     qi = qemu_allocate_irqs(mv88w8618_pic_set_irq, s, 32);
     s->parent_irq = parent_irq;
     iomemtype = cpu_register_io_memory(0, mv88w8618_pic_readfn,
@@ -1134,8 +1124,6 @@ static void mv88w8618_pit_init(uint32_t base, qemu_irq *pic, int irq)
     mv88w8618_pit_state *s;
 
     s = qemu_mallocz(sizeof(mv88w8618_pit_state));
-    if (!s)
-        return;
 
     /* Letting them all run at 1 MHz is likely just a pragmatic
      * simplification. */
@@ -1200,8 +1188,6 @@ static void mv88w8618_flashcfg_init(uint32_t base)
     mv88w8618_flashcfg_state *s;
 
     s = qemu_mallocz(sizeof(mv88w8618_flashcfg_state));
-    if (!s)
-        return;
 
     s->cfgr0 = 0xfffe4285; /* Default as set by U-Boot for 8 MB flash */
     iomemtype = cpu_register_io_memory(0, mv88w8618_flashcfg_readfn,
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 1bad3fd..bd7ac10 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -725,8 +725,6 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
     qemu_check_nic_model(nd, "ne2k_isa");
 
     s = qemu_mallocz(sizeof(NE2000State));
-    if (!s)
-        return;
 
     register_ioport_write(base, 16, 1, ne2000_ioport_write, s);
     register_ioport_read(base, 16, 1, ne2000_ioport_read, s);
diff --git a/hw/parallel.c b/hw/parallel.c
index c734bdb..0abd0a2 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -445,8 +445,6 @@ ParallelState *parallel_init(int base, qemu_irq irq, CharDriverState *chr)
     uint8_t dummy;
 
     s = qemu_mallocz(sizeof(ParallelState));
-    if (!s)
-        return NULL;
     s->irq = irq;
     s->chr = chr;
     parallel_reset(s);
@@ -539,8 +537,6 @@ ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq
     int io_sw;
 
     s = qemu_mallocz(sizeof(ParallelState));
-    if (!s)
-        return NULL;
     s->irq = irq;
     s->chr = chr;
     s->it_shift = it_shift;
diff --git a/hw/pci.c b/hw/pci.c
index c778948..0e57d21 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -178,8 +178,6 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
     found: ;
     }
     pci_dev = qemu_mallocz(instance_size);
-    if (!pci_dev)
-        return NULL;
     pci_dev->bus = bus;
     pci_dev->devfn = devfn;
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 828d980..5642099 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -2089,8 +2089,6 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,
     qemu_check_nic_model(nd, "lance");
 
     d = qemu_mallocz(sizeof(PCNetState));
-    if (!d)
-        return;
 
     lance_io_memory =
         cpu_register_io_memory(0, lance_mem_read, lance_mem_write, d);
diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c
index 23e695c..e41cf69 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -519,8 +519,6 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base, ram_addr_t off,
 
     pfl = qemu_mallocz(sizeof(pflash_t));
 
-    if (pfl == NULL)
-        return NULL;
     pfl->storage = phys_ram_base + off;
     pfl->fl_mem = cpu_register_io_memory(0,
                     pflash_read_ops, pflash_write_ops, pfl);
diff --git a/hw/pflash_cfi02.c b/hw/pflash_cfi02.c
index 05fb47f..1f58211 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/pflash_cfi02.c
@@ -557,8 +557,6 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off,
         return NULL;
 #endif
     pfl = qemu_mallocz(sizeof(pflash_t));
-    if (pfl == NULL)
-        return NULL;
     pfl->storage = phys_ram_base + off;
     pfl->fl_mem = cpu_register_io_memory(0, pflash_read_ops, pflash_write_ops,
                                          pfl);
diff --git a/hw/pl031.c b/hw/pl031.c
index 75bda7c..8c62995 100644
--- a/hw/pl031.c
+++ b/hw/pl031.c
@@ -193,8 +193,6 @@ void pl031_init(uint32_t base, qemu_irq irq)
     struct tm tm;
 
     s = qemu_mallocz(sizeof(pl031_state));
-    if (!s)
-        cpu_abort(cpu_single_env, "pl031_init: Out of memory\n");
 
     iomemtype = cpu_register_io_memory(0, pl031_readfn, pl031_writefn, s);
     if (iomemtype == -1)
diff --git a/hw/ppc.c b/hw/ppc.c
index 05e787f..9a01c01 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -645,8 +645,6 @@ clk_setup_cb cpu_ppc_tb_init (CPUState *env, uint32_t freq)
     ppc_tb_t *tb_env;
 
     tb_env = qemu_mallocz(sizeof(ppc_tb_t));
-    if (tb_env == NULL)
-        return NULL;
     env->tb_env = tb_env;
     /* Create new timer */
     tb_env->decr_timer = qemu_new_timer(vm_clock, &cpu_ppc_decr_cb, env);
@@ -915,9 +913,6 @@ clk_setup_cb ppc_emb_timers_init (CPUState *env, uint32_t freq)
     ppcemb_timer_t *ppcemb_timer;
 
     tb_env = qemu_mallocz(sizeof(ppc_tb_t));
-    if (tb_env == NULL) {
-        return NULL;
-    }
     env->tb_env = tb_env;
     ppcemb_timer = qemu_mallocz(sizeof(ppcemb_timer_t));
     tb_env->tb_freq = freq;
@@ -1024,8 +1019,6 @@ int ppc_dcr_init (CPUState *env, int (*read_error)(int dcrn),
     ppc_dcr_t *dcr_env;
 
     dcr_env = qemu_mallocz(sizeof(ppc_dcr_t));
-    if (dcr_env == NULL)
-        return -1;
     dcr_env->read_error = read_error;
     dcr_env->write_error = write_error;
     env->dcr_env = dcr_env;
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 49dd10f..945f095 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -162,13 +162,11 @@ static void ref405ep_fpga_init (uint32_t base)
     int fpga_memory;
 
     fpga = qemu_mallocz(sizeof(ref405ep_fpga_t));
-    if (fpga != NULL) {
-        fpga_memory = cpu_register_io_memory(0, ref405ep_fpga_read,
-                                             ref405ep_fpga_write, fpga);
-        cpu_register_physical_memory(base, 0x00000100, fpga_memory);
-        ref405ep_fpga_reset(fpga);
-        qemu_register_reset(&ref405ep_fpga_reset, fpga);
-    }
+    fpga_memory = cpu_register_io_memory(0, ref405ep_fpga_read,
+                                         ref405ep_fpga_write, fpga);
+    cpu_register_physical_memory(base, 0x00000100, fpga_memory);
+    ref405ep_fpga_reset(fpga);
+    qemu_register_reset(&ref405ep_fpga_reset, fpga);
 }
 
 static void ref405ep_init (ram_addr_t ram_size, int vga_ram_size,
@@ -486,13 +484,11 @@ static void taihu_cpld_init (uint32_t base)
     int cpld_memory;
 
     cpld = qemu_mallocz(sizeof(taihu_cpld_t));
-    if (cpld != NULL) {
-        cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
-                                             taihu_cpld_write, cpld);
-        cpu_register_physical_memory(base, 0x00000100, cpld_memory);
-        taihu_cpld_reset(cpld);
-        qemu_register_reset(&taihu_cpld_reset, cpld);
-    }
+    cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
+                                         taihu_cpld_write, cpld);
+    cpu_register_physical_memory(base, 0x00000100, cpld_memory);
+    taihu_cpld_reset(cpld);
+    qemu_register_reset(&taihu_cpld_reset, cpld);
 }
 
 static void taihu_405ep_init(ram_addr_t ram_size, int vga_ram_size,
diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
index 9275416..79a951e 100644
--- a/hw/ppc405_uc.c
+++ b/hw/ppc405_uc.c
@@ -169,13 +169,11 @@ void ppc4xx_plb_init (CPUState *env)
     ppc4xx_plb_t *plb;
 
     plb = qemu_mallocz(sizeof(ppc4xx_plb_t));
-    if (plb != NULL) {
-        ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
-        ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb);
-        ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb);
-        ppc4xx_plb_reset(plb);
-        qemu_register_reset(ppc4xx_plb_reset, plb);
-    }
+    ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
+    ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb);
+    ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb);
+    ppc4xx_plb_reset(plb);
+    qemu_register_reset(ppc4xx_plb_reset, plb);
 }
 
 /*****************************************************************************/
@@ -248,13 +246,11 @@ void ppc4xx_pob_init (CPUState *env)
     ppc4xx_pob_t *pob;
 
     pob = qemu_mallocz(sizeof(ppc4xx_pob_t));
-    if (pob != NULL) {
-        ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
-        ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
-        ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
-        qemu_register_reset(ppc4xx_pob_reset, pob);
-        ppc4xx_pob_reset(env);
-    }
+    ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
+    ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
+    ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
+    qemu_register_reset(ppc4xx_pob_reset, pob);
+    ppc4xx_pob_reset(env);
 }
 
 /*****************************************************************************/
@@ -384,16 +380,14 @@ void ppc4xx_opba_init (CPUState *env, ppc4xx_mmio_t *mmio,
     ppc4xx_opba_t *opba;
 
     opba = qemu_mallocz(sizeof(ppc4xx_opba_t));
-    if (opba != NULL) {
-        opba->base = offset;
+    opba->base = offset;
 #ifdef DEBUG_OPBA
-        printf("%s: offset " PADDRX "\n", __func__, offset);
+    printf("%s: offset " PADDRX "\n", __func__, offset);
 #endif
-        ppc4xx_mmio_register(env, mmio, offset, 0x002,
-                             opba_read, opba_write, opba);
-        qemu_register_reset(ppc4xx_opba_reset, opba);
-        ppc4xx_opba_reset(opba);
-    }
+    ppc4xx_mmio_register(env, mmio, offset, 0x002,
+                         opba_read, opba_write, opba);
+    qemu_register_reset(ppc4xx_opba_reset, opba);
+    ppc4xx_opba_reset(opba);
 }
 
 /*****************************************************************************/
@@ -585,14 +579,12 @@ void ppc405_ebc_init (CPUState *env)
     ppc4xx_ebc_t *ebc;
 
     ebc = qemu_mallocz(sizeof(ppc4xx_ebc_t));
-    if (ebc != NULL) {
-        ebc_reset(ebc);
-        qemu_register_reset(&ebc_reset, ebc);
-        ppc_dcr_register(env, EBC0_CFGADDR,
-                         ebc, &dcr_read_ebc, &dcr_write_ebc);
-        ppc_dcr_register(env, EBC0_CFGDATA,
-                         ebc, &dcr_read_ebc, &dcr_write_ebc);
-    }
+    ebc_reset(ebc);
+    qemu_register_reset(&ebc_reset, ebc);
+    ppc_dcr_register(env, EBC0_CFGADDR,
+                     ebc, &dcr_read_ebc, &dcr_write_ebc);
+    ppc_dcr_register(env, EBC0_CFGDATA,
+                     ebc, &dcr_read_ebc, &dcr_write_ebc);
 }
 
 /*****************************************************************************/
@@ -678,59 +670,57 @@ void ppc405_dma_init (CPUState *env, qemu_irq irqs[4])
     ppc405_dma_t *dma;
 
     dma = qemu_mallocz(sizeof(ppc405_dma_t));
-    if (dma != NULL) {
-        memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
-        ppc405_dma_reset(dma);
-        qemu_register_reset(&ppc405_dma_reset, dma);
-        ppc_dcr_register(env, DMA0_CR0,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CT0,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_DA0,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SA0,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SG0,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CR1,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CT1,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_DA1,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SA1,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SG1,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CR2,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CT2,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_DA2,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SA2,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SG2,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CR3,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_CT3,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_DA3,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SA3,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SG3,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SR,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SGC,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_SLP,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-        ppc_dcr_register(env, DMA0_POL,
-                         dma, &dcr_read_dma, &dcr_write_dma);
-    }
+    memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
+    ppc405_dma_reset(dma);
+    qemu_register_reset(&ppc405_dma_reset, dma);
+    ppc_dcr_register(env, DMA0_CR0,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CT0,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_DA0,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SA0,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SG0,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CR1,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CT1,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_DA1,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SA1,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SG1,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CR2,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CT2,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_DA2,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SA2,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SG2,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CR3,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_CT3,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_DA3,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SA3,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SG3,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SR,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SGC,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_SLP,
+                     dma, &dcr_read_dma, &dcr_write_dma);
+    ppc_dcr_register(env, DMA0_POL,
+                     dma, &dcr_read_dma, &dcr_write_dma);
 }
 
 /*****************************************************************************/
@@ -845,16 +835,14 @@ void ppc405_gpio_init (CPUState *env, ppc4xx_mmio_t *mmio,
     ppc405_gpio_t *gpio;
 
     gpio = qemu_mallocz(sizeof(ppc405_gpio_t));
-    if (gpio != NULL) {
-        gpio->base = offset;
-        ppc405_gpio_reset(gpio);
-        qemu_register_reset(&ppc405_gpio_reset, gpio);
+    gpio->base = offset;
+    ppc405_gpio_reset(gpio);
+    qemu_register_reset(&ppc405_gpio_reset, gpio);
 #ifdef DEBUG_GPIO
-        printf("%s: offset " PADDRX "\n", __func__, offset);
+    printf("%s: offset " PADDRX "\n", __func__, offset);
 #endif
-        ppc4xx_mmio_register(env, mmio, offset, 0x038,
-                             ppc405_gpio_read, ppc405_gpio_write, gpio);
-    }
+    ppc4xx_mmio_register(env, mmio, offset, 0x038,
+                         ppc405_gpio_read, ppc405_gpio_write, gpio);
 }
 
 /*****************************************************************************/
@@ -1038,19 +1026,17 @@ void ppc405_ocm_init (CPUState *env, unsigned long offset)
     ppc405_ocm_t *ocm;
 
     ocm = qemu_mallocz(sizeof(ppc405_ocm_t));
-    if (ocm != NULL) {
-        ocm->offset = offset;
-        ocm_reset(ocm);
-        qemu_register_reset(&ocm_reset, ocm);
-        ppc_dcr_register(env, OCM0_ISARC,
-                         ocm, &dcr_read_ocm, &dcr_write_ocm);
-        ppc_dcr_register(env, OCM0_ISACNTL,
-                         ocm, &dcr_read_ocm, &dcr_write_ocm);
-        ppc_dcr_register(env, OCM0_DSARC,
-                         ocm, &dcr_read_ocm, &dcr_write_ocm);
-        ppc_dcr_register(env, OCM0_DSACNTL,
-                         ocm, &dcr_read_ocm, &dcr_write_ocm);
-    }
+    ocm->offset = offset;
+    ocm_reset(ocm);
+    qemu_register_reset(&ocm_reset, ocm);
+    ppc_dcr_register(env, OCM0_ISARC,
+                     ocm, &dcr_read_ocm, &dcr_write_ocm);
+    ppc_dcr_register(env, OCM0_ISACNTL,
+                     ocm, &dcr_read_ocm, &dcr_write_ocm);
+    ppc_dcr_register(env, OCM0_DSARC,
+                     ocm, &dcr_read_ocm, &dcr_write_ocm);
+    ppc_dcr_register(env, OCM0_DSACNTL,
+                     ocm, &dcr_read_ocm, &dcr_write_ocm);
 }
 
 /*****************************************************************************/
@@ -1286,17 +1272,15 @@ void ppc405_i2c_init (CPUState *env, ppc4xx_mmio_t *mmio,
     ppc4xx_i2c_t *i2c;
 
     i2c = qemu_mallocz(sizeof(ppc4xx_i2c_t));
-    if (i2c != NULL) {
-        i2c->base = offset;
-        i2c->irq = irq;
-        ppc4xx_i2c_reset(i2c);
+    i2c->base = offset;
+    i2c->irq = irq;
+    ppc4xx_i2c_reset(i2c);
 #ifdef DEBUG_I2C
-        printf("%s: offset " PADDRX "\n", __func__, offset);
+    printf("%s: offset " PADDRX "\n", __func__, offset);
 #endif
-        ppc4xx_mmio_register(env, mmio, offset, 0x011,
-                             i2c_read, i2c_write, i2c);
-        qemu_register_reset(ppc4xx_i2c_reset, i2c);
-    }
+    ppc4xx_mmio_register(env, mmio, offset, 0x011,
+                         i2c_read, i2c_write, i2c);
+    qemu_register_reset(ppc4xx_i2c_reset, i2c);
 }
 
 /*****************************************************************************/
@@ -1568,19 +1552,17 @@ void ppc4xx_gpt_init (CPUState *env, ppc4xx_mmio_t *mmio,
     int i;
 
     gpt = qemu_mallocz(sizeof(ppc4xx_gpt_t));
-    if (gpt != NULL) {
-        gpt->base = offset;
-        for (i = 0; i < 5; i++)
-            gpt->irqs[i] = irqs[i];
-        gpt->timer = qemu_new_timer(vm_clock, &ppc4xx_gpt_cb, gpt);
-        ppc4xx_gpt_reset(gpt);
+    gpt->base = offset;
+    for (i = 0; i < 5; i++)
+        gpt->irqs[i] = irqs[i];
+    gpt->timer = qemu_new_timer(vm_clock, &ppc4xx_gpt_cb, gpt);
+    ppc4xx_gpt_reset(gpt);
 #ifdef DEBUG_GPT
-        printf("%s: offset " PADDRX "\n", __func__, offset);
+    printf("%s: offset " PADDRX "\n", __func__, offset);
 #endif
-        ppc4xx_mmio_register(env, mmio, offset, 0x0D4,
-                             gpt_read, gpt_write, gpt);
-        qemu_register_reset(ppc4xx_gpt_reset, gpt);
-    }
+    ppc4xx_mmio_register(env, mmio, offset, 0x0D4,
+                         gpt_read, gpt_write, gpt);
+    qemu_register_reset(ppc4xx_gpt_reset, gpt);
 }
 
 /*****************************************************************************/
@@ -1802,50 +1784,48 @@ void ppc405_mal_init (CPUState *env, qemu_irq irqs[4])
     int i;
 
     mal = qemu_mallocz(sizeof(ppc40x_mal_t));
-    if (mal != NULL) {
-        for (i = 0; i < 4; i++)
-            mal->irqs[i] = irqs[i];
-        ppc40x_mal_reset(mal);
-        qemu_register_reset(&ppc40x_mal_reset, mal);
-        ppc_dcr_register(env, MAL0_CFG,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_ESR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_IER,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCASR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCARR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXEOBISR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXDEIR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXCASR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXCARR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXEOBISR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXDEIR,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCTP0R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCTP1R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCTP2R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_TXCTP3R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXCTP0R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RXCTP1R,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RCBS0,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-        ppc_dcr_register(env, MAL0_RCBS1,
-                         mal, &dcr_read_mal, &dcr_write_mal);
-    }
+    for (i = 0; i < 4; i++)
+        mal->irqs[i] = irqs[i];
+    ppc40x_mal_reset(mal);
+    qemu_register_reset(&ppc40x_mal_reset, mal);
+    ppc_dcr_register(env, MAL0_CFG,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_ESR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_IER,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCASR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCARR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXEOBISR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXDEIR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXCASR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXCARR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXEOBISR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXDEIR,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCTP0R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCTP1R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCTP2R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_TXCTP3R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXCTP0R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RXCTP1R,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RCBS0,
+                     mal, &dcr_read_mal, &dcr_write_mal);
+    ppc_dcr_register(env, MAL0_RCBS1,
+                     mal, &dcr_read_mal, &dcr_write_mal);
 }
 
 /*****************************************************************************/
@@ -2170,31 +2150,29 @@ static void ppc405cr_cpc_init (CPUState *env, clk_setup_t clk_setup[7],
     ppc405cr_cpc_t *cpc;
 
     cpc = qemu_mallocz(sizeof(ppc405cr_cpc_t));
-    if (cpc != NULL) {
-        memcpy(cpc->clk_setup, clk_setup,
-               PPC405CR_CLK_NB * sizeof(clk_setup_t));
-        cpc->sysclk = sysclk;
-        cpc->jtagid = 0x42051049;
-        ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc,
-                         &dcr_read_crcpc, &dcr_write_crcpc);
-        ppc405cr_clk_init(cpc);
-        qemu_register_reset(ppc405cr_cpc_reset, cpc);
-        ppc405cr_cpc_reset(cpc);
-    }
+    memcpy(cpc->clk_setup, clk_setup,
+           PPC405CR_CLK_NB * sizeof(clk_setup_t));
+    cpc->sysclk = sysclk;
+    cpc->jtagid = 0x42051049;
+    ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc,
+                     &dcr_read_crcpc, &dcr_write_crcpc);
+    ppc405cr_clk_init(cpc);
+    qemu_register_reset(ppc405cr_cpc_reset, cpc);
+    ppc405cr_cpc_reset(cpc);
 }
 
 CPUState *ppc405cr_init (target_phys_addr_t ram_bases[4],
@@ -2516,38 +2494,36 @@ static void ppc405ep_cpc_init (CPUState *env, clk_setup_t clk_setup[8],
     ppc405ep_cpc_t *cpc;
 
     cpc = qemu_mallocz(sizeof(ppc405ep_cpc_t));
-    if (cpc != NULL) {
-        memcpy(cpc->clk_setup, clk_setup,
-               PPC405EP_CLK_NB * sizeof(clk_setup_t));
-        cpc->jtagid = 0x20267049;
-        cpc->sysclk = sysclk;
-        ppc405ep_cpc_reset(cpc);
-        qemu_register_reset(&ppc405ep_cpc_reset, cpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
+    memcpy(cpc->clk_setup, clk_setup,
+           PPC405EP_CLK_NB * sizeof(clk_setup_t));
+    cpc->jtagid = 0x20267049;
+    cpc->sysclk = sysclk;
+    ppc405ep_cpc_reset(cpc);
+    qemu_register_reset(&ppc405ep_cpc_reset, cpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
 #if 0
-        ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
-        ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc,
-                         &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
+    ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc,
+                     &dcr_read_epcpc, &dcr_write_epcpc);
 #endif
-    }
 }
 
 CPUState *ppc405ep_init (target_phys_addr_t ram_bases[2],
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 5f03661..fbd447c 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -42,8 +42,6 @@ static void *bamboo_load_device_tree(void *addr,
 
     pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1;
     path = qemu_malloc(pathlen);
-    if (path == NULL)
-        return NULL;
 
     snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
 
diff --git a/hw/ppc4xx_devs.c b/hw/ppc4xx_devs.c
index aec0602..c02cebf 100644
--- a/hw/ppc4xx_devs.c
+++ b/hw/ppc4xx_devs.c
@@ -246,18 +246,16 @@ ppc4xx_mmio_t *ppc4xx_mmio_init (CPUState *env, target_phys_addr_t base)
     int mmio_memory;
 
     mmio = qemu_mallocz(sizeof(ppc4xx_mmio_t));
-    if (mmio != NULL) {
-        mmio->base = base;
-        mmio_memory = cpu_register_io_memory(0, mmio_read, mmio_write, mmio);
+    mmio->base = base;
+    mmio_memory = cpu_register_io_memory(0, mmio_read, mmio_write, mmio);
 #if defined(DEBUG_MMIO)
-        printf("%s: base " PADDRX " len %08x %d\n", __func__,
-               base, TARGET_PAGE_SIZE, mmio_memory);
+    printf("%s: base " PADDRX " len %08x %d\n", __func__,
+           base, TARGET_PAGE_SIZE, mmio_memory);
 #endif
-        cpu_register_physical_memory(base, TARGET_PAGE_SIZE, mmio_memory);
-        ppc4xx_mmio_register(env, mmio, 0, TARGET_PAGE_SIZE,
-                             unassigned_mmio_read, unassigned_mmio_write,
-                             mmio);
-    }
+    cpu_register_physical_memory(base, TARGET_PAGE_SIZE, mmio_memory);
+    ppc4xx_mmio_register(env, mmio, 0, TARGET_PAGE_SIZE,
+                         unassigned_mmio_read, unassigned_mmio_write,
+                         mmio);
 
     return mmio;
 }
@@ -492,18 +490,16 @@ qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs,
     int i;
 
     uic = qemu_mallocz(sizeof(ppcuic_t));
-    if (uic != NULL) {
-        uic->dcr_base = dcr_base;
-        uic->irqs = irqs;
-        if (has_vr)
-            uic->use_vectors = 1;
-        for (i = 0; i < DCR_UICMAX; i++) {
-            ppc_dcr_register(env, dcr_base + i, uic,
-                             &dcr_read_uic, &dcr_write_uic);
-        }
-        qemu_register_reset(ppcuic_reset, uic);
-        ppcuic_reset(uic);
+    uic->dcr_base = dcr_base;
+    uic->irqs = irqs;
+    if (has_vr)
+        uic->use_vectors = 1;
+    for (i = 0; i < DCR_UICMAX; i++) {
+        ppc_dcr_register(env, dcr_base + i, uic,
+                         &dcr_read_uic, &dcr_write_uic);
     }
+    qemu_register_reset(ppcuic_reset, uic);
+    ppcuic_reset(uic);
 
     return qemu_allocate_irqs(&ppcuic_set_irq, uic, UIC_MAX_IRQ);
 }
@@ -829,24 +825,22 @@ void ppc4xx_sdram_init (CPUState *env, qemu_irq irq, int nbanks,
     ppc4xx_sdram_t *sdram;
 
     sdram = qemu_mallocz(sizeof(ppc4xx_sdram_t));
-    if (sdram != NULL) {
-        sdram->irq = irq;
-        sdram->nbanks = nbanks;
-        memset(sdram->ram_bases, 0, 4 * sizeof(target_phys_addr_t));
-        memcpy(sdram->ram_bases, ram_bases,
-               nbanks * sizeof(target_phys_addr_t));
-        memset(sdram->ram_sizes, 0, 4 * sizeof(target_phys_addr_t));
-        memcpy(sdram->ram_sizes, ram_sizes,
-               nbanks * sizeof(target_phys_addr_t));
-        sdram_reset(sdram);
-        qemu_register_reset(&sdram_reset, sdram);
-        ppc_dcr_register(env, SDRAM0_CFGADDR,
-                         sdram, &dcr_read_sdram, &dcr_write_sdram);
-        ppc_dcr_register(env, SDRAM0_CFGDATA,
-                         sdram, &dcr_read_sdram, &dcr_write_sdram);
-        if (do_init)
-            sdram_map_bcr(sdram);
-    }
+    sdram->irq = irq;
+    sdram->nbanks = nbanks;
+    memset(sdram->ram_bases, 0, 4 * sizeof(target_phys_addr_t));
+    memcpy(sdram->ram_bases, ram_bases,
+           nbanks * sizeof(target_phys_addr_t));
+    memset(sdram->ram_sizes, 0, 4 * sizeof(target_phys_addr_t));
+    memcpy(sdram->ram_sizes, ram_sizes,
+           nbanks * sizeof(target_phys_addr_t));
+    sdram_reset(sdram);
+    qemu_register_reset(&sdram_reset, sdram);
+    ppc_dcr_register(env, SDRAM0_CFGADDR,
+                     sdram, &dcr_read_sdram, &dcr_write_sdram);
+    ppc_dcr_register(env, SDRAM0_CFGDATA,
+                     sdram, &dcr_read_sdram, &dcr_write_sdram);
+    if (do_init)
+        sdram_map_bcr(sdram);
 }
 
 /* Fill in consecutive SDRAM banks with 'ram_size' bytes of memory.
diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c
index 574ec19..601bfcf 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc4xx_pci.c
@@ -369,8 +369,6 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
     uint8_t *pci_conf;
 
     controller = qemu_mallocz(sizeof(PPC4xxPCIState));
-    if (!controller)
-        return NULL;
 
     controller->pci_state.bus = pci_register_bus(ppc4xx_pci_set_irq,
                                                  ppc4xx_pci_map_irq,
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index f9d0acc..b104fc3 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -553,8 +553,6 @@ static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size,
     BlockDriverState *fd[MAX_FD];
 
     sysctrl = qemu_mallocz(sizeof(sysctrl_t));
-    if (sysctrl == NULL)
-        return;
 
     linux_boot = (kernel_filename != NULL);
 
diff --git a/hw/r2d.c b/hw/r2d.c
index 3901a73..e6b2bf4 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -170,8 +170,6 @@ static qemu_irq *r2d_fpga_init(target_phys_addr_t base, qemu_irq irl)
     r2d_fpga_t *s;
 
     s = qemu_mallocz(sizeof(r2d_fpga_t));
-    if (!s)
-        return NULL;
 
     s->irl = irl;
 
diff --git a/hw/rc4030.c b/hw/rc4030.c
index c37c252..f4044ce 100644
--- a/hw/rc4030.c
+++ b/hw/rc4030.c
@@ -718,8 +718,6 @@ qemu_irq *rc4030_init(qemu_irq timer, qemu_irq jazz_bus,
     int s_chipset, s_jazzio;
 
     s = qemu_mallocz(sizeof(rc4030State));
-    if (!s)
-        return NULL;
 
     *dmas = rc4030_allocate_dmas(s, 4);
     *dma_read = rc4030_dma_read;
diff --git a/hw/sb16.c b/hw/sb16.c
index ad246ea..14f3e3d 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1411,11 +1411,6 @@ int SB16_init (AudioState *audio, qemu_irq *pic)
     }
 
     s = qemu_mallocz (sizeof (*s));
-    if (!s) {
-        dolog ("Could not allocate memory for SB16 (%zu bytes)\n",
-               sizeof (*s));
-        return -1;
-    }
 
     s->cmd = -1;
     s->pic = pic;
diff --git a/hw/sbi.c b/hw/sbi.c
index 199db8f..9c41f53 100644
--- a/hw/sbi.c
+++ b/hw/sbi.c
@@ -146,8 +146,6 @@ void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq,
     SBIState *s;
 
     s = qemu_mallocz(sizeof(SBIState));
-    if (!s)
-        return NULL;
 
     for (i = 0; i < MAX_CPUS; i++) {
         s->cpu_irqs[i] = parent_irq[i];
diff --git a/hw/serial.c b/hw/serial.c
index 0273177..ac089fc 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -732,8 +732,6 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
     SerialState *s;
 
     s = qemu_mallocz(sizeof(SerialState));
-    if (!s)
-        return NULL;
 
     serial_init_core(s, irq, baudbase, chr);
 
@@ -824,8 +822,6 @@ SerialState *serial_mm_init (target_phys_addr_t base, int it_shift,
     int s_io_memory;
 
     s = qemu_mallocz(sizeof(SerialState));
-    if (!s)
-        return NULL;
 
     s->it_shift = it_shift;
 
diff --git a/hw/sh_intc.c b/hw/sh_intc.c
index 9039e55..f4138fd 100644
--- a/hw/sh_intc.c
+++ b/hw/sh_intc.c
@@ -432,9 +432,7 @@ int sh_intc_init(struct intc_desc *desc,
     desc->nr_prio_regs = nr_prio_regs;
 
     i = sizeof(struct intc_source) * nr_sources;
-    desc->sources = malloc(i);
-    if (!desc->sources)
-        return -1;
+    desc->sources = qemu_malloc(i);
 
     memset(desc->sources, 0, i);
     for (i = 0; i < desc->nr_sources; i++) {
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
index da1a2ca..4957c41 100644
--- a/hw/sh_serial.c
+++ b/hw/sh_serial.c
@@ -376,8 +376,6 @@ void sh_serial_init (target_phys_addr_t base, int feat,
     int s_io_memory;
 
     s = qemu_mallocz(sizeof(sh_serial_state));
-    if (!s)
-        return;
 
     s->feat = feat;
     s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE;
diff --git a/hw/slavio_intctl.c b/hw/slavio_intctl.c
index 0729c2a..ff8f0c7 100644
--- a/hw/slavio_intctl.c
+++ b/hw/slavio_intctl.c
@@ -381,14 +381,10 @@ void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
     SLAVIO_CPUINTCTLState *slave;
 
     s = qemu_mallocz(sizeof(SLAVIO_INTCTLState));
-    if (!s)
-        return NULL;
 
     s->intbit_to_level = intbit_to_level;
     for (i = 0; i < MAX_CPUS; i++) {
         slave = qemu_mallocz(sizeof(SLAVIO_CPUINTCTLState));
-        if (!slave)
-            return NULL;
 
         slave->cpu = i;
         slave->master = s;
diff --git a/hw/slavio_misc.c b/hw/slavio_misc.c
index 2c383ca..79d4018 100644
--- a/hw/slavio_misc.c
+++ b/hw/slavio_misc.c
@@ -446,8 +446,6 @@ void *slavio_misc_init(target_phys_addr_t base, target_phys_addr_t power_base,
     MiscState *s;
 
     s = qemu_mallocz(sizeof(MiscState));
-    if (!s)
-        return NULL;
 
     if (base) {
         /* 8 bit registers */
diff --git a/hw/slavio_timer.c b/hw/slavio_timer.c
index 01cb1cf..6a29ce2 100644
--- a/hw/slavio_timer.c
+++ b/hw/slavio_timer.c
@@ -372,8 +372,6 @@ static SLAVIO_TIMERState *slavio_timer_init(target_phys_addr_t addr,
     QEMUBH *bh;
 
     s = qemu_mallocz(sizeof(SLAVIO_TIMERState));
-    if (!s)
-        return s;
     s->irq = irq;
     s->master = master;
     s->slave_index = slave_index;
diff --git a/hw/sparc32_dma.c b/hw/sparc32_dma.c
index 354b551..b1495dd 100644
--- a/hw/sparc32_dma.c
+++ b/hw/sparc32_dma.c
@@ -248,8 +248,6 @@ void *sparc32_dma_init(target_phys_addr_t daddr, qemu_irq parent_irq,
     int dma_io_memory;
 
     s = qemu_mallocz(sizeof(DMAState));
-    if (!s)
-        return NULL;
 
     s->irq = parent_irq;
     s->iommu = iommu;
diff --git a/hw/sun4c_intctl.c b/hw/sun4c_intctl.c
index dd42777..1759157 100644
--- a/hw/sun4c_intctl.c
+++ b/hw/sun4c_intctl.c
@@ -204,8 +204,6 @@ void *sun4c_intctl_init(target_phys_addr_t addr, qemu_irq **irq,
     Sun4c_INTCTLState *s;
 
     s = qemu_mallocz(sizeof(Sun4c_INTCTLState));
-    if (!s)
-        return NULL;
 
     sun4c_intctl_io_memory = cpu_register_io_memory(0, sun4c_intctl_mem_read,
                                                     sun4c_intctl_mem_write, s);
diff --git a/hw/tcx.c b/hw/tcx.c
index 1005e63..20c0dbb 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -499,8 +499,6 @@ void tcx_init(target_phys_addr_t addr, uint8_t *vram_base,
     int size;
 
     s = qemu_mallocz(sizeof(TCXState));
-    if (!s)
-        return;
     s->addr = addr;
     s->vram_offset = vram_offset;
     s->width = width;
diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 3c4a586..55f979e 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -625,8 +625,6 @@ USBDevice *usb_bt_init(HCIInfo *hci)
     if (!hci)
         return NULL;
     s = qemu_mallocz(sizeof(struct USBBtState));
-    if (!s)
-        return NULL;
     s->dev.opaque = s;
     s->dev.speed = USB_SPEED_HIGH;
     s->dev.handle_packet = usb_generic_handle_packet;
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 76fdce6..c850a91 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -851,8 +851,6 @@ USBDevice *usb_tablet_init(void)
     USBHIDState *s;
 
     s = qemu_mallocz(sizeof(USBHIDState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
@@ -874,8 +872,6 @@ USBDevice *usb_mouse_init(void)
     USBHIDState *s;
 
     s = qemu_mallocz(sizeof(USBHIDState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
@@ -897,8 +893,6 @@ USBDevice *usb_keyboard_init(void)
     USBHIDState *s;
 
     s = qemu_mallocz(sizeof(USBHIDState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 97c3d05..9f26bbe 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -530,8 +530,6 @@ USBDevice *usb_hub_init(int nb_ports)
     if (nb_ports > MAX_PORTS)
         return NULL;
     s = qemu_mallocz(sizeof(USBHubState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_hub_handle_packet;
 
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index f7ad25e..342b0e8 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -548,8 +548,6 @@ USBDevice *usb_msd_init(const char *filename)
     }
 
     s = qemu_mallocz(sizeof(MSDState));
-    if (!s)
-        return NULL;
 
     bdrv = bdrv_new("usb");
     if (bdrv_open2(bdrv, filename, 0, drv) < 0)
diff --git a/hw/usb-net.c b/hw/usb-net.c
index c49fd62..863c25f 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1430,8 +1430,6 @@ USBDevice *usb_net_init(NICInfo *nd)
     USBNetState *s;
 
     s = qemu_mallocz(sizeof(USBNetState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 9dd2c07..5208482 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -554,8 +554,6 @@ USBDevice *usb_serial_init(const char *filename)
     }
     filename++;
     s = qemu_mallocz(sizeof(USBSerialState));
-    if (!s)
-        return NULL;
 
     snprintf(label, sizeof(label), "usbserial%d", index++);
     cdrv = qemu_chr_open(label, filename, NULL);
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 89b357e..d42d394 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -155,14 +155,13 @@ typedef struct UHCI_QH {
 static UHCIAsync *uhci_async_alloc(UHCIState *s)
 {
     UHCIAsync *async = qemu_malloc(sizeof(UHCIAsync));
-    if (async) {
-        memset(&async->packet, 0, sizeof(async->packet));
-        async->valid = 0;
-        async->td    = 0;
-        async->token = 0;
-        async->done  = 0;
-        async->next  = NULL;
-    }
+
+    memset(&async->packet, 0, sizeof(async->packet));
+    async->valid = 0;
+    async->td    = 0;
+    async->token = 0;
+    async->done  = 0;
+    async->next  = NULL;
 
     return async;
 }
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index cc3579c..eaf0d29 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -397,8 +397,6 @@ USBDevice *usb_wacom_init(void)
     USBWacomState *s;
 
     s = qemu_mallocz(sizeof(USBWacomState));
-    if (!s)
-        return NULL;
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;
 
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index f601e2f..d80e2f2 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -135,8 +135,6 @@ static qemu_irq *vpb_sic_init(uint32_t base, qemu_irq *parent, int irq)
     int iomemtype;
 
     s = (vpb_sic_state *)qemu_mallocz(sizeof(vpb_sic_state));
-    if (!s)
-        return NULL;
     qi = qemu_allocate_irqs(vpb_sic_set_irq, s, 32);
     s->parent = parent;
     s->irq = irq;
diff --git a/hw/vga.c b/hw/vga.c
index bad120b..98c2234 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2444,8 +2444,6 @@ int isa_vga_init(uint8_t *vga_ram_base,
     VGAState *s;
 
     s = qemu_mallocz(sizeof(VGAState));
-    if (!s)
-        return -1;
 
     vga_common_init(s, vga_ram_base, vga_ram_offset, vga_ram_size);
     vga_init(s);
@@ -2469,8 +2467,6 @@ int isa_vga_mm_init(uint8_t *vga_ram_base,
     VGAState *s;
 
     s = qemu_mallocz(sizeof(VGAState));
-    if (!s)
-        return -1;
 
     vga_common_init(s, vga_ram_base, vga_ram_offset, vga_ram_size);
     vga_mm_init(s, vram_base, ctrl_base, it_shift);
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index e74455b..a7b1146 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -104,8 +104,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
 static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
 {
     VirtIOBlockReq *req = qemu_mallocz(sizeof(*req));
-    if (req != NULL)
-        req->dev = s;
+    req->dev = s;
     return req;
 }
 
diff --git a/hw/virtio.c b/hw/virtio.c
index cc8314d..b94ab0f 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -447,8 +447,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
             sg->iov_len = 2 << 20;
 
         sg->iov_base = qemu_malloc(sg->iov_len);
-        if (sg->iov_base && 
-            !(vring_desc_flags(vq, i) & VRING_DESC_F_WRITE)) {
+        if (!(vring_desc_flags(vq, i) & VRING_DESC_F_WRITE)) {
             cpu_physical_memory_read(vring_desc_addr(vq, i),
                                      sg->iov_base,
                                      sg->iov_len);
diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index 5249393..c70e825 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -275,8 +275,6 @@ void *vmmouse_init(void *m)
     DPRINTF("vmmouse_init\n");
 
     s = qemu_mallocz(sizeof(VMMouseState));
-    if (!s)
-        return NULL;
 
     s->status = 0xffff;
     s->ps2_mouse = m;
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 5/6] targets: remove error handling from qemu_malloc() callers
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
                   ` (3 preceding siblings ...)
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 4/6] hw: " Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 6/6] toplevel: " Avi Kivity
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 target-alpha/translate.c    |    2 --
 target-arm/helper.c         |    4 ----
 target-cris/translate.c     |    2 --
 target-i386/helper.c        |    2 --
 target-i386/kvm.c           |    2 --
 target-m68k/helper.c        |    2 --
 target-mips/translate.c     |    2 --
 target-ppc/helper.c         |    2 --
 target-ppc/kvm_ppc.c        |    4 ----
 target-ppc/translate_init.c |    2 --
 target-sh4/translate.c      |    2 --
 target-sparc/helper.c       |    2 --
 12 files changed, 0 insertions(+), 28 deletions(-)

diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index 3affb21..e27376d 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -2466,8 +2466,6 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
     uint64_t hwpcb;
 
     env = qemu_mallocz(sizeof(CPUAlphaState));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
     alpha_translate_init();
     tlb_flush(env, 1);
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 26fd6d0..3250fb8 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -248,8 +248,6 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
     if (id == 0)
         return NULL;
     env = qemu_mallocz(sizeof(CPUARMState));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
     if (!inited) {
         inited = 1;
@@ -468,8 +466,6 @@ int cpu_arm_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
 static void allocate_mmon_state(CPUState *env)
 {
     env->mmon_entry = malloc(sizeof (mmon_state));
-    if (!env->mmon_entry)
-        abort();
     memset (env->mmon_entry, 0, sizeof (mmon_state));
     env->mmon_entry->cpu_env = env;
     mmon_head = env->mmon_entry;
diff --git a/target-cris/translate.c b/target-cris/translate.c
index 288262d..f575e63 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -3400,8 +3400,6 @@ CPUCRISState *cpu_cris_init (const char *cpu_model)
 	int i;
 
 	env = qemu_mallocz(sizeof(CPUCRISState));
-	if (!env)
-		return NULL;
 
 	cpu_exec_init(env);
 	cpu_reset(env);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index e55de96..5950c97 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1645,8 +1645,6 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
     static int inited;
 
     env = qemu_mallocz(sizeof(CPUX86State));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
     env->cpu_model_str = cpu_model;
 
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 49766e2..0834e62 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -97,8 +97,6 @@ static int kvm_has_msr_star(CPUState *env)
 
         kvm_msr_list = qemu_mallocz(sizeof(msr_list) +
                                     msr_list.nmsrs * sizeof(msr_list.indices[0]));
-        if (kvm_msr_list == NULL)
-            return 0;
 
         kvm_msr_list->nmsrs = msr_list.nmsrs;
         ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, kvm_msr_list);
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 076ea35..7eb21dd 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -166,8 +166,6 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model)
     static int inited;
 
     env = qemu_mallocz(sizeof(CPUM68KState));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
     if (!inited) {
         inited = 1;
diff --git a/target-mips/translate.c b/target-mips/translate.c
index b447b98..d659afb 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -8476,8 +8476,6 @@ CPUMIPSState *cpu_mips_init (const char *cpu_model)
     if (!def)
         return NULL;
     env = qemu_mallocz(sizeof(CPUMIPSState));
-    if (!env)
-        return NULL;
     env->cpu_model = def;
 
     cpu_exec_init(env);
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 3bd1d45..fc62a63 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -2761,8 +2761,6 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
         return NULL;
 
     env = qemu_mallocz(sizeof(CPUPPCState));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
     ppc_translate_init();
     env->cpu_model_str = cpu_model;
diff --git a/target-ppc/kvm_ppc.c b/target-ppc/kvm_ppc.c
index 82c0f42..10cfdb3 100644
--- a/target-ppc/kvm_ppc.c
+++ b/target-ppc/kvm_ppc.c
@@ -33,10 +33,6 @@ int kvmppc_read_host_property(const char *node_path, const char *prop,
     pathlen = snprintf(NULL, 0, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop)
               + 1;
     path = qemu_malloc(pathlen);
-    if (path == NULL) {
-        ret = -ENOMEM;
-        goto out;
-    }
 
     snprintf(path, pathlen, "%s/%s/%s", PROC_DEVTREE_PATH, node_path, prop);
 
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 9570479..c808923 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -9040,8 +9040,6 @@ static int create_new_table (opc_handler_t **table, unsigned char idx)
     opc_handler_t **tmp;
 
     tmp = malloc(0x20 * sizeof(opc_handler_t));
-    if (tmp == NULL)
-        return -1;
     fill_new_table(tmp, 0x20);
     table[idx] = (opc_handler_t *)((unsigned long)tmp | PPC_INDIRECT);
 
diff --git a/target-sh4/translate.c b/target-sh4/translate.c
index 6c9dff5..80ea851 100644
--- a/target-sh4/translate.c
+++ b/target-sh4/translate.c
@@ -277,8 +277,6 @@ CPUSH4State *cpu_sh4_init(const char *cpu_model)
     if (!def)
 	return NULL;
     env = qemu_mallocz(sizeof(CPUSH4State));
-    if (!env)
-	return NULL;
     env->features = def->features;
     cpu_exec_init(env);
     sh4_translate_init();
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index a275880..1a06525 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -713,8 +713,6 @@ CPUSPARCState *cpu_sparc_init(const char *cpu_model)
     CPUSPARCState *env;
 
     env = qemu_mallocz(sizeof(CPUSPARCState));
-    if (!env)
-        return NULL;
     cpu_exec_init(env);
 
     gen_intermediate_code_init(env);
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 6/6] toplevel: remove error handling from qemu_malloc() callers
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
                   ` (4 preceding siblings ...)
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 5/6] targets: " Avi Kivity
@ 2009-02-05 11:08 ` Avi Kivity
  2009-02-05 17:43 ` [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Ian Jackson
  2009-02-05 22:07 ` [Qemu-devel] " Anthony Liguori
  7 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 11:08 UTC (permalink / raw)
  To: Anthony Liguori, qemu-devel

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 aio.c            |    2 -
 buffered_file.c  |    2 -
 console.c        |   23 ---------------------
 cris-dis.c       |   26 +++++++----------------
 curses.c         |    2 -
 device_tree.c    |    4 ---
 exec.c           |   25 ++++++----------------
 gdbstub.c        |    8 -------
 keymaps.c        |   10 ++------
 kvm-all.c        |    7 ------
 loader.c         |    4 ---
 migration-exec.c |    5 ----
 migration-tcp.c  |    2 -
 monitor.c        |    4 ---
 net.c            |   14 ------------
 qemu-char.c      |   59 ------------------------------------------------------
 qemu-nbd.c       |    2 -
 qemu-tool.c      |    6 +---
 readline.c       |    2 -
 savevm.c         |   19 -----------------
 sdl.c            |    2 -
 usb-bsd.c        |    2 -
 usb-linux.c      |   24 +--------------------
 vl.c             |   16 --------------
 vnc.c            |    9 ++-----
 25 files changed, 25 insertions(+), 254 deletions(-)

diff --git a/aio.c b/aio.c
index 70d3cdc..200320c 100644
--- a/aio.c
+++ b/aio.c
@@ -79,8 +79,6 @@ int qemu_aio_set_fd_handler(int fd,
         if (node == NULL) {
             /* Alloc and insert if it's not already there */
             node = qemu_mallocz(sizeof(AioHandler));
-            if (node == NULL)
-                return -ENOMEM;
             node->fd = fd;
             LIST_INSERT_HEAD(&aio_handlers, node, node);
         }
diff --git a/buffered_file.c b/buffered_file.c
index be5baea..ec4f664 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -228,8 +228,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
     QEMUFileBuffered *s;
 
     s = qemu_mallocz(sizeof(*s));
-    if (s == NULL)
-        return NULL;
 
     s->opaque = opaque;
     s->xfer_limit = bytes_per_sec / 10;
diff --git a/console.c b/console.c
index 68ac970..3f2794e 100644
--- a/console.c
+++ b/console.c
@@ -1246,9 +1246,6 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
     if (nb_consoles >= MAX_CONSOLES)
         return NULL;
     s = qemu_mallocz(sizeof(TextConsole));
-    if (!s) {
-        return NULL;
-    }
     if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
         (console_type == GRAPHIC_CONSOLE))) {
         active_console = s;
@@ -1280,8 +1277,6 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
     DisplayState *ds;
 
     ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
-    if (ds == NULL)
-        return NULL;
     ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
 
     s = new_console(ds, GRAPHIC_CONSOLE);
@@ -1402,8 +1397,6 @@ CharDriverState *text_console_init(const char *p)
     CharDriverState *chr;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
 
     if (n_text_consoles == 128) {
         fprintf(stderr, "Too many text consoles\n");
@@ -1562,10 +1555,6 @@ PixelFormat qemu_default_pixelformat(int bpp)
 DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
 {
     DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
-    if (surface == NULL) {
-        fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
-        exit(1);
-    }
 
     surface->width = width;
     surface->height = height;
@@ -1577,10 +1566,6 @@ DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int l
     surface->flags = QEMU_ALLOCATED_FLAG;
 #endif
     surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
-    if (surface->data == NULL) {
-        fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
-        exit(1);
-    }
 
     return surface;
 }
@@ -1596,10 +1581,6 @@ DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
         surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
     else
         surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
-    if (surface->data == NULL) {
-        fprintf(stderr, "qemu_resize_displaysurface: malloc failed\n");
-        exit(1);
-    }
 #ifdef WORDS_BIGENDIAN
     surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
 #else
@@ -1613,10 +1594,6 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
                                               int linesize, uint8_t *data)
 {
     DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
-    if (surface == NULL) {
-        fprintf(stderr, "qemu_create_displaysurface_from: malloc failed\n");
-        exit(1);
-    }
 
     surface->width = width;
     surface->height = height;
diff --git a/cris-dis.c b/cris-dis.c
index 0781b08..ba69907 100644
--- a/cris-dis.c
+++ b/cris-dis.c
@@ -26,6 +26,8 @@
 //#include "libiberty.h"
 \f

 
+void *qemu_malloc(size_t len); /* can't include qemu-common.h here */
+
 #define FALSE 0
 #define TRUE 1
 #define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
@@ -1401,44 +1403,32 @@ get_opcode_entry (unsigned int insn,
   /* Allocate and clear the opcode-table.  */
   if (opc_table == NULL)
     {
-      opc_table = malloc (65536 * sizeof (opc_table[0]));
-      if (opc_table == NULL)
-	return NULL;
+      opc_table = qemu_malloc (65536 * sizeof (opc_table[0]));
 
       memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
 
       dip_prefixes
-	= malloc (65536 * sizeof (const struct cris_opcode **));
-      if (dip_prefixes == NULL)
-	return NULL;
+	= qemu_malloc (65536 * sizeof (const struct cris_opcode **));
 
       memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
 
       bdapq_m1_prefixes
-	= malloc (65536 * sizeof (const struct cris_opcode **));
-      if (bdapq_m1_prefixes == NULL)
-	return NULL;
+	= qemu_malloc (65536 * sizeof (const struct cris_opcode **));
 
       memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
 
       bdapq_m2_prefixes
-	= malloc (65536 * sizeof (const struct cris_opcode **));
-      if (bdapq_m2_prefixes == NULL)
-	return NULL;
+	= qemu_malloc (65536 * sizeof (const struct cris_opcode **));
 
       memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
 
       bdapq_m4_prefixes
-	= malloc (65536 * sizeof (const struct cris_opcode **));
-      if (bdapq_m4_prefixes == NULL)
-	return NULL;
+	= qemu_malloc (65536 * sizeof (const struct cris_opcode **));
 
       memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
 
       rest_prefixes
-	= malloc (65536 * sizeof (const struct cris_opcode **));
-      if (rest_prefixes == NULL)
-	return NULL;
+	= qemu_malloc (65536 * sizeof (const struct cris_opcode **));
 
       memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
     }
diff --git a/curses.c b/curses.c
index 97ab412..d699b5e 100644
--- a/curses.c
+++ b/curses.c
@@ -361,8 +361,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
 #endif
 
     dcl = (DisplayChangeListener *) qemu_mallocz(sizeof(DisplayChangeListener));
-    if (!dcl)
-        exit(1);
     dcl->dpy_update = curses_update;
     dcl->dpy_resize = curses_resize;
     dcl->dpy_refresh = curses_refresh;
diff --git a/device_tree.c b/device_tree.c
index 2238682..4fc0781 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -43,10 +43,6 @@ void *load_device_tree(const char *filename_path, void *load_addr)
 
     /* First allocate space in qemu for device tree */
     dt_file = qemu_mallocz(dt_file_size);
-    if (dt_file == NULL) {
-        printf("Unable to allocate memory in qemu for device tree\n");
-        goto fail;
-    }
 
     dt_file_load_size = load_image(filename_path, dt_file);
 
diff --git a/exec.c b/exec.c
index 302da34..9852bdc 100644
--- a/exec.c
+++ b/exec.c
@@ -476,10 +476,6 @@ static void code_gen_alloc(unsigned long tb_size)
     }
 #else
     code_gen_buffer = qemu_malloc(code_gen_buffer_size);
-    if (!code_gen_buffer) {
-        fprintf(stderr, "Could not allocate dynamic translator buffer\n");
-        exit(1);
-    }
     map_exec(code_gen_buffer, code_gen_buffer_size);
 #endif
 #endif /* !USE_STATIC_CODE_GEN_BUFFER */
@@ -825,8 +821,6 @@ static void build_page_bitmap(PageDesc *p)
     TranslationBlock *tb;
 
     p->code_bitmap = qemu_mallocz(TARGET_PAGE_SIZE / 8);
-    if (!p->code_bitmap)
-        return;
 
     tb = p->first_tb;
     while (tb != NULL) {
@@ -1318,8 +1312,6 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
         return -EINVAL;
     }
     wp = qemu_malloc(sizeof(*wp));
-    if (!wp)
-        return -ENOMEM;
 
     wp->vaddr = addr;
     wp->len_mask = len_mask;
@@ -1384,8 +1376,6 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
     CPUBreakpoint *bp;
 
     bp = qemu_malloc(sizeof(*bp));
-    if (!bp)
-        return -ENOMEM;
 
     bp->pc = pc;
     bp->flags = flags;
@@ -2795,17 +2785,16 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
     int subpage_memory;
 
     mmio = qemu_mallocz(sizeof(subpage_t));
-    if (mmio != NULL) {
-        mmio->base = base;
-        subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
+
+    mmio->base = base;
+    subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
 #if defined(DEBUG_SUBPAGE)
-        printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
-               mmio, base, TARGET_PAGE_SIZE, subpage_memory);
+    printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
+           mmio, base, TARGET_PAGE_SIZE, subpage_memory);
 #endif
-        *phys = subpage_memory | IO_MEM_SUBPAGE;
-        subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
+    *phys = subpage_memory | IO_MEM_SUBPAGE;
+    subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
                          region_offset);
-    }
 
     return mmio;
 }
diff --git a/gdbstub.c b/gdbstub.c
index b4b8292..239f2e0 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2189,11 +2189,6 @@ static void gdb_accept(void)
     setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
 
     s = qemu_mallocz(sizeof(GDBState));
-    if (!s) {
-        errno = ENOMEM;
-        perror("accept");
-        return;
-    }
 
     memset (s, 0, sizeof (GDBState));
     s->c_cpu = first_cpu;
@@ -2311,9 +2306,6 @@ int gdbserver_start(const char *port)
         return -1;
 
     s = qemu_mallocz(sizeof(GDBState));
-    if (!s) {
-        return -1;
-    }
     s->c_cpu = first_cpu;
     s->g_cpu = first_cpu;
     s->chr = chr;
diff --git a/keymaps.c b/keymaps.c
index 38e50f0..216e378 100644
--- a/keymaps.c
+++ b/keymaps.c
@@ -67,11 +67,9 @@ static void add_to_key_range(struct key_range **krp, int code) {
     }
     if (kr == NULL) {
 	kr = qemu_mallocz(sizeof(*kr));
-	if (kr) {
-	    kr->start = kr->end = code;
-	    kr->next = *krp;
-	    *krp = kr;
-	}
+        kr->start = kr->end = code;
+        kr->next = *krp;
+        *krp = kr;
     }
 }
 
@@ -88,8 +86,6 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
 
     if (!k)
 	k = qemu_mallocz(sizeof(kbd_layout_t));
-    if (!k)
-        return 0;
     if (!(f = fopen(file_name, "r"))) {
 	fprintf(stderr,
 		"Could not read keymap file: '%s'\n", file_name);
diff --git a/kvm-all.c b/kvm-all.c
index 9fb295c..0b17427 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -220,11 +220,6 @@ void kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_a
     alloc_size = mem->memory_size >> TARGET_PAGE_BITS / sizeof(d.dirty_bitmap);
     d.dirty_bitmap = qemu_mallocz(alloc_size);
 
-    if (d.dirty_bitmap == NULL) {
-        dprintf("Could not allocate dirty bitmap\n");
-        return;
-    }
-
     d.slot = mem->slot;
     dprintf("slot %d, phys_addr %llx, uaddr: %llx\n",
             d.slot, mem->start_addr, mem->phys_offset);
@@ -295,8 +290,6 @@ int kvm_init(int smp_cpus)
         return -EINVAL;
 
     s = qemu_mallocz(sizeof(KVMState));
-    if (s == NULL)
-        return -ENOMEM;
 
     for (i = 0; i < ARRAY_SIZE(s->slots); i++)
         s->slots[i].slot = i;
diff --git a/loader.c b/loader.c
index cf603cc..71b9ba7 100644
--- a/loader.c
+++ b/loader.c
@@ -266,8 +266,6 @@ static void *load_at(int fd, int offset, int size)
     if (lseek(fd, offset, SEEK_SET) < 0)
         return NULL;
     ptr = qemu_malloc(size);
-    if (!ptr)
-        return NULL;
     if (read(fd, ptr, size) != size) {
         qemu_free(ptr);
         return NULL;
@@ -505,8 +503,6 @@ int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
 
     *ep = hdr->ih_ep;
     data = qemu_malloc(hdr->ih_size);
-    if (!data)
-        goto out;
 
     if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
         fprintf(stderr, "Error reading file\n");
diff --git a/migration-exec.c b/migration-exec.c
index caeed4b..6ed322a 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -61,10 +61,6 @@ MigrationState *exec_start_outgoing_migration(const char *command,
     FILE *f;
 
     s = qemu_mallocz(sizeof(*s));
-    if (s == NULL) {
-        dprintf("Unable to allocate FdMigrationState\n");
-        goto err;
-    }
 
     f = popen(command, "w");
     if (f == NULL) {
@@ -109,7 +105,6 @@ err_after_open:
     pclose(f);
 err_after_alloc:
     qemu_free(s);
-err:
     return NULL;
 }
 
diff --git a/migration-tcp.c b/migration-tcp.c
index 6fc1943..3f5b104 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -89,8 +89,6 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
         return NULL;
 
     s = qemu_mallocz(sizeof(*s));
-    if (s == NULL)
-        return NULL;
 
     s->get_error = socket_errno;
     s->write = socket_write;
diff --git a/monitor.c b/monitor.c
index 8815688..354a792 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1371,10 +1371,6 @@ static void do_wav_capture (const char *path,
     CaptureState *s;
 
     s = qemu_mallocz (sizeof (*s));
-    if (!s) {
-        term_printf ("Not enough memory to add wave capture\n");
-        return;
-    }
 
     freq = has_freq ? freq : 44100;
     bits = has_bits ? bits : 16;
diff --git a/net.c b/net.c
index 8d9b3de..e7c097e 100644
--- a/net.c
+++ b/net.c
@@ -333,8 +333,6 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
 {
     VLANClientState *vc, **pvc;
     vc = qemu_mallocz(sizeof(VLANClientState));
-    if (!vc)
-        return NULL;
     vc->model = strdup(model);
     if (name)
         vc->name = strdup(name);
@@ -728,8 +726,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
     TAPState *s;
 
     s = qemu_mallocz(sizeof(TAPState));
-    if (!s)
-        return NULL;
     s->fd = fd;
     s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
 #ifdef HAVE_IOVEC
@@ -1049,8 +1045,6 @@ static int net_vde_init(VLANState *vlan, const char *model,
     };
 
     s = qemu_mallocz(sizeof(VDEState));
-    if (!s)
-        return -1;
     s->vde = vde_open(init_sock, "QEMU", &args);
     if (!s->vde){
         free(s);
@@ -1274,8 +1268,6 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
     }
 
     s = qemu_mallocz(sizeof(NetSocketState));
-    if (!s)
-        return NULL;
     s->fd = fd;
 
     s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
@@ -1304,8 +1296,6 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
 {
     NetSocketState *s;
     s = qemu_mallocz(sizeof(NetSocketState));
-    if (!s)
-        return NULL;
     s->fd = fd;
     s->vc = qemu_new_vlan_client(vlan, model, name,
                                  net_socket_receive, NULL, s);
@@ -1383,8 +1373,6 @@ static int net_socket_listen_init(VLANState *vlan,
         return -1;
 
     s = qemu_mallocz(sizeof(NetSocketListenState));
-    if (!s)
-        return -1;
 
     fd = socket(PF_INET, SOCK_STREAM, 0);
     if (fd < 0) {
@@ -1504,8 +1492,6 @@ VLANState *qemu_find_vlan(int id)
             return vlan;
     }
     vlan = qemu_mallocz(sizeof(VLANState));
-    if (!vlan)
-        return NULL;
     vlan->id = id;
     vlan->next = NULL;
     pvlan = &first_vlan;
diff --git a/qemu-char.c b/qemu-char.c
index f849187..6e10c67 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -193,8 +193,6 @@ static CharDriverState *qemu_chr_open_null(void)
     CharDriverState *chr;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     chr->chr_write = null_chr_write;
     return chr;
 }
@@ -425,13 +423,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     MuxDriver *d;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     d = qemu_mallocz(sizeof(MuxDriver));
-    if (!d) {
-        free(chr);
-        return NULL;
-    }
 
     chr->opaque = d;
     d->drv = drv;
@@ -576,13 +568,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
     FDCharDriver *s;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = qemu_mallocz(sizeof(FDCharDriver));
-    if (!s) {
-        free(chr);
-        return NULL;
-    }
     s->fd_in = fd_in;
     s->fd_out = fd_out;
     chr->opaque = s;
@@ -929,13 +915,7 @@ static CharDriverState *qemu_chr_open_pty(void)
 #endif
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = qemu_mallocz(sizeof(PtyCharDriver));
-    if (!s) {
-        qemu_free(chr);
-        return NULL;
-    }
 
     if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
         return NULL;
@@ -1246,19 +1226,10 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
     }
 
     drv = qemu_mallocz(sizeof(ParallelCharDriver));
-    if (!drv) {
-        close(fd);
-        return NULL;
-    }
     drv->fd = fd;
     drv->mode = IEEE1284_MODE_COMPAT;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr) {
-	qemu_free(drv);
-        close(fd);
-        return NULL;
-    }
     chr->chr_write = null_chr_write;
     chr->chr_ioctl = pp_ioctl;
     chr->chr_close = pp_close;
@@ -1318,10 +1289,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
         return NULL;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr) {
-        close(fd);
-        return NULL;
-    }
     chr->opaque = (void *)fd;
     chr->chr_write = null_chr_write;
     chr->chr_ioctl = pp_ioctl;
@@ -1535,13 +1502,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
     WinCharState *s;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = qemu_mallocz(sizeof(WinCharState));
-    if (!s) {
-        free(chr);
-        return NULL;
-    }
     chr->opaque = s;
     chr->chr_write = win_chr_write;
     chr->chr_close = win_chr_close;
@@ -1640,13 +1601,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
     WinCharState *s;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = qemu_mallocz(sizeof(WinCharState));
-    if (!s) {
-        free(chr);
-        return NULL;
-    }
     chr->opaque = s;
     chr->chr_write = win_chr_write;
     chr->chr_close = win_chr_close;
@@ -1666,13 +1621,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
     WinCharState *s;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = qemu_mallocz(sizeof(WinCharState));
-    if (!s) {
-        free(chr);
-        return NULL;
-    }
     s->hcom = fd_out;
     chr->opaque = s;
     chr->chr_write = win_chr_write;
@@ -1774,11 +1723,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def)
     struct sockaddr_in saddr;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        goto return_err;
     s = qemu_mallocz(sizeof(NetCharDriver));
-    if (!s)
-        goto return_err;
 
     fd = socket(PF_INET, SOCK_DGRAM, 0);
     if (fd < 0) {
@@ -2044,11 +1989,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
         is_waitconnect = 0;
 
     chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        goto fail;
     s = qemu_mallocz(sizeof(TCPCharDriver));
-    if (!s)
-        goto fail;
 
     if (is_listen) {
         chr->filename = qemu_malloc(256);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 59bd2f1..0af97ca 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -409,8 +409,6 @@ int main(int argc, char **argv)
     }
 
     sharing_fds = qemu_malloc((shared + 1) * sizeof(int));
-    if (sharing_fds == NULL)
-        errx(ENOMEM, "Cannot allocate sharing fds");
 
     if (socket) {
         sharing_fds[0] = unix_socket_incoming(socket);
diff --git a/qemu-tool.c b/qemu-tool.c
index c0b1cad..4dda5af 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -43,10 +43,8 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
     QEMUBH *bh;
 
     bh = qemu_malloc(sizeof(*bh));
-    if (bh) {
-        bh->cb = cb;
-        bh->opaque = opaque;
-    }
+    bh->cb = cb;
+    bh->opaque = opaque;
 
     return bh;
 }
diff --git a/readline.c b/readline.c
index 7bf9a5e..8572841 100644
--- a/readline.c
+++ b/readline.c
@@ -307,8 +307,6 @@ static void term_completion(void)
     nb_completions = 0;
 
     cmdline = qemu_malloc(term_cmd_buf_index + 1);
-    if (!cmdline)
-        return;
     memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);
     cmdline[term_cmd_buf_index] = '\0';
     readline_find_completion(cmdline);
diff --git a/savevm.c b/savevm.c
index 729e849..3eb2000 100644
--- a/savevm.c
+++ b/savevm.c
@@ -214,10 +214,6 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode)
     }
 
     s = qemu_mallocz(sizeof(QEMUFilePopen));
-    if (!s) {
-        fprintf(stderr, "qemu_popen: malloc failed\n");
-        return NULL;
-    }
 
     s->popen_file = popen_file;
 
@@ -246,9 +242,6 @@ QEMUFile *qemu_fopen_socket(int fd)
 {
     QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
 
-    if (s == NULL)
-        return NULL;
-
     s->fd = fd;
     s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
     return s->file;
@@ -288,8 +281,6 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
     QEMUFileStdio *s;
 
     s = qemu_mallocz(sizeof(QEMUFileStdio));
-    if (!s)
-        return NULL;
 
     s->outfile = fopen(filename, mode);
     if (!s->outfile)
@@ -339,8 +330,6 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr
     QEMUFileBdrv *s;
 
     s = qemu_mallocz(sizeof(QEMUFileBdrv));
-    if (!s)
-        return NULL;
 
     s->bs = bs;
     s->base_offset = offset;
@@ -359,8 +348,6 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
     QEMUFile *f;
 
     f = qemu_mallocz(sizeof(QEMUFile));
-    if (!f)
-        return NULL;
 
     f->opaque = opaque;
     f->put_buffer = put_buffer;
@@ -615,8 +602,6 @@ int register_savevm_live(const char *idstr,
     static int global_section_id;
 
     se = qemu_malloc(sizeof(SaveStateEntry));
-    if (!se)
-        return -1;
     pstrcpy(se->idstr, sizeof(se->idstr), idstr);
     se->instance_id = (instance_id == -1) ? 0 : instance_id;
     se->version_id = version_id;
@@ -908,10 +893,6 @@ int qemu_loadvm_state(QEMUFile *f)
 
             /* Add entry */
             le = qemu_mallocz(sizeof(*le));
-            if (le == NULL) {
-                ret = -ENOMEM;
-                goto out;
-            }
 
             le->se = se;
             le->section_id = section_id;
diff --git a/sdl.c b/sdl.c
index cfdf852..266fbcc 100644
--- a/sdl.c
+++ b/sdl.c
@@ -638,8 +638,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     }
 
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
-    if (!dcl)
-        exit(1);
     dcl->dpy_update = sdl_update;
     dcl->dpy_resize = sdl_resize;
     dcl->dpy_refresh = sdl_refresh;
diff --git a/usb-bsd.c b/usb-bsd.c
index a8a805f..fa4093c 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -340,8 +340,6 @@ USBDevice *usb_host_device_open(const char *devname)
 
     if (dfd >= 0) {
         dev = qemu_mallocz(sizeof(USBHostDevice));
-        if (!dev)
-            goto fail;
         dev->devfd = dfd;
 
         if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
diff --git a/usb-linux.c b/usb-linux.c
index fb1153b..f19f0c4 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -441,10 +441,6 @@ static int usb_host_handle_data(USBHostDevice *s, USBPacket *p)
     int ret;
 
     aurb = async_alloc();
-    if (!aurb) {
-        dprintf("husb: async malloc failed\n");
-        return USB_RET_NAK;
-    }
     aurb->hdev   = s;
     aurb->packet = p;
 
@@ -585,10 +581,6 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
     /* The rest are asynchronous */
 
     aurb = async_alloc();
-    if (!aurb) {
-        dprintf("husb: async malloc failed\n");
-        return USB_RET_NAK;
-    }
     aurb->hdev   = s;
     aurb->packet = p;
 
@@ -898,8 +890,6 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
     char buf[1024];
 
     dev = qemu_mallocz(sizeof(USBHostDevice));
-    if (!dev)
-        goto fail;
 
     dev->bus_num = bus_num;
     dev->addr = addr;
@@ -1308,14 +1298,8 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
 
         /* the module setting (used later for opening devices) */
         usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
-        if (usb_host_device_path) {
-            strcpy(usb_host_device_path, devpath);
-            term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
-        } else {
-            /* out of memory? */
-            perror("husb: unable to allocate memory for device path");
-            return -ENOMEM;
-        }
+        strcpy(usb_host_device_path, devpath);
+        term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
     }
 
     switch (usb_fs_type) {
@@ -1455,10 +1439,6 @@ static int usb_host_auto_add(const char *spec)
         return -1;
 
     f = qemu_mallocz(sizeof(*f));
-    if (!f) {
-        fprintf(stderr, "husb: failed to allocate auto filter\n");
-        return -1;
-    }
 
     *f = filter; 
 
diff --git a/vl.c b/vl.c
index 3676537..aff2b2c 100644
--- a/vl.c
+++ b/vl.c
@@ -546,8 +546,6 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
     QEMUPutMouseEntry *s, *cursor;
 
     s = qemu_mallocz(sizeof(QEMUPutMouseEntry));
-    if (!s)
-        return NULL;
 
     s->qemu_put_mouse_event = func;
     s->qemu_put_mouse_event_opaque = opaque;
@@ -1098,8 +1096,6 @@ static QEMUClock *qemu_new_clock(int type)
 {
     QEMUClock *clock;
     clock = qemu_mallocz(sizeof(QEMUClock));
-    if (!clock)
-        return NULL;
     clock->type = type;
     return clock;
 }
@@ -2808,10 +2804,6 @@ DisplayState *get_displaystate(void)
 static void dumb_display_init(void)
 {
     DisplayState *ds = qemu_mallocz(sizeof(DisplayState));
-    if (ds == NULL) {
-        fprintf(stderr, "dumb_display_init: DisplayState allocation failed\n");
-        exit(1);
-    }
     ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
     register_displaystate(ds);
 }
@@ -2863,8 +2855,6 @@ int qemu_set_fd_handler2(int fd,
                 goto found;
         }
         ioh = qemu_mallocz(sizeof(IOHandlerRecord));
-        if (!ioh)
-            return -1;
         ioh->next = first_io_handler;
         first_io_handler = ioh;
     found:
@@ -2902,8 +2892,6 @@ int qemu_add_polling_cb(PollingFunc *func, void *opaque)
 {
     PollingEntry **ppe, *pe;
     pe = qemu_mallocz(sizeof(PollingEntry));
-    if (!pe)
-        return -1;
     pe->func = func;
     pe->opaque = opaque;
     for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
@@ -3273,8 +3261,6 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
 {
     QEMUBH *bh;
     bh = qemu_mallocz(sizeof(QEMUBH));
-    if (!bh)
-        return NULL;
     bh->cb = cb;
     bh->opaque = opaque;
     bh->next = first_bh;
@@ -3432,8 +3418,6 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
     VMChangeStateEntry *e;
 
     e = qemu_mallocz(sizeof (*e));
-    if (!e)
-        return NULL;
 
     e->cb = cb;
     e->opaque = opaque;
diff --git a/vnc.c b/vnc.c
index 0c4d96e..68df599 100644
--- a/vnc.c
+++ b/vnc.c
@@ -471,8 +471,8 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
     int has_fg, has_bg;
     uint8_t *last_fg, *last_bg;
 
-    last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
-    last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
+    last_fg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
+    last_bg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
     has_fg = has_bg = 0;
     for (j = y; j < (y + h); j += 16) {
 	for (i = x; i < (x + w); i += 16) {
@@ -2237,8 +2237,6 @@ void vnc_display_init(DisplayState *ds)
 
     vs = qemu_mallocz(sizeof(VncState));
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
-    if (!vs || !dcl)
-	exit(1);
 
     ds->opaque = vs;
     dcl->idle = 1;
@@ -2289,8 +2287,7 @@ static int vnc_set_x509_credential(VncState *vs,
 	*cred = NULL;
     }
 
-    if (!(*cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2)))
-	return -1;
+    *cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2);
 
     strcpy(*cred, certdir);
     strcat(*cred, "/");
-- 
1.6.1.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure Avi Kivity
@ 2009-02-05 12:01   ` Daniel P. Berrange
  2009-02-05 12:22     ` Avi Kivity
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel P. Berrange @ 2009-02-05 12:01 UTC (permalink / raw)
  To: qemu-devel

On Thu, Feb 05, 2009 at 01:08:41PM +0200, Avi Kivity wrote:
> Memory allocation failures are a very rare condition on virtual-memory
> hosts.  They are also very difficult to handle correctly (especially in a
> hardware emulation context).  Because of this, it is better to gracefully
> terminate emulation rather than executing untested or even unwritten recovery
> code paths.
> 
> This patch changes the qemu memory allocation routines to terminate emulation
> if an allocation failure is encountered.
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  qemu-malloc.c |   16 ++++++++++------
>  1 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/qemu-malloc.c b/qemu-malloc.c
> index dc74efe..1d00f26 100644
> --- a/qemu-malloc.c
> +++ b/qemu-malloc.c
> @@ -22,6 +22,14 @@
>   * THE SOFTWARE.
>   */
>  #include "qemu-common.h"
> +#include <stdlib.h>
> +
> +static void *oom_check(void *ptr)
> +{
> +    if (ptr == NULL)
> +        exit(13);
> +    return ptr;
> +}

Will all our atexit handlers cope with OOM too? In particular
we don't want them calling qemu_malloc again, or this becomes
re-entrant. If we want to go down this route, then abort() is
probably safer.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure
  2009-02-05 12:01   ` Daniel P. Berrange
@ 2009-02-05 12:22     ` Avi Kivity
  2009-02-05 17:43       ` Ian Jackson
  0 siblings, 1 reply; 13+ messages in thread
From: Avi Kivity @ 2009-02-05 12:22 UTC (permalink / raw)
  To: Daniel P. Berrange, qemu-devel

Daniel P. Berrange wrote:
> On Thu, Feb 05, 2009 at 01:08:41PM +0200, Avi Kivity wrote:
>   
>> Memory allocation failures are a very rare condition on virtual-memory
>> hosts.  They are also very difficult to handle correctly (especially in a
>> hardware emulation context).  Because of this, it is better to gracefully
>> terminate emulation rather than executing untested or even unwritten recovery
>> code paths.
>>
>> This patch changes the qemu memory allocation routines to terminate emulation
>> if an allocation failure is encountered.
>>
>> Signed-off-by: Avi Kivity <avi@redhat.com>
>> ---
>>  qemu-malloc.c |   16 ++++++++++------
>>  1 files changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/qemu-malloc.c b/qemu-malloc.c
>> index dc74efe..1d00f26 100644
>> --- a/qemu-malloc.c
>> +++ b/qemu-malloc.c
>> @@ -22,6 +22,14 @@
>>   * THE SOFTWARE.
>>   */
>>  #include "qemu-common.h"
>> +#include <stdlib.h>
>> +
>> +static void *oom_check(void *ptr)
>> +{
>> +    if (ptr == NULL)
>> +        exit(13);
>> +    return ptr;
>> +}
>>     
>
> Will all our atexit handlers cope with OOM too? In particular
> we don't want them calling qemu_malloc again, or this becomes
> re-entrant. If we want to go down this route, then abort() is
> probably safer.

abort() is a little messy in leaving a core file (which would likely 
fail anyway if we're out of memory).

Maybe _exit() is better here.

Even exit() will work; if we are unable to allocate in the exit handler, 
worst case we overflow the stack and crash.

In any case, I didn't see any calls to qemu_malloc() in existing atexit 
handlers.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
                   ` (5 preceding siblings ...)
  2009-02-05 11:08 ` [Qemu-devel] [PATCH 6/6] toplevel: " Avi Kivity
@ 2009-02-05 17:43 ` Ian Jackson
  2009-02-05 22:07 ` [Qemu-devel] " Anthony Liguori
  7 siblings, 0 replies; 13+ messages in thread
From: Ian Jackson @ 2009-02-05 17:43 UTC (permalink / raw)
  To: qemu-devel

Avi Kivity writes ("[Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling"):
> This patchset modifies qemu_malloc() and related functions to terminate
> on error, and updates callers not to perform their own error handling.  In
> many cases error handling was already missing or incorrect.

Good idea.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

(Although I haven't reviewed your patches in detail.)

Ian.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure
  2009-02-05 12:22     ` Avi Kivity
@ 2009-02-05 17:43       ` Ian Jackson
  0 siblings, 0 replies; 13+ messages in thread
From: Ian Jackson @ 2009-02-05 17:43 UTC (permalink / raw)
  To: qemu-devel

Avi Kivity writes ("Re: [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure"):
> Maybe _exit() is better here.

Yes, I think _exit is correct - although it might be useful to at
least fflush stderr.

Ian.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] Re: [PATCH 0/6] Unify memory allocation failure handling
  2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
                   ` (6 preceding siblings ...)
  2009-02-05 17:43 ` [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Ian Jackson
@ 2009-02-05 22:07 ` Anthony Liguori
  2009-02-06  8:47   ` Avi Kivity
  7 siblings, 1 reply; 13+ messages in thread
From: Anthony Liguori @ 2009-02-05 22:07 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel

Avi Kivity wrote:
> Memory allocation failures are a very rare condition on virtual-memory
> hosts.  They are also very difficult to handle correctly (especially in a
> hardware emulation context).  Because of this, it is better to gracefully
> terminate emulation rather than executing untested or even unwritten recovery
> code paths.
>
> This patchset modifies qemu_malloc() and related functions to terminate
> on error, and updates callers not to perform their own error handling.  In
> many cases error handling was already missing or incorrect.
>
> Avi Kivity (6):
>   Terminate emulation on memory allocation failure
>   block: remove error handling from qemu_malloc() callers
>   audio: remove error handling from qemu_malloc() callers
>   hw: remove error handling from qemu_malloc() callers
>   targets: remove error handling from qemu_malloc() callers
>   toplevel: remove error handling from qemu_malloc() callers
>   

Applied all.  Thanks.

Did you do this all by hand or were scripts involved?

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] Re: [PATCH 0/6] Unify memory allocation failure handling
  2009-02-05 22:07 ` [Qemu-devel] " Anthony Liguori
@ 2009-02-06  8:47   ` Avi Kivity
  0 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2009-02-06  8:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

Anthony Liguori wrote:
>
> Did you do this all by hand or were scripts involved?

By hand, armed only with my trusty grep.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-02-06  8:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-05 11:08 [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Avi Kivity
2009-02-05 11:08 ` [Qemu-devel] [PATCH 1/6] Terminate emulation on memory allocation failure Avi Kivity
2009-02-05 12:01   ` Daniel P. Berrange
2009-02-05 12:22     ` Avi Kivity
2009-02-05 17:43       ` Ian Jackson
2009-02-05 11:08 ` [Qemu-devel] [PATCH 2/6] block: remove error handling from qemu_malloc() callers Avi Kivity
2009-02-05 11:08 ` [Qemu-devel] [PATCH 3/6] audio: " Avi Kivity
2009-02-05 11:08 ` [Qemu-devel] [PATCH 4/6] hw: " Avi Kivity
2009-02-05 11:08 ` [Qemu-devel] [PATCH 5/6] targets: " Avi Kivity
2009-02-05 11:08 ` [Qemu-devel] [PATCH 6/6] toplevel: " Avi Kivity
2009-02-05 17:43 ` [Qemu-devel] [PATCH 0/6] Unify memory allocation failure handling Ian Jackson
2009-02-05 22:07 ` [Qemu-devel] " Anthony Liguori
2009-02-06  8:47   ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).