diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-02-05 22:06:18 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-02-05 22:06:18 +0000 |
commit | 1eec614b36390be66430ed6dd0ce47a6f2f0ae1a (patch) | |
tree | fa9174028d54ea9a531a77d05996688fc704fadd | |
parent | 0d0266a53b4c80ab08c093c36bb3a7bbb29cc3e5 (diff) | |
download | qemu-1eec614b36390be66430ed6dd0ce47a6f2f0ae1a.zip qemu-1eec614b36390be66430ed6dd0ce47a6f2f0ae1a.tar.gz qemu-1eec614b36390be66430ed6dd0ce47a6f2f0ae1a.tar.bz2 |
toplevel: remove error handling from qemu_malloc() callers (Avi Kivity)
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6531 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r-- | aio.c | 2 | ||||
-rw-r--r-- | buffered_file.c | 2 | ||||
-rw-r--r-- | console.c | 23 | ||||
-rw-r--r-- | cris-dis.c | 26 | ||||
-rw-r--r-- | curses.c | 2 | ||||
-rw-r--r-- | device_tree.c | 4 | ||||
-rw-r--r-- | exec.c | 25 | ||||
-rw-r--r-- | gdbstub.c | 8 | ||||
-rw-r--r-- | keymaps.c | 10 | ||||
-rw-r--r-- | kvm-all.c | 7 | ||||
-rw-r--r-- | loader.c | 4 | ||||
-rw-r--r-- | migration-exec.c | 5 | ||||
-rw-r--r-- | migration-tcp.c | 2 | ||||
-rw-r--r-- | monitor.c | 4 | ||||
-rw-r--r-- | net.c | 14 | ||||
-rw-r--r-- | qemu-char.c | 59 | ||||
-rw-r--r-- | qemu-nbd.c | 2 | ||||
-rw-r--r-- | qemu-tool.c | 6 | ||||
-rw-r--r-- | readline.c | 2 | ||||
-rw-r--r-- | savevm.c | 19 | ||||
-rw-r--r-- | sdl.c | 2 | ||||
-rw-r--r-- | usb-bsd.c | 2 | ||||
-rw-r--r-- | usb-linux.c | 24 | ||||
-rw-r--r-- | vl.c | 16 | ||||
-rw-r--r-- | vnc.c | 9 |
25 files changed, 25 insertions, 254 deletions
@@ -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; @@ -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; @@ -26,6 +26,8 @@ //#include "libiberty.h" +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])); } @@ -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); @@ -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; } @@ -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; @@ -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); @@ -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; @@ -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; @@ -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; @@ -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); @@ -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; } @@ -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); @@ -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; @@ -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; @@ -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; @@ -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; @@ -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, "/"); |