Skip to content

Commit 1eec614

Browse files
author
aliguori
committed
toplevel: remove error handling from qemu_malloc() callers (Avi Kivity)
Signed-off-by: Avi Kivity <[email protected]> Signed-off-by: Anthony Liguori <[email protected]> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6531 c046a42c-6fe2-441c-8c8c-71466251a162
1 parent 0d0266a commit 1eec614

25 files changed

+25
-254
lines changed

aio.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ int qemu_aio_set_fd_handler(int fd,
7979
if (node == NULL) {
8080
/* Alloc and insert if it's not already there */
8181
node = qemu_mallocz(sizeof(AioHandler));
82-
if (node == NULL)
83-
return -ENOMEM;
8482
node->fd = fd;
8583
LIST_INSERT_HEAD(&aio_handlers, node, node);
8684
}

buffered_file.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
228228
QEMUFileBuffered *s;
229229

230230
s = qemu_mallocz(sizeof(*s));
231-
if (s == NULL)
232-
return NULL;
233231

234232
s->opaque = opaque;
235233
s->xfer_limit = bytes_per_sec / 10;

console.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,6 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
12461246
if (nb_consoles >= MAX_CONSOLES)
12471247
return NULL;
12481248
s = qemu_mallocz(sizeof(TextConsole));
1249-
if (!s) {
1250-
return NULL;
1251-
}
12521249
if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
12531250
(console_type == GRAPHIC_CONSOLE))) {
12541251
active_console = s;
@@ -1280,8 +1277,6 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
12801277
DisplayState *ds;
12811278

12821279
ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
1283-
if (ds == NULL)
1284-
return NULL;
12851280
ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
12861281

12871282
s = new_console(ds, GRAPHIC_CONSOLE);
@@ -1402,8 +1397,6 @@ CharDriverState *text_console_init(const char *p)
14021397
CharDriverState *chr;
14031398

14041399
chr = qemu_mallocz(sizeof(CharDriverState));
1405-
if (!chr)
1406-
return NULL;
14071400

14081401
if (n_text_consoles == 128) {
14091402
fprintf(stderr, "Too many text consoles\n");
@@ -1562,10 +1555,6 @@ PixelFormat qemu_default_pixelformat(int bpp)
15621555
DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
15631556
{
15641557
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
1565-
if (surface == NULL) {
1566-
fprintf(stderr, "qemu_create_displaysurface: malloc failed\n");
1567-
exit(1);
1568-
}
15691558

15701559
surface->width = width;
15711560
surface->height = height;
@@ -1577,10 +1566,6 @@ DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int l
15771566
surface->flags = QEMU_ALLOCATED_FLAG;
15781567
#endif
15791568
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-
}
15841569

15851570
return surface;
15861571
}
@@ -1596,10 +1581,6 @@ DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
15961581
surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height);
15971582
else
15981583
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-
}
16031584
#ifdef WORDS_BIGENDIAN
16041585
surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG;
16051586
#else
@@ -1613,10 +1594,6 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
16131594
int linesize, uint8_t *data)
16141595
{
16151596
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-
}
16201597

16211598
surface->width = width;
16221599
surface->height = height;

cris-dis.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
//#include "libiberty.h"
2727

2828

29+
void *qemu_malloc(size_t len); /* can't include qemu-common.h here */
30+
2931
#define FALSE 0
3032
#define TRUE 1
3133
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
@@ -1401,44 +1403,32 @@ get_opcode_entry (unsigned int insn,
14011403
/* Allocate and clear the opcode-table. */
14021404
if (opc_table == NULL)
14031405
{
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]));
14071407

14081408
memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
14091409

14101410
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 **));
14141412

14151413
memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
14161414

14171415
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 **));
14211417

14221418
memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
14231419

14241420
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 **));
14281422

14291423
memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
14301424

14311425
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 **));
14351427

14361428
memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
14371429

14381430
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 **));
14421432

14431433
memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
14441434
}

curses.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ void curses_display_init(DisplayState *ds, int full_screen)
361361
#endif
362362

363363
dcl = (DisplayChangeListener *) qemu_mallocz(sizeof(DisplayChangeListener));
364-
if (!dcl)
365-
exit(1);
366364
dcl->dpy_update = curses_update;
367365
dcl->dpy_resize = curses_resize;
368366
dcl->dpy_refresh = curses_refresh;

device_tree.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ void *load_device_tree(const char *filename_path, void *load_addr)
4343

4444
/* First allocate space in qemu for device tree */
4545
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-
}
5046

5147
dt_file_load_size = load_image(filename_path, dt_file);
5248

exec.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@ static void code_gen_alloc(unsigned long tb_size)
476476
}
477477
#else
478478
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-
}
483479
map_exec(code_gen_buffer, code_gen_buffer_size);
484480
#endif
485481
#endif /* !USE_STATIC_CODE_GEN_BUFFER */
@@ -825,8 +821,6 @@ static void build_page_bitmap(PageDesc *p)
825821
TranslationBlock *tb;
826822

827823
p->code_bitmap = qemu_mallocz(TARGET_PAGE_SIZE / 8);
828-
if (!p->code_bitmap)
829-
return;
830824

831825
tb = p->first_tb;
832826
while (tb != NULL) {
@@ -1318,8 +1312,6 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
13181312
return -EINVAL;
13191313
}
13201314
wp = qemu_malloc(sizeof(*wp));
1321-
if (!wp)
1322-
return -ENOMEM;
13231315

13241316
wp->vaddr = addr;
13251317
wp->len_mask = len_mask;
@@ -1384,8 +1376,6 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
13841376
CPUBreakpoint *bp;
13851377

13861378
bp = qemu_malloc(sizeof(*bp));
1387-
if (!bp)
1388-
return -ENOMEM;
13891379

13901380
bp->pc = pc;
13911381
bp->flags = flags;
@@ -2795,17 +2785,16 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
27952785
int subpage_memory;
27962786

27972787
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);
28012791
#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);
28042794
#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,
28072797
region_offset);
2808-
}
28092798

28102799
return mmio;
28112800
}

gdbstub.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,11 +2189,6 @@ static void gdb_accept(void)
21892189
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
21902190

21912191
s = qemu_mallocz(sizeof(GDBState));
2192-
if (!s) {
2193-
errno = ENOMEM;
2194-
perror("accept");
2195-
return;
2196-
}
21972192

21982193
memset (s, 0, sizeof (GDBState));
21992194
s->c_cpu = first_cpu;
@@ -2311,9 +2306,6 @@ int gdbserver_start(const char *port)
23112306
return -1;
23122307

23132308
s = qemu_mallocz(sizeof(GDBState));
2314-
if (!s) {
2315-
return -1;
2316-
}
23172309
s->c_cpu = first_cpu;
23182310
s->g_cpu = first_cpu;
23192311
s->chr = chr;

keymaps.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ static void add_to_key_range(struct key_range **krp, int code) {
6767
}
6868
if (kr == NULL) {
6969
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;
7573
}
7674
}
7775

@@ -88,8 +86,6 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
8886

8987
if (!k)
9088
k = qemu_mallocz(sizeof(kbd_layout_t));
91-
if (!k)
92-
return 0;
9389
if (!(f = fopen(file_name, "r"))) {
9490
fprintf(stderr,
9591
"Could not read keymap file: '%s'\n", file_name);

kvm-all.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ void kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_a
220220
alloc_size = mem->memory_size >> TARGET_PAGE_BITS / sizeof(d.dirty_bitmap);
221221
d.dirty_bitmap = qemu_mallocz(alloc_size);
222222

223-
if (d.dirty_bitmap == NULL) {
224-
dprintf("Could not allocate dirty bitmap\n");
225-
return;
226-
}
227-
228223
d.slot = mem->slot;
229224
dprintf("slot %d, phys_addr %llx, uaddr: %llx\n",
230225
d.slot, mem->start_addr, mem->phys_offset);
@@ -295,8 +290,6 @@ int kvm_init(int smp_cpus)
295290
return -EINVAL;
296291

297292
s = qemu_mallocz(sizeof(KVMState));
298-
if (s == NULL)
299-
return -ENOMEM;
300293

301294
for (i = 0; i < ARRAY_SIZE(s->slots); i++)
302295
s->slots[i].slot = i;

0 commit comments

Comments
 (0)