Commit 1eec614b36390be66430ed6dd0ce47a6f2f0ae1a

Authored by aliguori
1 parent 0d0266a5

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
... ... @@ -79,8 +79,6 @@ int qemu_aio_set_fd_handler(int fd,
79 79 if (node == NULL) {
80 80 /* Alloc and insert if it's not already there */
81 81 node = qemu_mallocz(sizeof(AioHandler));
82   - if (node == NULL)
83   - return -ENOMEM;
84 82 node->fd = fd;
85 83 LIST_INSERT_HEAD(&aio_handlers, node, node);
86 84 }
... ...
buffered_file.c
... ... @@ -228,8 +228,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
228 228 QEMUFileBuffered *s;
229 229  
230 230 s = qemu_mallocz(sizeof(*s));
231   - if (s == NULL)
232   - return NULL;
233 231  
234 232 s->opaque = opaque;
235 233 s->xfer_limit = bytes_per_sec / 10;
... ...
console.c
... ... @@ -1246,9 +1246,6 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
1246 1246 if (nb_consoles >= MAX_CONSOLES)
1247 1247 return NULL;
1248 1248 s = qemu_mallocz(sizeof(TextConsole));
1249   - if (!s) {
1250   - return NULL;
1251   - }
1252 1249 if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
1253 1250 (console_type == GRAPHIC_CONSOLE))) {
1254 1251 active_console = s;
... ... @@ -1280,8 +1277,6 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
1280 1277 DisplayState *ds;
1281 1278  
1282 1279 ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
1283   - if (ds == NULL)
1284   - return NULL;
1285 1280 ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
1286 1281  
1287 1282 s = new_console(ds, GRAPHIC_CONSOLE);
... ... @@ -1402,8 +1397,6 @@ CharDriverState *text_console_init(const char *p)
1402 1397 CharDriverState *chr;
1403 1398  
1404 1399 chr = qemu_mallocz(sizeof(CharDriverState));
1405   - if (!chr)
1406   - return NULL;
1407 1400  
1408 1401 if (n_text_consoles == 128) {
1409 1402 fprintf(stderr, "Too many text consoles\n");
... ... @@ -1562,10 +1555,6 @@ PixelFormat qemu_default_pixelformat(int bpp)
1562 1555 DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
1563 1556 {
1564 1557 DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
1565   - if (surface == NULL) {
1566   - fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
1567   - exit(1);
1568   - }
1569 1558  
1570 1559 surface->width = width;
1571 1560 surface->height = height;
... ... @@ -1577,10 +1566,6 @@ DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int l
1577 1566 surface->flags = QEMU_ALLOCATED_FLAG;
1578 1567 #endif
1579 1568 surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height);
1580   - if (surface->data == NULL) {
1581   - fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
1582   - exit(1);
1583   - }
1584 1569  
1585 1570 return surface;
1586 1571 }
... ... @@ -1596,10 +1581,6 @@ DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
1596 1581 surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
1597 1582 else
1598 1583 surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height);
1599   - if (surface->data == NULL) {
1600   - fprintf(stderr, "qemu_resize_displaysurface: malloc failed\n");
1601   - exit(1);
1602   - }
1603 1584 #ifdef WORDS_BIGENDIAN
1604 1585 surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
1605 1586 #else
... ... @@ -1613,10 +1594,6 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
1613 1594 int linesize, uint8_t *data)
1614 1595 {
1615 1596 DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
1616   - if (surface == NULL) {
1617   - fprintf(stderr, "qemu_create_displaysurface_from: malloc failed\n");
1618   - exit(1);
1619   - }
1620 1597  
1621 1598 surface->width = width;
1622 1599 surface->height = height;
... ...
cris-dis.c
... ... @@ -26,6 +26,8 @@
26 26 //#include "libiberty.h"
27 27  
28 28  
  29 +void *qemu_malloc(size_t len); /* can't include qemu-common.h here */
  30 +
29 31 #define FALSE 0
30 32 #define TRUE 1
31 33 #define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
... ... @@ -1401,44 +1403,32 @@ get_opcode_entry (unsigned int insn,
1401 1403 /* Allocate and clear the opcode-table. */
1402 1404 if (opc_table == NULL)
1403 1405 {
1404   - opc_table = malloc (65536 * sizeof (opc_table[0]));
1405   - if (opc_table == NULL)
1406   - return NULL;
  1406 + opc_table = qemu_malloc (65536 * sizeof (opc_table[0]));
1407 1407  
1408 1408 memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
1409 1409  
1410 1410 dip_prefixes
1411   - = malloc (65536 * sizeof (const struct cris_opcode **));
1412   - if (dip_prefixes == NULL)
1413   - return NULL;
  1411 + = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
1414 1412  
1415 1413 memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
1416 1414  
1417 1415 bdapq_m1_prefixes
1418   - = malloc (65536 * sizeof (const struct cris_opcode **));
1419   - if (bdapq_m1_prefixes == NULL)
1420   - return NULL;
  1416 + = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
1421 1417  
1422 1418 memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
1423 1419  
1424 1420 bdapq_m2_prefixes
1425   - = malloc (65536 * sizeof (const struct cris_opcode **));
1426   - if (bdapq_m2_prefixes == NULL)
1427   - return NULL;
  1421 + = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
1428 1422  
1429 1423 memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
1430 1424  
1431 1425 bdapq_m4_prefixes
1432   - = malloc (65536 * sizeof (const struct cris_opcode **));
1433   - if (bdapq_m4_prefixes == NULL)
1434   - return NULL;
  1426 + = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
1435 1427  
1436 1428 memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
1437 1429  
1438 1430 rest_prefixes
1439   - = malloc (65536 * sizeof (const struct cris_opcode **));
1440   - if (rest_prefixes == NULL)
1441   - return NULL;
  1431 + = qemu_malloc (65536 * sizeof (const struct cris_opcode **));
1442 1432  
1443 1433 memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
1444 1434 }
... ...
curses.c
... ... @@ -361,8 +361,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
361 361 #endif
362 362  
363 363 dcl = (DisplayChangeListener *) qemu_mallocz(sizeof(DisplayChangeListener));
364   - if (!dcl)
365   - exit(1);
366 364 dcl->dpy_update = curses_update;
367 365 dcl->dpy_resize = curses_resize;
368 366 dcl->dpy_refresh = curses_refresh;
... ...
device_tree.c
... ... @@ -43,10 +43,6 @@ void *load_device_tree(const char *filename_path, void *load_addr)
43 43  
44 44 /* First allocate space in qemu for device tree */
45 45 dt_file = qemu_mallocz(dt_file_size);
46   - if (dt_file == NULL) {
47   - printf("Unable to allocate memory in qemu for device tree\n");
48   - goto fail;
49   - }
50 46  
51 47 dt_file_load_size = load_image(filename_path, dt_file);
52 48  
... ...
... ... @@ -476,10 +476,6 @@ static void code_gen_alloc(unsigned long tb_size)
476 476 }
477 477 #else
478 478 code_gen_buffer = qemu_malloc(code_gen_buffer_size);
479   - if (!code_gen_buffer) {
480   - fprintf(stderr, "Could not allocate dynamic translator buffer\n");
481   - exit(1);
482   - }
483 479 map_exec(code_gen_buffer, code_gen_buffer_size);
484 480 #endif
485 481 #endif /* !USE_STATIC_CODE_GEN_BUFFER */
... ... @@ -825,8 +821,6 @@ static void build_page_bitmap(PageDesc *p)
825 821 TranslationBlock *tb;
826 822  
827 823 p->code_bitmap = qemu_mallocz(TARGET_PAGE_SIZE / 8);
828   - if (!p->code_bitmap)
829   - return;
830 824  
831 825 tb = p->first_tb;
832 826 while (tb != NULL) {
... ... @@ -1318,8 +1312,6 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
1318 1312 return -EINVAL;
1319 1313 }
1320 1314 wp = qemu_malloc(sizeof(*wp));
1321   - if (!wp)
1322   - return -ENOMEM;
1323 1315  
1324 1316 wp->vaddr = addr;
1325 1317 wp->len_mask = len_mask;
... ... @@ -1384,8 +1376,6 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
1384 1376 CPUBreakpoint *bp;
1385 1377  
1386 1378 bp = qemu_malloc(sizeof(*bp));
1387   - if (!bp)
1388   - return -ENOMEM;
1389 1379  
1390 1380 bp->pc = pc;
1391 1381 bp->flags = flags;
... ... @@ -2795,17 +2785,16 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
2795 2785 int subpage_memory;
2796 2786  
2797 2787 mmio = qemu_mallocz(sizeof(subpage_t));
2798   - if (mmio != NULL) {
2799   - mmio->base = base;
2800   - subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
  2788 +
  2789 + mmio->base = base;
  2790 + subpage_memory = cpu_register_io_memory(0, subpage_read, subpage_write, mmio);
2801 2791 #if defined(DEBUG_SUBPAGE)
2802   - printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
2803   - mmio, base, TARGET_PAGE_SIZE, subpage_memory);
  2792 + printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
  2793 + mmio, base, TARGET_PAGE_SIZE, subpage_memory);
2804 2794 #endif
2805   - *phys = subpage_memory | IO_MEM_SUBPAGE;
2806   - subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
  2795 + *phys = subpage_memory | IO_MEM_SUBPAGE;
  2796 + subpage_register(mmio, 0, TARGET_PAGE_SIZE - 1, orig_memory,
2807 2797 region_offset);
2808   - }
2809 2798  
2810 2799 return mmio;
2811 2800 }
... ...
gdbstub.c
... ... @@ -2189,11 +2189,6 @@ static void gdb_accept(void)
2189 2189 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
2190 2190  
2191 2191 s = qemu_mallocz(sizeof(GDBState));
2192   - if (!s) {
2193   - errno = ENOMEM;
2194   - perror("accept");
2195   - return;
2196   - }
2197 2192  
2198 2193 memset (s, 0, sizeof (GDBState));
2199 2194 s->c_cpu = first_cpu;
... ... @@ -2311,9 +2306,6 @@ int gdbserver_start(const char *port)
2311 2306 return -1;
2312 2307  
2313 2308 s = qemu_mallocz(sizeof(GDBState));
2314   - if (!s) {
2315   - return -1;
2316   - }
2317 2309 s->c_cpu = first_cpu;
2318 2310 s->g_cpu = first_cpu;
2319 2311 s->chr = chr;
... ...
keymaps.c
... ... @@ -67,11 +67,9 @@ static void add_to_key_range(struct key_range **krp, int code) {
67 67 }
68 68 if (kr == NULL) {
69 69 kr = qemu_mallocz(sizeof(*kr));
70   - if (kr) {
71   - kr->start = kr->end = code;
72   - kr->next = *krp;
73   - *krp = kr;
74   - }
  70 + kr->start = kr->end = code;
  71 + kr->next = *krp;
  72 + *krp = kr;
75 73 }
76 74 }
77 75  
... ... @@ -88,8 +86,6 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
88 86  
89 87 if (!k)
90 88 k = qemu_mallocz(sizeof(kbd_layout_t));
91   - if (!k)
92   - return 0;
93 89 if (!(f = fopen(file_name, "r"))) {
94 90 fprintf(stderr,
95 91 "Could not read keymap file: '%s'\n", file_name);
... ...
kvm-all.c
... ... @@ -220,11 +220,6 @@ void kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_a
220 220 alloc_size = mem->memory_size >> TARGET_PAGE_BITS / sizeof(d.dirty_bitmap);
221 221 d.dirty_bitmap = qemu_mallocz(alloc_size);
222 222  
223   - if (d.dirty_bitmap == NULL) {
224   - dprintf("Could not allocate dirty bitmap\n");
225   - return;
226   - }
227   -
228 223 d.slot = mem->slot;
229 224 dprintf("slot %d, phys_addr %llx, uaddr: %llx\n",
230 225 d.slot, mem->start_addr, mem->phys_offset);
... ... @@ -295,8 +290,6 @@ int kvm_init(int smp_cpus)
295 290 return -EINVAL;
296 291  
297 292 s = qemu_mallocz(sizeof(KVMState));
298   - if (s == NULL)
299   - return -ENOMEM;
300 293  
301 294 for (i = 0; i < ARRAY_SIZE(s->slots); i++)
302 295 s->slots[i].slot = i;
... ...
loader.c
... ... @@ -266,8 +266,6 @@ static void *load_at(int fd, int offset, int size)
266 266 if (lseek(fd, offset, SEEK_SET) < 0)
267 267 return NULL;
268 268 ptr = qemu_malloc(size);
269   - if (!ptr)
270   - return NULL;
271 269 if (read(fd, ptr, size) != size) {
272 270 qemu_free(ptr);
273 271 return NULL;
... ... @@ -505,8 +503,6 @@ int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
505 503  
506 504 *ep = hdr->ih_ep;
507 505 data = qemu_malloc(hdr->ih_size);
508   - if (!data)
509   - goto out;
510 506  
511 507 if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
512 508 fprintf(stderr, "Error reading file\n");
... ...
migration-exec.c
... ... @@ -61,10 +61,6 @@ MigrationState *exec_start_outgoing_migration(const char *command,
61 61 FILE *f;
62 62  
63 63 s = qemu_mallocz(sizeof(*s));
64   - if (s == NULL) {
65   - dprintf("Unable to allocate FdMigrationState\n");
66   - goto err;
67   - }
68 64  
69 65 f = popen(command, "w");
70 66 if (f == NULL) {
... ... @@ -109,7 +105,6 @@ err_after_open:
109 105 pclose(f);
110 106 err_after_alloc:
111 107 qemu_free(s);
112   -err:
113 108 return NULL;
114 109 }
115 110  
... ...
migration-tcp.c
... ... @@ -89,8 +89,6 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
89 89 return NULL;
90 90  
91 91 s = qemu_mallocz(sizeof(*s));
92   - if (s == NULL)
93   - return NULL;
94 92  
95 93 s->get_error = socket_errno;
96 94 s->write = socket_write;
... ...
monitor.c
... ... @@ -1371,10 +1371,6 @@ static void do_wav_capture (const char *path,
1371 1371 CaptureState *s;
1372 1372  
1373 1373 s = qemu_mallocz (sizeof (*s));
1374   - if (!s) {
1375   - term_printf ("Not enough memory to add wave capture\n");
1376   - return;
1377   - }
1378 1374  
1379 1375 freq = has_freq ? freq : 44100;
1380 1376 bits = has_bits ? bits : 16;
... ...
... ... @@ -333,8 +333,6 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
333 333 {
334 334 VLANClientState *vc, **pvc;
335 335 vc = qemu_mallocz(sizeof(VLANClientState));
336   - if (!vc)
337   - return NULL;
338 336 vc->model = strdup(model);
339 337 if (name)
340 338 vc->name = strdup(name);
... ... @@ -728,8 +726,6 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
728 726 TAPState *s;
729 727  
730 728 s = qemu_mallocz(sizeof(TAPState));
731   - if (!s)
732   - return NULL;
733 729 s->fd = fd;
734 730 s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
735 731 #ifdef HAVE_IOVEC
... ... @@ -1049,8 +1045,6 @@ static int net_vde_init(VLANState *vlan, const char *model,
1049 1045 };
1050 1046  
1051 1047 s = qemu_mallocz(sizeof(VDEState));
1052   - if (!s)
1053   - return -1;
1054 1048 s->vde = vde_open(init_sock, "QEMU", &args);
1055 1049 if (!s->vde){
1056 1050 free(s);
... ... @@ -1274,8 +1268,6 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
1274 1268 }
1275 1269  
1276 1270 s = qemu_mallocz(sizeof(NetSocketState));
1277   - if (!s)
1278   - return NULL;
1279 1271 s->fd = fd;
1280 1272  
1281 1273 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,
1304 1296 {
1305 1297 NetSocketState *s;
1306 1298 s = qemu_mallocz(sizeof(NetSocketState));
1307   - if (!s)
1308   - return NULL;
1309 1299 s->fd = fd;
1310 1300 s->vc = qemu_new_vlan_client(vlan, model, name,
1311 1301 net_socket_receive, NULL, s);
... ... @@ -1383,8 +1373,6 @@ static int net_socket_listen_init(VLANState *vlan,
1383 1373 return -1;
1384 1374  
1385 1375 s = qemu_mallocz(sizeof(NetSocketListenState));
1386   - if (!s)
1387   - return -1;
1388 1376  
1389 1377 fd = socket(PF_INET, SOCK_STREAM, 0);
1390 1378 if (fd < 0) {
... ... @@ -1504,8 +1492,6 @@ VLANState *qemu_find_vlan(int id)
1504 1492 return vlan;
1505 1493 }
1506 1494 vlan = qemu_mallocz(sizeof(VLANState));
1507   - if (!vlan)
1508   - return NULL;
1509 1495 vlan->id = id;
1510 1496 vlan->next = NULL;
1511 1497 pvlan = &first_vlan;
... ...
qemu-char.c
... ... @@ -193,8 +193,6 @@ static CharDriverState *qemu_chr_open_null(void)
193 193 CharDriverState *chr;
194 194  
195 195 chr = qemu_mallocz(sizeof(CharDriverState));
196   - if (!chr)
197   - return NULL;
198 196 chr->chr_write = null_chr_write;
199 197 return chr;
200 198 }
... ... @@ -425,13 +423,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
425 423 MuxDriver *d;
426 424  
427 425 chr = qemu_mallocz(sizeof(CharDriverState));
428   - if (!chr)
429   - return NULL;
430 426 d = qemu_mallocz(sizeof(MuxDriver));
431   - if (!d) {
432   - free(chr);
433   - return NULL;
434   - }
435 427  
436 428 chr->opaque = d;
437 429 d->drv = drv;
... ... @@ -576,13 +568,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
576 568 FDCharDriver *s;
577 569  
578 570 chr = qemu_mallocz(sizeof(CharDriverState));
579   - if (!chr)
580   - return NULL;
581 571 s = qemu_mallocz(sizeof(FDCharDriver));
582   - if (!s) {
583   - free(chr);
584   - return NULL;
585   - }
586 572 s->fd_in = fd_in;
587 573 s->fd_out = fd_out;
588 574 chr->opaque = s;
... ... @@ -929,13 +915,7 @@ static CharDriverState *qemu_chr_open_pty(void)
929 915 #endif
930 916  
931 917 chr = qemu_mallocz(sizeof(CharDriverState));
932   - if (!chr)
933   - return NULL;
934 918 s = qemu_mallocz(sizeof(PtyCharDriver));
935   - if (!s) {
936   - qemu_free(chr);
937   - return NULL;
938   - }
939 919  
940 920 if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
941 921 return NULL;
... ... @@ -1246,19 +1226,10 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
1246 1226 }
1247 1227  
1248 1228 drv = qemu_mallocz(sizeof(ParallelCharDriver));
1249   - if (!drv) {
1250   - close(fd);
1251   - return NULL;
1252   - }
1253 1229 drv->fd = fd;
1254 1230 drv->mode = IEEE1284_MODE_COMPAT;
1255 1231  
1256 1232 chr = qemu_mallocz(sizeof(CharDriverState));
1257   - if (!chr) {
1258   - qemu_free(drv);
1259   - close(fd);
1260   - return NULL;
1261   - }
1262 1233 chr->chr_write = null_chr_write;
1263 1234 chr->chr_ioctl = pp_ioctl;
1264 1235 chr->chr_close = pp_close;
... ... @@ -1318,10 +1289,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
1318 1289 return NULL;
1319 1290  
1320 1291 chr = qemu_mallocz(sizeof(CharDriverState));
1321   - if (!chr) {
1322   - close(fd);
1323   - return NULL;
1324   - }
1325 1292 chr->opaque = (void *)fd;
1326 1293 chr->chr_write = null_chr_write;
1327 1294 chr->chr_ioctl = pp_ioctl;
... ... @@ -1535,13 +1502,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
1535 1502 WinCharState *s;
1536 1503  
1537 1504 chr = qemu_mallocz(sizeof(CharDriverState));
1538   - if (!chr)
1539   - return NULL;
1540 1505 s = qemu_mallocz(sizeof(WinCharState));
1541   - if (!s) {
1542   - free(chr);
1543   - return NULL;
1544   - }
1545 1506 chr->opaque = s;
1546 1507 chr->chr_write = win_chr_write;
1547 1508 chr->chr_close = win_chr_close;
... ... @@ -1640,13 +1601,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
1640 1601 WinCharState *s;
1641 1602  
1642 1603 chr = qemu_mallocz(sizeof(CharDriverState));
1643   - if (!chr)
1644   - return NULL;
1645 1604 s = qemu_mallocz(sizeof(WinCharState));
1646   - if (!s) {
1647   - free(chr);
1648   - return NULL;
1649   - }
1650 1605 chr->opaque = s;
1651 1606 chr->chr_write = win_chr_write;
1652 1607 chr->chr_close = win_chr_close;
... ... @@ -1666,13 +1621,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
1666 1621 WinCharState *s;
1667 1622  
1668 1623 chr = qemu_mallocz(sizeof(CharDriverState));
1669   - if (!chr)
1670   - return NULL;
1671 1624 s = qemu_mallocz(sizeof(WinCharState));
1672   - if (!s) {
1673   - free(chr);
1674   - return NULL;
1675   - }
1676 1625 s->hcom = fd_out;
1677 1626 chr->opaque = s;
1678 1627 chr->chr_write = win_chr_write;
... ... @@ -1774,11 +1723,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def)
1774 1723 struct sockaddr_in saddr;
1775 1724  
1776 1725 chr = qemu_mallocz(sizeof(CharDriverState));
1777   - if (!chr)
1778   - goto return_err;
1779 1726 s = qemu_mallocz(sizeof(NetCharDriver));
1780   - if (!s)
1781   - goto return_err;
1782 1727  
1783 1728 fd = socket(PF_INET, SOCK_DGRAM, 0);
1784 1729 if (fd < 0) {
... ... @@ -2044,11 +1989,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
2044 1989 is_waitconnect = 0;
2045 1990  
2046 1991 chr = qemu_mallocz(sizeof(CharDriverState));
2047   - if (!chr)
2048   - goto fail;
2049 1992 s = qemu_mallocz(sizeof(TCPCharDriver));
2050   - if (!s)
2051   - goto fail;
2052 1993  
2053 1994 if (is_listen) {
2054 1995 chr->filename = qemu_malloc(256);
... ...
qemu-nbd.c
... ... @@ -409,8 +409,6 @@ int main(int argc, char **argv)
409 409 }
410 410  
411 411 sharing_fds = qemu_malloc((shared + 1) * sizeof(int));
412   - if (sharing_fds == NULL)
413   - errx(ENOMEM, "Cannot allocate sharing fds");
414 412  
415 413 if (socket) {
416 414 sharing_fds[0] = unix_socket_incoming(socket);
... ...
qemu-tool.c
... ... @@ -43,10 +43,8 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
43 43 QEMUBH *bh;
44 44  
45 45 bh = qemu_malloc(sizeof(*bh));
46   - if (bh) {
47   - bh->cb = cb;
48   - bh->opaque = opaque;
49   - }
  46 + bh->cb = cb;
  47 + bh->opaque = opaque;
50 48  
51 49 return bh;
52 50 }
... ...
readline.c
... ... @@ -307,8 +307,6 @@ static void term_completion(void)
307 307 nb_completions = 0;
308 308  
309 309 cmdline = qemu_malloc(term_cmd_buf_index + 1);
310   - if (!cmdline)
311   - return;
312 310 memcpy(cmdline, term_cmd_buf, term_cmd_buf_index);
313 311 cmdline[term_cmd_buf_index] = '\0';
314 312 readline_find_completion(cmdline);
... ...
savevm.c
... ... @@ -214,10 +214,6 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode)
214 214 }
215 215  
216 216 s = qemu_mallocz(sizeof(QEMUFilePopen));
217   - if (!s) {
218   - fprintf(stderr, "qemu_popen: malloc failed\n");
219   - return NULL;
220   - }
221 217  
222 218 s->popen_file = popen_file;
223 219  
... ... @@ -246,9 +242,6 @@ QEMUFile *qemu_fopen_socket(int fd)
246 242 {
247 243 QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
248 244  
249   - if (s == NULL)
250   - return NULL;
251   -
252 245 s->fd = fd;
253 246 s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
254 247 return s->file;
... ... @@ -288,8 +281,6 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
288 281 QEMUFileStdio *s;
289 282  
290 283 s = qemu_mallocz(sizeof(QEMUFileStdio));
291   - if (!s)
292   - return NULL;
293 284  
294 285 s->outfile = fopen(filename, mode);
295 286 if (!s->outfile)
... ... @@ -339,8 +330,6 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr
339 330 QEMUFileBdrv *s;
340 331  
341 332 s = qemu_mallocz(sizeof(QEMUFileBdrv));
342   - if (!s)
343   - return NULL;
344 333  
345 334 s->bs = bs;
346 335 s->base_offset = offset;
... ... @@ -359,8 +348,6 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
359 348 QEMUFile *f;
360 349  
361 350 f = qemu_mallocz(sizeof(QEMUFile));
362   - if (!f)
363   - return NULL;
364 351  
365 352 f->opaque = opaque;
366 353 f->put_buffer = put_buffer;
... ... @@ -615,8 +602,6 @@ int register_savevm_live(const char *idstr,
615 602 static int global_section_id;
616 603  
617 604 se = qemu_malloc(sizeof(SaveStateEntry));
618   - if (!se)
619   - return -1;
620 605 pstrcpy(se->idstr, sizeof(se->idstr), idstr);
621 606 se->instance_id = (instance_id == -1) ? 0 : instance_id;
622 607 se->version_id = version_id;
... ... @@ -908,10 +893,6 @@ int qemu_loadvm_state(QEMUFile *f)
908 893  
909 894 /* Add entry */
910 895 le = qemu_mallocz(sizeof(*le));
911   - if (le == NULL) {
912   - ret = -ENOMEM;
913   - goto out;
914   - }
915 896  
916 897 le->se = se;
917 898 le->section_id = section_id;
... ...
... ... @@ -638,8 +638,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
638 638 }
639 639  
640 640 dcl = qemu_mallocz(sizeof(DisplayChangeListener));
641   - if (!dcl)
642   - exit(1);
643 641 dcl->dpy_update = sdl_update;
644 642 dcl->dpy_resize = sdl_resize;
645 643 dcl->dpy_refresh = sdl_refresh;
... ...
usb-bsd.c
... ... @@ -340,8 +340,6 @@ USBDevice *usb_host_device_open(const char *devname)
340 340  
341 341 if (dfd >= 0) {
342 342 dev = qemu_mallocz(sizeof(USBHostDevice));
343   - if (!dev)
344   - goto fail;
345 343 dev->devfd = dfd;
346 344  
347 345 if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
... ...
usb-linux.c
... ... @@ -441,10 +441,6 @@ static int usb_host_handle_data(USBHostDevice *s, USBPacket *p)
441 441 int ret;
442 442  
443 443 aurb = async_alloc();
444   - if (!aurb) {
445   - dprintf("husb: async malloc failed\n");
446   - return USB_RET_NAK;
447   - }
448 444 aurb->hdev = s;
449 445 aurb->packet = p;
450 446  
... ... @@ -585,10 +581,6 @@ static int usb_host_handle_control(USBHostDevice *s, USBPacket *p)
585 581 /* The rest are asynchronous */
586 582  
587 583 aurb = async_alloc();
588   - if (!aurb) {
589   - dprintf("husb: async malloc failed\n");
590   - return USB_RET_NAK;
591   - }
592 584 aurb->hdev = s;
593 585 aurb->packet = p;
594 586  
... ... @@ -898,8 +890,6 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
898 890 char buf[1024];
899 891  
900 892 dev = qemu_mallocz(sizeof(USBHostDevice));
901   - if (!dev)
902   - goto fail;
903 893  
904 894 dev->bus_num = bus_num;
905 895 dev->addr = addr;
... ... @@ -1308,14 +1298,8 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
1308 1298  
1309 1299 /* the module setting (used later for opening devices) */
1310 1300 usb_host_device_path = qemu_mallocz(strlen(devpath)+1);
1311   - if (usb_host_device_path) {
1312   - strcpy(usb_host_device_path, devpath);
1313   - term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
1314   - } else {
1315   - /* out of memory? */
1316   - perror("husb: unable to allocate memory for device path");
1317   - return -ENOMEM;
1318   - }
  1301 + strcpy(usb_host_device_path, devpath);
  1302 + term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);
1319 1303 }
1320 1304  
1321 1305 switch (usb_fs_type) {
... ... @@ -1455,10 +1439,6 @@ static int usb_host_auto_add(const char *spec)
1455 1439 return -1;
1456 1440  
1457 1441 f = qemu_mallocz(sizeof(*f));
1458   - if (!f) {
1459   - fprintf(stderr, "husb: failed to allocate auto filter\n");
1460   - return -1;
1461   - }
1462 1442  
1463 1443 *f = filter;
1464 1444  
... ...
... ... @@ -546,8 +546,6 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
546 546 QEMUPutMouseEntry *s, *cursor;
547 547  
548 548 s = qemu_mallocz(sizeof(QEMUPutMouseEntry));
549   - if (!s)
550   - return NULL;
551 549  
552 550 s->qemu_put_mouse_event = func;
553 551 s->qemu_put_mouse_event_opaque = opaque;
... ... @@ -1098,8 +1096,6 @@ static QEMUClock *qemu_new_clock(int type)
1098 1096 {
1099 1097 QEMUClock *clock;
1100 1098 clock = qemu_mallocz(sizeof(QEMUClock));
1101   - if (!clock)
1102   - return NULL;
1103 1099 clock->type = type;
1104 1100 return clock;
1105 1101 }
... ... @@ -2808,10 +2804,6 @@ DisplayState *get_displaystate(void)
2808 2804 static void dumb_display_init(void)
2809 2805 {
2810 2806 DisplayState *ds = qemu_mallocz(sizeof(DisplayState));
2811   - if (ds == NULL) {
2812   - fprintf(stderr, "dumb_display_init: DisplayState allocation failed\n");
2813   - exit(1);
2814   - }
2815 2807 ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
2816 2808 register_displaystate(ds);
2817 2809 }
... ... @@ -2863,8 +2855,6 @@ int qemu_set_fd_handler2(int fd,
2863 2855 goto found;
2864 2856 }
2865 2857 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
2866   - if (!ioh)
2867   - return -1;
2868 2858 ioh->next = first_io_handler;
2869 2859 first_io_handler = ioh;
2870 2860 found:
... ... @@ -2902,8 +2892,6 @@ int qemu_add_polling_cb(PollingFunc *func, void *opaque)
2902 2892 {
2903 2893 PollingEntry **ppe, *pe;
2904 2894 pe = qemu_mallocz(sizeof(PollingEntry));
2905   - if (!pe)
2906   - return -1;
2907 2895 pe->func = func;
2908 2896 pe->opaque = opaque;
2909 2897 for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
... ... @@ -3273,8 +3261,6 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
3273 3261 {
3274 3262 QEMUBH *bh;
3275 3263 bh = qemu_mallocz(sizeof(QEMUBH));
3276   - if (!bh)
3277   - return NULL;
3278 3264 bh->cb = cb;
3279 3265 bh->opaque = opaque;
3280 3266 bh->next = first_bh;
... ... @@ -3432,8 +3418,6 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
3432 3418 VMChangeStateEntry *e;
3433 3419  
3434 3420 e = qemu_mallocz(sizeof (*e));
3435   - if (!e)
3436   - return NULL;
3437 3421  
3438 3422 e->cb = cb;
3439 3423 e->opaque = opaque;
... ...
... ... @@ -471,8 +471,8 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
471 471 int has_fg, has_bg;
472 472 uint8_t *last_fg, *last_bg;
473 473  
474   - last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
475   - last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
  474 + last_fg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
  475 + last_bg = (uint8_t *) qemu_malloc(vs->serverds.pf.bytes_per_pixel);
476 476 has_fg = has_bg = 0;
477 477 for (j = y; j < (y + h); j += 16) {
478 478 for (i = x; i < (x + w); i += 16) {
... ... @@ -2237,8 +2237,6 @@ void vnc_display_init(DisplayState *ds)
2237 2237  
2238 2238 vs = qemu_mallocz(sizeof(VncState));
2239 2239 dcl = qemu_mallocz(sizeof(DisplayChangeListener));
2240   - if (!vs || !dcl)
2241   - exit(1);
2242 2240  
2243 2241 ds->opaque = vs;
2244 2242 dcl->idle = 1;
... ... @@ -2289,8 +2287,7 @@ static int vnc_set_x509_credential(VncState *vs,
2289 2287 *cred = NULL;
2290 2288 }
2291 2289  
2292   - if (!(*cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2)))
2293   - return -1;
  2290 + *cred = qemu_malloc(strlen(certdir) + strlen(filename) + 2);
2294 2291  
2295 2292 strcpy(*cred, certdir);
2296 2293 strcat(*cred, "/");
... ...