@@ -81,7 +81,7 @@ int qemu_aio_set_fd_handler(int fd,
} else {
if (node == NULL) {
/* Alloc and insert if it's not already there */
- node = g_malloc0(sizeof(AioHandler));
+ node = g_new0(AioHandler, 1);
node->fd = fd;
QLIST_INSERT_HEAD(&aio_handlers, node, node);
}
@@ -43,7 +43,7 @@ struct QEMUBH {
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
- bh = g_malloc0(sizeof(QEMUBH));
+ bh = g_new0(QEMUBH, 1);
bh->cb = cb;
bh->opaque = opaque;
bh->next = first_bh;
@@ -235,7 +235,7 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,
nr_sectors = total_sectors - cur_sector;
}
- blk = g_malloc(sizeof(BlkMigBlock));
+ blk = g_new(BlkMigBlock, 1);
blk->buf = g_malloc(BLOCK_SIZE);
blk->bmds = bmds;
blk->sector = cur_sector;
@@ -290,7 +290,7 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
return;
}
- bmds = g_malloc0(sizeof(BlkMigDevState));
+ bmds = g_new0(BlkMigDevState, 1);
bmds->bs = bs;
bmds->bulk_completed = 0;
bmds->total_sectors = sectors;
@@ -395,7 +395,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,
} else {
nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK;
}
- blk = g_malloc(sizeof(BlkMigBlock));
+ blk = g_new(BlkMigBlock, 1);
blk->buf = g_malloc(BLOCK_SIZE);
blk->bmds = bmds;
blk->sector = sector;
@@ -214,7 +214,7 @@ BlockDriverState *bdrv_new(const char *device_name)
{
BlockDriverState *bs;
- bs = g_malloc0(sizeof(BlockDriverState));
+ bs = g_new0(BlockDriverState, 1);
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
if (device_name[0] != '\0') {
QTAILQ_INSERT_TAIL(&bdrv_states, bs, list);
@@ -129,7 +129,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
s->l1_size = (header.size + (1LL << shift) - 1) >> shift;
s->l1_table_offset = header.l1_table_offset;
- s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t));
+ s->l1_table = g_new(uint64_t, s->l1_size);
if (!s->l1_table)
goto fail;
if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
@@ -139,7 +139,7 @@ static int qcow_open(BlockDriverState *bs, int flags)
be64_to_cpus(&s->l1_table[i]);
}
/* alloc L2 cache */
- s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
+ s->l2_cache = g_new(uint64_t, s->l2_size * L2_CACHE_SIZE);
if (!s->l2_cache)
goto fail;
s->cluster_cache = g_malloc(s->cluster_size);
@@ -612,7 +612,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
if (m->nb_clusters == 0)
return 0;
- old_cluster = g_malloc(m->nb_clusters * sizeof(uint64_t));
+ old_cluster = g_new(uint64_t, m->nb_clusters);
/* copy content of unmodified sectors */
start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9;
@@ -324,7 +324,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
s->cluster_size;
uint64_t table_offset = meta_offset + blocks_clusters * s->cluster_size;
uint16_t *new_blocks = g_malloc0(blocks_clusters * s->cluster_size);
- uint64_t *new_table = g_malloc0(table_size * sizeof(uint64_t));
+ uint64_t *new_table = g_new0(uint64_t, table_size);
assert(meta_offset >= (s->free_cluster_index * s->cluster_size));
@@ -1074,7 +1074,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res)
size = bdrv_getlength(bs->file);
nb_clusters = size_to_clusters(s, size);
- refcount_table = g_malloc0(nb_clusters * sizeof(uint16_t));
+ refcount_table = g_new0(uint16_t, nb_clusters);
/* header */
inc_refcounts(bs, res, refcount_table, nb_clusters,
@@ -278,7 +278,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
sn->l1_size = s->l1_size;
if (s->l1_size != 0) {
- l1_table = g_malloc(s->l1_size * sizeof(uint64_t));
+ l1_table = g_new(uint64_t, s->l1_size);
} else {
l1_table = NULL;
}
@@ -292,7 +292,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
g_free(l1_table);
l1_table = NULL;
- snapshots1 = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));
+ snapshots1 = g_new(QCowSnapshot, (s->nb_snapshots + 1));
if (s->snapshots) {
memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
g_free(s->snapshots);
@@ -416,7 +416,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
return s->nb_snapshots;
}
- sn_tab = g_malloc0(s->nb_snapshots * sizeof(QEMUSnapshotInfo));
+ sn_tab = g_new0(QEMUSnapshotInfo, s->nb_snapshots);
for(i = 0; i < s->nb_snapshots; i++) {
sn_info = sn_tab + i;
sn = s->snapshots + i;
@@ -655,7 +655,7 @@ static BlockDriverAIOCB *rbd_aio_rw_vector(BlockDriverState *bs,
s->qemu_aio_count++; /* All the RADOSCB */
- rcb = g_malloc(sizeof(RADOSCB));
+ rcb = g_new(RADOSCB, 1);
rcb->done = 0;
rcb->acb = acb;
rcb->buf = buf;
@@ -811,7 +811,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
return snap_count;
}
- sn_tab = g_malloc0(snap_count * sizeof(QEMUSnapshotInfo));
+ sn_tab = g_new0(QEMUSnapshotInfo, snap_count);
for (i = 0; i < snap_count; i++) {
const char *snap_name = snaps[i].name;
@@ -1852,7 +1852,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
uint32_t snapid = 0;
int ret = -ENOENT, fd;
- old_s = g_malloc(sizeof(BDRVSheepdogState));
+ old_s = g_new(BDRVSheepdogState, 1);
memcpy(old_s, s, sizeof(BDRVSheepdogState));
@@ -301,7 +301,7 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res)
uint32_t *bmap;
logout("\n");
- bmap = g_malloc(s->header.blocks_in_image * sizeof(uint32_t));
+ bmap = g_new(uint32_t, s->header.blocks_in_image);
memset(bmap, 0xff, s->header.blocks_in_image * sizeof(uint32_t));
/* Check block map and value of blocks_allocated. */
@@ -377,8 +377,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
}
}
- extent->l2_cache =
- g_malloc(extent->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
+ extent->l2_cache = g_new(uint32_t, extent->l2_size * L2_CACHE_SIZE);
return 0;
fail_l1b:
g_free(extent->l1_backup_table);
@@ -177,7 +177,7 @@ struct HCIInfo *bt_host_hci(const char *id)
}
# endif
- s = g_malloc0(sizeof(struct bt_host_hci_s));
+ s = g_new0(struct bt_host_hci_s, 1);
s->fd = fd;
s->hci.cmd_send = bt_host_cmd;
s->hci.sco_send = bt_host_sco;
@@ -156,7 +156,7 @@ void bt_vhci_init(struct HCIInfo *info)
exit(-1);
}
- s = g_malloc0(sizeof(struct bt_vhci_s));
+ s = g_new0(struct bt_vhci_s, 1);
s->fd = fd;
s->info = info ?: qemu_next_hci();
s->info->opaque = s;
@@ -522,7 +522,7 @@ static void text_console_resize(TextConsole *s)
if (s->width < w1)
w1 = s->width;
- cells = g_malloc(s->width * s->total_height * sizeof(TextCell));
+ cells = g_new(TextCell, s->width * s->total_height);
for(y = 0; y < s->total_height; y++) {
c = &cells[y * s->width];
if (w1 > 0) {
@@ -1243,7 +1243,7 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
if (nb_consoles >= MAX_CONSOLES)
return NULL;
- s = g_malloc0(sizeof(TextConsole));
+ s = g_new0(TextConsole, 1);
if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
(console_type == GRAPHIC_CONSOLE))) {
active_console = s;
@@ -1342,7 +1342,7 @@ static struct DisplayAllocator default_allocator = {
static void dumb_display_init(void)
{
- DisplayState *ds = g_malloc0(sizeof(DisplayState));
+ DisplayState *ds = g_new0(DisplayState, 1);
int width = 640;
int height = 480;
@@ -1514,7 +1514,7 @@ int text_console_init(QemuOpts *opts, CharDriverState **_chr)
unsigned width;
unsigned height;
- chr = g_malloc0(sizeof(CharDriverState));
+ chr = g_new0(CharDriverState, 1);
if (n_text_consoles == 128) {
fprintf(stderr, "Too many text consoles\n");
@@ -136,7 +136,7 @@ int qemu_fdatasync(int fd)
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
{
- qiov->iov = g_malloc(alloc_hint * sizeof(struct iovec));
+ qiov->iov = g_new(struct iovec, alloc_hint);
qiov->niov = 0;
qiov->nalloc = alloc_hint;
qiov->size = 0;
@@ -413,7 +413,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc)
if (!alloc) {
return NULL;
}
- *lp = p = g_malloc0(sizeof(void *) * L2_SIZE);
+ *lp = p = g_new0(void *, L2_SIZE);
}
lp = p + ((index >> (i * L2_BITS)) & (L2_SIZE - 1));
}
@@ -426,7 +426,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc)
return NULL;
}
- *lp = pd = g_malloc(sizeof(PhysPageDesc) * L2_SIZE);
+ *lp = pd = g_new(PhysPageDesc, L2_SIZE);
for (i = 0; i < L2_SIZE; i++) {
pd[i].phys_offset = IO_MEM_UNASSIGNED;
@@ -562,7 +562,7 @@ static void code_gen_alloc(unsigned long tb_size)
code_gen_buffer_max_size = code_gen_buffer_size -
(TCG_MAX_OP_SIZE * OPC_BUF_SIZE);
code_gen_max_blocks = code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE;
- tbs = g_malloc(code_gen_max_blocks * sizeof(TranslationBlock));
+ tbs = g_new(TranslationBlock, code_gen_max_blocks);
}
/* Must be called before using the QEMU cpus. 'tb_size' is the size
@@ -3598,7 +3598,7 @@ static subpage_t *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
subpage_t *mmio;
int subpage_memory;
- mmio = g_malloc0(sizeof(subpage_t));
+ mmio = g_new0(subpage_t, 1);
mmio->base = base;
subpage_memory = cpu_register_io_memory(subpage_read, subpage_write, mmio,
@@ -3704,7 +3704,7 @@ static CPUWriteMemoryFunc * const swapendian_writefn[3]={
static void swapendian_init(int io_index)
{
- SwapEndianContainer *c = g_malloc(sizeof(SwapEndianContainer));
+ SwapEndianContainer *c = g_new(SwapEndianContainer, 1);
int i;
/* Swap mmio for big endian targets */
@@ -2712,7 +2712,7 @@ static void gdb_accept(void)
val = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
- s = g_malloc0(sizeof(GDBState));
+ s = g_new0(GDBState, 1);
s->c_cpu = first_cpu;
s->g_cpu = first_cpu;
s->fd = fd;
@@ -2880,7 +2880,7 @@ int gdbserver_start(const char *device)
s = gdbserver_state;
if (!s) {
- s = g_malloc0(sizeof(GDBState));
+ s = g_new0(GDBState, 1);
gdbserver_state = s;
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
@@ -550,7 +550,7 @@ static int handle_init(FsContext *ctx)
{
int ret, mnt_id;
struct file_handle fh;
- struct handle_data *data = g_malloc(sizeof(struct handle_data));
+ struct handle_data *data = g_new(struct handle_data, 1);
data->mountfd = open(ctx->fs_root, O_DIRECTORY);
if (data->mountfd < 0) {
ret = data->mountfd;
@@ -336,7 +336,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
return NULL;
}
}
- f = g_malloc0(sizeof(V9fsFidState));
+ f = g_new0(V9fsFidState, 1);
f->fid = fid;
f->fid_type = P9_FID_NONE;
f->ref = 1;
@@ -1771,7 +1771,7 @@ static int v9fs_do_readdir_with_stat(V9fsPDU *pdu,
return saved_dir_pos;
}
- dent = g_malloc(sizeof(struct dirent));
+ dent = g_new(struct dirent, 1);
while (1) {
v9fs_path_init(&path);
@@ -1915,7 +1915,7 @@ static int v9fs_do_readdir(V9fsPDU *pdu,
return saved_dir_pos;
}
- dent = g_malloc(sizeof(struct dirent));
+ dent = g_new(struct dirent, 1);
while (1) {
err = v9fs_co_readdir_r(pdu, fidp, dent, &result);
@@ -290,7 +290,7 @@ void adb_kbd_init(ADBBusState *bus)
{
ADBDevice *d;
KBDState *s;
- s = g_malloc0(sizeof(KBDState));
+ s = g_new0(KBDState, 1);
d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
adb_kbd_reset, s);
qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
@@ -447,7 +447,7 @@ void adb_mouse_init(ADBBusState *bus)
ADBDevice *d;
MouseState *s;
- s = g_malloc0(sizeof(MouseState));
+ s = g_new0(MouseState, 1);
d = adb_register_device(bus, ADB_MOUSE, adb_mouse_request,
adb_mouse_reset, s);
qemu_add_mouse_event_handler(adb_mouse_event, d, 0, "QEMU ADB Mouse");
@@ -170,7 +170,7 @@ static void applesmc_add_key(struct AppleSMCStatus *s, const char *key,
{
struct AppleSMCData *def;
- def = g_malloc0(sizeof(struct AppleSMCData));
+ def = g_new0(struct AppleSMCData, 1);
def->key = key;
def->len = len;
def->data = data;
@@ -572,8 +572,8 @@ int chr_baum_init(QemuOpts *opts, CharDriverState **_chr)
#endif
int tty;
- baum = g_malloc0(sizeof(BaumDriverState));
- baum->chr = chr = g_malloc0(sizeof(CharDriverState));
+ baum = g_new0(BaumDriverState, 1);
+ baum->chr = chr = g_new0(CharDriverState, 1);
chr->opaque = baum;
chr->chr_write = baum_write;
@@ -171,7 +171,7 @@ bitbang_i2c_interface *bitbang_i2c_init(i2c_bus *bus)
{
bitbang_i2c_interface *s;
- s = g_malloc0(sizeof(bitbang_i2c_interface));
+ s = g_new0(bitbang_i2c_interface, 1);
s->bus = bus;
s->last_data = 1;
@@ -963,8 +963,7 @@ void *s1d13745_init(qemu_irq gpio_int)
switch (ds_get_bits_per_pixel(s->state)) {
case 0:
- s->line_fn_tab[0] = s->line_fn_tab[1] =
- g_malloc0(sizeof(blizzard_fn_t) * 0x10);
+ s->line_fn_tab[0] = s->line_fn_tab[1] = g_new0(blizzard_fn_t, 0x10);
break;
case 8:
s->line_fn_tab[0] = blizzard_draw_fn_8;
@@ -721,7 +721,7 @@ static void bt_hci_connection_reject_event(struct bt_hci_s *hci,
static void bt_hci_connection_accept(struct bt_hci_s *hci,
struct bt_device_s *host)
{
- struct bt_hci_link_s *link = g_malloc0(sizeof(struct bt_hci_link_s));
+ struct bt_hci_link_s *link = g_new0(struct bt_hci_link_s, 1);
evt_conn_complete params;
uint16_t handle;
uint8_t status = HCI_SUCCESS;
@@ -2143,7 +2143,7 @@ static void bt_hci_destroy(struct bt_device_s *dev)
struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
{
- struct bt_hci_s *s = g_malloc0(sizeof(struct bt_hci_s));
+ struct bt_hci_s *s = g_new0(struct bt_hci_s, 1);
s->lm.inquiry_done = qemu_new_timer_ns(vm_clock, bt_hci_inquiry_done, s);
s->lm.inquiry_next = qemu_new_timer_ns(vm_clock, bt_hci_inquiry_next, s);
@@ -1236,7 +1236,7 @@ static void l2cap_lmp_connection_request(struct bt_link_s *link)
/* Always accept - we only get called if (dev->device->page_scan). */
- l2cap = g_malloc0(sizeof(struct slave_l2cap_instance_s));
+ l2cap = g_new0(struct slave_l2cap_instance_s, 1);
l2cap->link.slave = &dev->device;
l2cap->link.host = link->host;
l2cap_init(&l2cap->l2cap, &l2cap->link, 0);
@@ -1257,7 +1257,7 @@ static void l2cap_lmp_connection_complete(struct bt_link_s *link)
return;
}
- l2cap = g_malloc0(sizeof(struct l2cap_instance_s));
+ l2cap = g_new0(struct l2cap_instance_s, 1);
l2cap_init(l2cap, link, 1);
link->acl_mode = acl_active;
@@ -54,7 +54,7 @@ static void bt_dummy_lmp_acl_resp(struct bt_link_s *link,
/* Slaves that don't hold any additional per link state can use these */
static void bt_dummy_lmp_connection_request(struct bt_link_s *req)
{
- struct bt_link_s *link = g_malloc0(sizeof(struct bt_link_s));
+ struct bt_link_s *link = g_new0(struct bt_link_s, 1);
link->slave = req->slave;
link->host = req->host;
@@ -2903,7 +2903,7 @@ void isa_cirrus_vga_init(MemoryRegion *system_memory)
{
CirrusVGAState *s;
- s = g_malloc0(sizeof(CirrusVGAState));
+ s = g_new0(CirrusVGAState, 1);
vga_common_init(&s->vga, VGA_RAM_SIZE);
cirrus_init_common(s, CIRRUS_ID_CLGD5430, 0, system_memory);
@@ -889,7 +889,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
qemu_check_nic_model(nd, "dp83932");
- s = g_malloc0(sizeof(dp8393xState));
+ s = g_new0(dp8393xState, 1);
s->mem_opaque = mem_opaque;
s->memory_rw = memory_rw;
@@ -202,7 +202,7 @@ qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
{
HeathrowPICS *s;
- s = g_malloc0(sizeof(HeathrowPICS));
+ s = g_new0(HeathrowPICS, 1);
/* only 1 CPU */
s->irqs = irqs[0];
memory_region_init_io(&s->mem, &heathrow_pic_ops, s,
@@ -524,7 +524,7 @@ qemu_irq *i8259_init(qemu_irq parent_irq)
ISADevice *dev;
int i;
- irq_set = g_malloc(ISA_NUM_IRQS * sizeof(qemu_irq));
+ irq_set = g_new(qemu_irq, ISA_NUM_IRQS);
dev = isa_create("isa-i8259");
qdev_prop_set_uint32(&dev->qdev, "iobase", 0x20);
@@ -342,7 +342,7 @@ MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
{
MACIOIDEState *d;
- d = g_malloc0(sizeof(MACIOIDEState));
+ d = g_new0(MACIOIDEState, 1);
ide_init2_with_non_qdev_drives(&d->bus, hd_table[0], hd_table[1], irq);
if (dbdma)
@@ -120,7 +120,7 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
qemu_irq irq, int shift,
DriveInfo *hd0, DriveInfo *hd1)
{
- MMIOState *s = g_malloc0(sizeof(MMIOState));
+ MMIOState *s = g_new0(MMIOState, 1);
int mem1, mem2;
ide_init2_with_non_qdev_drives(&s->bus, hd0, hd1, irq);
@@ -85,7 +85,7 @@ static void qemu_splitirq(void *opaque, int line, int level)
qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2)
{
- qemu_irq *s = g_malloc0(2 * sizeof(qemu_irq));
+ qemu_irq *s = g_new0(qemu_irq, 2);
s[0] = irq1;
s[1] = irq2;
return qemu_allocate_irqs(qemu_splitirq, s, 1)[0];
@@ -556,7 +556,7 @@ static void ivshmem_setup_msi(IVShmemState * s) {
}
/* allocate Qemu char devices for receiving interrupts */
- s->eventfd_table = g_malloc0(s->vectors * sizeof(EventfdEntry));
+ s->eventfd_table = g_new0(EventfdEntry, s->vectors);
}
static void ivshmem_save(QEMUFile* f, void *opaque)
@@ -690,12 +690,12 @@ static int pci_ivshmem_init(PCIDevice *dev)
s->vm_id = -1;
/* allocate/initialize space for interrupt handling */
- s->peers = g_malloc0(s->nb_peers * sizeof(Peer));
+ s->peers = g_new0(Peer, s->nb_peers);
pci_register_bar(&s->dev, 2,
PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ivshmem);
- s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
+ s->eventfd_chr = g_new0(CharDriverState *, s->vectors);
qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
ivshmem_event, s);
@@ -312,7 +312,7 @@ void jazz_led_init(target_phys_addr_t base)
LedState *s;
int io;
- s = g_malloc0(sizeof(LedState));
+ s = g_new0(LedState, 1);
s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
@@ -125,7 +125,7 @@ static void leon3_generic_hw_init(ram_addr_t ram_size,
cpu_sparc_set_id(env, 0);
/* Reset data */
- reset_info = g_malloc0(sizeof(ResetData));
+ reset_info = g_new0(ResetData, 1);
reset_info->env = env;
qemu_register_reset(main_cpu_reset, reset_info);
@@ -96,7 +96,7 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
int timer0_irq = 1;
int timer1_irq = 3;
- reset_info = g_malloc0(sizeof(ResetInfo));
+ reset_info = g_new0(ResetInfo, 1);
if (cpu_model == NULL) {
cpu_model = "lm32-full";
@@ -190,7 +190,7 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
target_phys_addr_t initrd_base = 0x08400000;
size_t initrd_max = 0x01000000;
- reset_info = g_malloc0(sizeof(ResetInfo));
+ reset_info = g_new0(ResetInfo, 1);
if (cpu_model == NULL) {
cpu_model = "lm32-full";
@@ -57,7 +57,7 @@ static inline HWSetup *hwsetup_init(void)
{
HWSetup *hw;
- hw = g_malloc(sizeof(HWSetup));
+ hw = g_new(HWSetup, 1);
hw->data = g_malloc0(TARGET_PAGE_SIZE);
hw->ptr = hw->data;
@@ -846,7 +846,7 @@ void* DBDMA_init (MemoryRegion **dbdma_mem)
{
DBDMAState *s;
- s = g_malloc0(sizeof(DBDMAState));
+ s = g_new0(DBDMAState, 1);
memory_region_init_io(&s->mem, &dbdma_ops, s, "dbdma", 0x1000);
*dbdma_mem = &s->mem;
@@ -121,7 +121,7 @@ MacIONVRAMState *macio_nvram_init (target_phys_addr_t size,
{
MacIONVRAMState *s;
- s = g_malloc0(sizeof(MacIONVRAMState));
+ s = g_new0(MacIONVRAMState, 1);
s->data = g_malloc0(size);
s->size = size;
s->it_shift = it_shift;
@@ -144,7 +144,7 @@ qemu_irq *mcf_intc_init(target_phys_addr_t base, CPUState *env)
mcf_intc_state *s;
int iomemtype;
- s = g_malloc0(sizeof(mcf_intc_state));
+ s = g_new0(mcf_intc_state, 1);
s->env = env;
mcf_intc_reset(s);
@@ -272,7 +272,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
{
mcf_uart_state *s;
- s = g_malloc0(sizeof(mcf_uart_state));
+ s = g_new0(mcf_uart_state, 1);
s->chr = chr;
s->irq = irq;
if (chr) {
@@ -100,7 +100,7 @@ milkymist_init(ram_addr_t ram_size_not_used,
target_phys_addr_t cmdline_base = sdram_base + 0x1000000;
size_t initrd_max = sdram_size - 0x1002000;
- reset_info = g_malloc0(sizeof(ResetInfo));
+ reset_info = g_new0(ResetInfo, 1);
if (cpu_model == NULL) {
cpu_model = "lm32-full";
@@ -157,7 +157,7 @@ mips_mipssim_init (ram_addr_t ram_size,
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
- reset_info = g_malloc0(sizeof(ResetData));
+ reset_info = g_new0(ResetData, 1);
reset_info->env = env;
reset_info->vector = env->active_tc.PC;
qemu_register_reset(main_cpu_reset, reset_info);
@@ -182,7 +182,7 @@ void mips_r4k_init (ram_addr_t ram_size,
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
- reset_info = g_malloc0(sizeof(ResetData));
+ reset_info = g_new0(ResetData, 1);
reset_info->env = env;
reset_info->vector = env->active_tc.PC;
qemu_register_reset(main_cpu_reset, reset_info);
@@ -68,7 +68,7 @@ int qemu_chr_open_msmouse(QemuOpts *opts, CharDriverState **_chr)
{
CharDriverState *chr;
- chr = g_malloc0(sizeof(CharDriverState));
+ chr = g_new0(CharDriverState, 1);
chr->chr_write = msmouse_chr_write;
chr->chr_close = msmouse_chr_close;
@@ -1113,7 +1113,7 @@ inline static int debug_register_io_memory(CPUReadMemoryFunc * const *mem_read,
CPUWriteMemoryFunc * const *mem_write,
void *opaque)
{
- struct io_fn *s = g_malloc(sizeof(struct io_fn));
+ struct io_fn *s = g_new(struct io_fn, 1);
s->mem_read = mem_read;
s->mem_write = mem_write;
@@ -696,8 +696,8 @@ static int omap2_gpio_init(SysBusDevice *dev)
} else {
s->modulecount = 6;
}
- s->modules = g_malloc0(s->modulecount * sizeof(struct omap2_gpio_s));
- s->handler = g_malloc0(s->modulecount * 32 * sizeof(qemu_irq));
+ s->modules = g_new0(struct omap2_gpio_s, s->modulecount);
+ s->handler = g_new0(qemu_irq, s->modulecount * 32);
qdev_init_gpio_in(&dev->qdev, omap2_gpio_set, s->modulecount * 32);
qdev_init_gpio_out(&dev->qdev, s->handler, s->modulecount * 32);
for (i = 0; i < s->modulecount; i++) {
@@ -140,7 +140,7 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
omap_l4_io_writeb_fn = g_malloc0(sizeof(void *) * L4_PAGES);
omap_l4_io_writeh_fn = g_malloc0(sizeof(void *) * L4_PAGES);
omap_l4_io_writew_fn = g_malloc0(sizeof(void *) * L4_PAGES);
- omap_l4_io_opaque = g_malloc0(sizeof(void *) * L4_PAGES);
+ omap_l4_io_opaque = g_new0(void *, L4_PAGES);
#endif
return bus;
@@ -574,7 +574,7 @@ bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
ParallelState *s;
int io_sw;
- s = g_malloc0(sizeof(ParallelState));
+ s = g_new0(ParallelState, 1);
s->irq = irq;
s->chr = chr;
s->it_shift = it_shift;
@@ -412,7 +412,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
MemoryRegion *region, ram_addr_t size,
target_phys_addr_t mask)
{
- KBDState *s = g_malloc0(sizeof(KBDState));
+ KBDState *s = g_new0(KBDState, 1);
s->irq_kbd = kbd_irq;
s->irq_mouse = mouse_irq;
@@ -585,7 +585,7 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base,
return NULL;
#endif
- pfl = g_malloc0(sizeof(pflash_t));
+ pfl = g_new0(pflash_t, 1);
memory_region_init_rom_device(
&pfl->mem, be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl,
@@ -625,7 +625,7 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base,
total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))
return NULL;
#endif
- pfl = g_malloc0(sizeof(pflash_t));
+ pfl = g_new0(pflash_t, 1);
memory_region_init_rom_device(
&pfl->orig_mem, be ? &pflash_cfi02_ops_be : &pflash_cfi02_ops_le, pfl,
qdev, name, size);
@@ -753,7 +753,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUState *env, uint32_t freq)
{
ppc_tb_t *tb_env;
- tb_env = g_malloc0(sizeof(ppc_tb_t));
+ tb_env = g_new0(ppc_tb_t, 1);
env->tb_env = tb_env;
tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
/* Create new timer */
@@ -1007,10 +1007,10 @@ clk_setup_cb ppc_40x_timers_init (CPUState *env, uint32_t freq,
ppc_tb_t *tb_env;
ppc40x_timer_t *ppc40x_timer;
- tb_env = g_malloc0(sizeof(ppc_tb_t));
+ tb_env = g_new0(ppc_tb_t, 1);
env->tb_env = tb_env;
tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
- ppc40x_timer = g_malloc0(sizeof(ppc40x_timer_t));
+ ppc40x_timer = g_new0(ppc40x_timer_t, 1);
tb_env->tb_freq = freq;
tb_env->decr_freq = freq;
tb_env->opaque = ppc40x_timer;
@@ -1115,7 +1115,7 @@ int ppc_dcr_init (CPUState *env, int (*read_error)(int dcrn),
{
ppc_dcr_t *dcr_env;
- dcr_env = g_malloc0(sizeof(ppc_dcr_t));
+ dcr_env = g_new0(ppc_dcr_t, 1);
dcr_env->read_error = read_error;
dcr_env->write_error = write_error;
env->dcr_env = dcr_env;
@@ -163,7 +163,7 @@ static void ref405ep_fpga_init (MemoryRegion *sysmem, uint32_t base)
ref405ep_fpga_t *fpga;
MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
- fpga = g_malloc0(sizeof(ref405ep_fpga_t));
+ fpga = g_new0(ref405ep_fpga_t, 1);
memory_region_init_io(fpga_memory, &ref405ep_fpga_ops, fpga,
"fpga", 0x00000100);
memory_region_add_subregion(sysmem, base, fpga_memory);
@@ -486,7 +486,7 @@ static void taihu_cpld_init (MemoryRegion *sysmem, uint32_t base)
taihu_cpld_t *cpld;
MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
- cpld = g_malloc0(sizeof(taihu_cpld_t));
+ cpld = g_new0(taihu_cpld_t, 1);
memory_region_init_io(cpld_memory, &taihu_cpld_ops, cpld, "cpld", 0x100);
memory_region_add_subregion(sysmem, base, cpld_memory);
qemu_register_reset(&taihu_cpld_reset, cpld);
@@ -173,7 +173,7 @@ static void ppc4xx_plb_init(CPUState *env)
{
ppc4xx_plb_t *plb;
- plb = g_malloc0(sizeof(ppc4xx_plb_t));
+ plb = g_new0(ppc4xx_plb_t, 1);
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);
@@ -249,7 +249,7 @@ static void ppc4xx_pob_init(CPUState *env)
{
ppc4xx_pob_t *pob;
- pob = g_malloc0(sizeof(ppc4xx_pob_t));
+ pob = g_new0(ppc4xx_pob_t, 1);
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);
@@ -380,7 +380,7 @@ static void ppc4xx_opba_init(target_phys_addr_t base)
{
ppc4xx_opba_t *opba;
- opba = g_malloc0(sizeof(ppc4xx_opba_t));
+ opba = g_new0(ppc4xx_opba_t, 1);
#ifdef DEBUG_OPBA
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
#endif
@@ -578,7 +578,7 @@ static void ppc405_ebc_init(CPUState *env)
{
ppc4xx_ebc_t *ebc;
- ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
+ ebc = g_new0(ppc4xx_ebc_t, 1);
qemu_register_reset(&ebc_reset, ebc);
ppc_dcr_register(env, EBC0_CFGADDR,
ebc, &dcr_read_ebc, &dcr_write_ebc);
@@ -661,7 +661,7 @@ static void ppc405_dma_init(CPUState *env, qemu_irq irqs[4])
{
ppc405_dma_t *dma;
- dma = g_malloc0(sizeof(ppc405_dma_t));
+ dma = g_new0(ppc405_dma_t, 1);
memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
qemu_register_reset(&ppc405_dma_reset, dma);
ppc_dcr_register(env, DMA0_CR0,
@@ -802,7 +802,7 @@ static void ppc405_gpio_init(target_phys_addr_t base)
{
ppc405_gpio_t *gpio;
- gpio = g_malloc0(sizeof(ppc405_gpio_t));
+ gpio = g_new0(ppc405_gpio_t, 1);
#ifdef DEBUG_GPIO
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
#endif
@@ -964,7 +964,7 @@ static void ppc405_ocm_init(CPUState *env)
{
ppc405_ocm_t *ocm;
- ocm = g_malloc0(sizeof(ppc405_ocm_t));
+ ocm = g_new0(ppc405_ocm_t, 1);
/* XXX: Size is 4096 or 0x04000000 */
memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4096);
memory_region_init_alias(&ocm->dsarc_ram, "ppc405.dsarc", &ocm->isarc_ram,
@@ -1210,7 +1210,7 @@ static void ppc405_i2c_init(target_phys_addr_t base, qemu_irq irq)
{
ppc4xx_i2c_t *i2c;
- i2c = g_malloc0(sizeof(ppc4xx_i2c_t));
+ i2c = g_new0(ppc4xx_i2c_t, 1);
i2c->irq = irq;
#ifdef DEBUG_I2C
printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
@@ -1486,7 +1486,7 @@ static void ppc4xx_gpt_init(target_phys_addr_t base, qemu_irq irqs[5])
ppc4xx_gpt_t *gpt;
int i;
- gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
+ gpt = g_new0(ppc4xx_gpt_t, 1);
for (i = 0; i < 5; i++) {
gpt->irqs[i] = irqs[i];
}
@@ -1717,7 +1717,7 @@ static void ppc405_mal_init(CPUState *env, qemu_irq irqs[4])
ppc40x_mal_t *mal;
int i;
- mal = g_malloc0(sizeof(ppc40x_mal_t));
+ mal = g_new0(ppc40x_mal_t, 1);
for (i = 0; i < 4; i++)
mal->irqs[i] = irqs[i];
qemu_register_reset(&ppc40x_mal_reset, mal);
@@ -2082,7 +2082,7 @@ static void ppc405cr_cpc_init (CPUState *env, clk_setup_t clk_setup[7],
{
ppc405cr_cpc_t *cpc;
- cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
+ cpc = g_new0(ppc405cr_cpc_t, 1);
memcpy(cpc->clk_setup, clk_setup,
PPC405CR_CLK_NB * sizeof(clk_setup_t));
cpc->sysclk = sysclk;
@@ -2130,7 +2130,7 @@ CPUState *ppc405cr_init(MemoryRegion *address_space_mem,
/* OBP arbitrer */
ppc4xx_opba_init(0xef600600);
/* Universal interrupt controller */
- irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+ irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
irqs[PPCUIC_OUTPUT_INT] =
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
irqs[PPCUIC_OUTPUT_CINT] =
@@ -2424,7 +2424,7 @@ static void ppc405ep_cpc_init (CPUState *env, clk_setup_t clk_setup[8],
{
ppc405ep_cpc_t *cpc;
- cpc = g_malloc0(sizeof(ppc405ep_cpc_t));
+ cpc = g_new0(ppc405ep_cpc_t, 1);
memcpy(cpc->clk_setup, clk_setup,
PPC405EP_CLK_NB * sizeof(clk_setup_t));
cpc->jtagid = 0x20267049;
@@ -2483,7 +2483,7 @@ CPUState *ppc405ep_init(MemoryRegion *address_space_mem,
/* OBP arbitrer */
ppc4xx_opba_init(0xef600600);
/* Universal interrupt controller */
- irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+ irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
irqs[PPCUIC_OUTPUT_INT] =
((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
irqs[PPCUIC_OUTPUT_CINT] =
@@ -58,7 +58,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,
ppc_dcr_init(env, NULL, NULL);
/* interrupt controller */
- irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+ irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
@@ -75,7 +75,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,
ram_bases, ram_sizes, do_init);
/* PCI */
- pci_irqs = g_malloc(sizeof(qemu_irq) * 4);
+ pci_irqs = g_new(qemu_irq, 4);
pci_irqs[0] = pic[pci_irq_nrs[0]];
pci_irqs[1] = pic[pci_irq_nrs[1]];
pci_irqs[2] = pic[pci_irq_nrs[2]];
@@ -294,7 +294,7 @@ qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs,
ppcuic_t *uic;
int i;
- uic = g_malloc0(sizeof(ppcuic_t));
+ uic = g_new0(ppcuic_t, 1);
uic->dcr_base = dcr_base;
uic->irqs = irqs;
if (has_vr)
@@ -642,7 +642,7 @@ void ppc4xx_sdram_init (CPUState *env, qemu_irq irq, int nbanks,
{
ppc4xx_sdram_t *sdram;
- sdram = g_malloc0(sizeof(ppc4xx_sdram_t));
+ sdram = g_new0(ppc4xx_sdram_t, 1);
sdram->irq = irq;
sdram->nbanks = nbanks;
sdram->ram_memories = ram_memories;
@@ -341,7 +341,7 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
static int ppc4xx_pci_id;
uint8_t *pci_conf;
- controller = g_malloc0(sizeof(PPC4xxPCIState));
+ controller = g_new0(PPC4xxPCIState, 1);
controller->pci_state.bus = pci_register_bus(NULL, "pci",
ppc4xx_pci_set_irq,
@@ -236,8 +236,8 @@ void ppc_booke_timers_init(CPUState *env, uint32_t freq, uint32_t flags)
ppc_tb_t *tb_env;
booke_timer_t *booke_timer;
- tb_env = g_malloc0(sizeof(ppc_tb_t));
- booke_timer = g_malloc0(sizeof(booke_timer_t));
+ tb_env = g_new0(ppc_tb_t, 1);
+ booke_timer = g_new0(booke_timer_t, 1);
env->tb_env = tb_env;
tb_env->flags = flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED;
@@ -266,7 +266,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
memory_region_init_io(unin_memory, &unin_ops, NULL, "unin", 0x1000);
memory_region_add_subregion(get_system_memory(), 0xf8000000, unin_memory);
- openpic_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+ openpic_irqs = g_new0(qemu_irq *, smp_cpus);
openpic_irqs[0] =
g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
for (i = 0; i < smp_cpus; i++) {
@@ -212,7 +212,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
isa_mmio_init(0xfe000000, 0x00200000);
/* XXX: we register only 1 output pin for heathrow PIC */
- heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+ heathrow_irqs = g_new0(qemu_irq *, smp_cpus);
heathrow_irqs[0] =
g_malloc0(smp_cpus * sizeof(qemu_irq) * 1);
/* Connect the heathrow PIC outputs to the 6xx bus */
@@ -550,7 +550,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
DriveInfo *fd[MAX_FD];
- sysctrl = g_malloc0(sizeof(sysctrl_t));
+ sysctrl = g_new0(sysctrl_t, 1);
linux_boot = (kernel_filename != NULL);
@@ -250,7 +250,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
cpu_model = "e500v2_v30";
}
- irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+ irqs = g_new0(qemu_irq *, smp_cpus);
irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
for (i = 0; i < smp_cpus; i++) {
qemu_irq *input;
@@ -276,7 +276,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
if (!i) {
/* Primary CPU */
struct boot_info *boot_info;
- boot_info = g_malloc0(sizeof(struct boot_info));
+ boot_info = g_new0(struct boot_info, 1);
qemu_register_reset(mpc8544ds_cpu_reset, env);
env->load_info = boot_info;
} else {
@@ -118,7 +118,7 @@ PCIBus *pci_prep_init(qemu_irq *pic,
PCIDevice *d;
int PPC_io_memory;
- s = g_malloc0(sizeof(PREPPCIState));
+ s = g_new0(PREPPCIState, 1);
s->bus = pci_register_bus(NULL, "pci",
prep_set_irq, prep_map_irq, pic,
address_space_mem,
@@ -461,7 +461,7 @@ static int pxa2xx_dma_init(SysBusDevice *dev)
return -1;
}
- s->chan = g_malloc0(sizeof(PXA2xxDMAChannel) * s->channels);
+ s->chan = g_new0(PXA2xxDMAChannel, s->channels);
memset(s->chan, 0, sizeof(PXA2xxDMAChannel) * s->channels);
for (i = 0; i < s->channels; i ++)
@@ -1700,7 +1700,7 @@ static int qxl_post_load(void *opaque, int version)
qxl_create_guest_primary(d, 1, QXL_SYNC);
/* replay surface-create and cursor-set commands */
- cmds = g_malloc0(sizeof(QXLCommandExt) * (NUM_SURFACES + 1));
+ cmds = g_new0(QXLCommandExt, (NUM_SURFACES + 1));
for (in = 0, out = 0; in < NUM_SURFACES; in++) {
if (d->guest_surfaces.cmds[in] == 0) {
continue;
@@ -185,7 +185,7 @@ static qemu_irq *r2d_fpga_init(target_phys_addr_t base, qemu_irq irl)
int iomemtype;
r2d_fpga_t *s;
- s = g_malloc0(sizeof(r2d_fpga_t));
+ s = g_new0(r2d_fpga_t, 1);
s->irl = irl;
@@ -246,7 +246,7 @@ static void r2d_init(ram_addr_t ram_size,
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
- reset_info = g_malloc0(sizeof(ResetData));
+ reset_info = g_new0(ResetData, 1);
reset_info->env = env;
reset_info->vector = env->pc;
qemu_register_reset(main_cpu_reset, reset_info);
@@ -806,7 +806,7 @@ void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus,
rc4030State *s;
int s_chipset, s_jazzio;
- s = g_malloc0(sizeof(rc4030State));
+ s = g_new0(rc4030State, 1);
*irqs = qemu_allocate_irqs(rc4030_irq_jazz_request, s, 16);
*dmas = rc4030_allocate_dmas(s, 4);
@@ -161,7 +161,7 @@ static void s390_init(ram_addr_t my_ram_size,
cpu_model = "host";
}
- ipi_states = g_malloc(sizeof(CPUState *) * smp_cpus);
+ ipi_states = g_new(CPUState *, smp_cpus);
for (i = 0; i < smp_cpus; i++) {
CPUState *tmp_env;
@@ -806,7 +806,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
{
SerialState *s;
- s = g_malloc0(sizeof(SerialState));
+ s = g_new0(SerialState, 1);
s->irq = irq;
s->baudbase = baudbase;
@@ -861,7 +861,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
{
SerialState *s;
- s = g_malloc0(sizeof(SerialState));
+ s = g_new0(SerialState, 1);
s->it_shift = it_shift;
s->irq = irq;
@@ -712,7 +712,7 @@ SH7750State *sh7750_init(CPUSH4State * cpu)
int sh7750_io_memory;
int sh7750_mm_cache_and_tlb; /* memory mapped cache and tlb */
- s = g_malloc0(sizeof(SH7750State));
+ s = g_new0(SH7750State, 1);
s->cpu = cpu;
s->periph_freq = 60000000; /* 60MHz */
sh7750_io_memory = cpu_register_io_memory(sh7750_mem_read,
@@ -361,7 +361,7 @@ void sh_serial_init (target_phys_addr_t base, int feat,
sh_serial_state *s;
int s_io_memory;
- s = g_malloc0(sizeof(sh_serial_state));
+ s = g_new0(sh_serial_state, 1);
s->feat = feat;
s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE;
@@ -381,7 +381,7 @@ static int slavio_timer_init1(SysBusDevice *dev)
TimerContext *tc;
for (i = 0; i <= MAX_CPUS; i++) {
- tc = g_malloc0(sizeof(TimerContext));
+ tc = g_new0(TimerContext, 1);
tc->s = s;
tc->timer_index = i;
@@ -1529,7 +1529,7 @@ StrongARMState *sa1110_init(unsigned int sdram_size, const char *rev)
qemu_irq *pic;
int i;
- s = g_malloc0(sizeof(StrongARMState));
+ s = g_new0(StrongARMState, 1);
if (!rev) {
rev = "sa1110-b5";
@@ -348,7 +348,7 @@ static CPUTimer* cpu_timer_create(const char* name, CPUState *env,
QEMUBHFunc *cb, uint32_t frequency,
uint64_t disabled_mask)
{
- CPUTimer *timer = g_malloc0(sizeof (CPUTimer));
+ CPUTimer *timer = g_new0(CPUTimer, 1);
timer->name = name;
timer->frequency = frequency;
@@ -720,7 +720,7 @@ static CPUState *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
env->hstick = cpu_timer_create("hstick", env, hstick_irq,
hstick_frequency, TICK_INT_DIS);
- reset_info = g_malloc0(sizeof(ResetData));
+ reset_info = g_new0(ResetData, 1);
reset_info->env = env;
reset_info->prom_addr = hwdef->prom_addr;
qemu_register_reset(main_cpu_reset, reset_info);
@@ -213,7 +213,7 @@ static int syborg_int_init(SysBusDevice *dev)
syborg_int_writefn, s,
DEVICE_NATIVE_ENDIAN);
sysbus_init_mmio(dev, 0x1000, iomemtype);
- s->flags = g_malloc0(s->num_irqs * sizeof(syborg_int_flags));
+ s->flags = g_new0(syborg_int_flags, s->num_irqs);
register_savevm(&dev->qdev, "syborg_int", -1, 1, syborg_int_save,
syborg_int_load, s);
@@ -168,7 +168,7 @@ typedef struct UHCI_QH {
static UHCIAsync *uhci_async_alloc(UHCIState *s)
{
- UHCIAsync *async = g_malloc(sizeof(UHCIAsync));
+ UHCIAsync *async = g_new(UHCIAsync, 1);
memset(&async->packet, 0, sizeof(async->packet));
async->uhci = s;
@@ -2394,7 +2394,7 @@ static DisplayChangeListener* vga_screen_dump_init(DisplayState *ds)
{
DisplayChangeListener *dcl;
- dcl = g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->dpy_update = vga_save_dpy_update;
dcl->dpy_resize = vga_save_dpy_resize;
dcl->dpy_refresh = vga_save_dpy_refresh;
@@ -98,7 +98,7 @@ static CPUState *ppc440_init_xilinx(ram_addr_t *ram_size,
ppc_dcr_init(env, NULL, NULL);
/* interrupt controller */
- irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+ irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
ppcuic_init(env, irqs, 0x0C0, 0, 1);
@@ -493,8 +493,8 @@ static int xenfb_map_fb(struct XenFB *xenfb)
n_fbdirs = xenfb->fbpages * mode / 8;
n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
- pgmfns = g_malloc0(sizeof(unsigned long) * n_fbdirs);
- fbmfns = g_malloc0(sizeof(unsigned long) * xenfb->fbpages);
+ pgmfns = g_new0(unsigned long, n_fbdirs);
+ fbmfns = g_new0(unsigned long, xenfb->fbpages);
xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
@@ -439,7 +439,7 @@ struct icp_state *xics_system_init(int nr_irqs)
icp = g_new0(struct icp_state, 1);
icp->nr_servers = max_server_num + 1;
- icp->ss = g_malloc0(icp->nr_servers*sizeof(struct icp_server_state));
+ icp->ss = g_new0(struct icp_server_state, icp->nr_servers);
for (i = 0; i < icp->nr_servers; i++) {
icp->ss[i].mfrr = 0xff;
@@ -467,7 +467,7 @@ struct icp_state *xics_system_init(int nr_irqs)
ics = g_new0(struct ics_state, 1);
ics->nr_irqs = nr_irqs;
ics->offset = 16;
- ics->irqs = g_malloc0(nr_irqs * sizeof(struct ics_irq_state));
+ ics->irqs = g_new0(struct ics_irq_state, nr_irqs);
icp->ics = ics;
ics->icp = icp;
@@ -96,7 +96,7 @@ static const MemoryRegionOps lx60_fpga_ops = {
static Lx60FpgaState *lx60_fpga_init(MemoryRegion *address_space,
target_phys_addr_t base)
{
- Lx60FpgaState *s = g_malloc(sizeof(Lx60FpgaState));
+ Lx60FpgaState *s = g_new(Lx60FpgaState, 1);
memory_region_init_io(&s->iomem, &lx60_fpga_ops, s,
"lx60-fpga", 0x10000);
@@ -73,7 +73,7 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
QEMUPutMouseEntry *s;
static int mouse_index = 0;
- s = g_malloc0(sizeof(QEMUPutMouseEntry));
+ s = g_new0(QEMUPutMouseEntry, 1);
s->qemu_put_mouse_event = func;
s->qemu_put_mouse_event_opaque = opaque;
@@ -111,7 +111,7 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
{
QEMUPutLEDEntry *s;
- s = g_malloc0(sizeof(QEMUPutLEDEntry));
+ s = g_new0(QEMUPutLEDEntry, 1);
s->put_led = func;
s->opaque = opaque;
@@ -67,7 +67,7 @@ int qemu_set_fd_handler2(int fd,
if (ioh->fd == fd)
goto found;
}
- ioh = g_malloc0(sizeof(IOHandlerRecord));
+ ioh = g_new0(IOHandlerRecord, 1);
QLIST_INSERT_HEAD(&io_handlers, ioh, next);
found:
ioh->fd = fd;
@@ -237,7 +237,7 @@ int qemu_add_child_watch(pid_t pid)
return 1;
}
}
- rec = g_malloc0(sizeof(ChildProcessRecord));
+ rec = g_new0(ChildProcessRecord, 1);
rec->pid = pid;
QLIST_INSERT_HEAD(&child_watches, rec, next);
return 0;
@@ -702,7 +702,7 @@ int kvm_init(void)
int ret;
int i;
- s = g_malloc0(sizeof(KVMState));
+ s = g_new0(KVMState, 1);
#ifdef KVM_CAP_SET_GUEST_DEBUG
QTAILQ_INIT(&s->kvm_sw_breakpoints);
@@ -1188,7 +1188,7 @@ int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,
return 0;
}
- bp = g_malloc(sizeof(struct kvm_sw_breakpoint));
+ bp = g_new(struct kvm_sw_breakpoint, 1);
if (!bp) {
return -ENOMEM;
}
@@ -3463,7 +3463,7 @@ int main(int argc, char **argv, char **envp)
}
target_argv[target_argc] = NULL;
- ts = g_malloc0 (sizeof(TaskState));
+ ts = g_new0(TaskState, 1);
init_task_state(ts);
/* build Task State */
ts->info = info;
@@ -4002,7 +4002,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
new_thread_info info;
pthread_attr_t attr;
#endif
- ts = g_malloc0(sizeof(TaskState));
+ ts = g_new0(TaskState, 1);
init_task_state(ts);
/* we create a new CPU instance. */
new_env = cpu_copy(env);
@@ -2673,7 +2673,7 @@ static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
return 0;
}
- monfd = g_malloc0(sizeof(mon_fd_t));
+ monfd = g_new0(mon_fd_t, 1);
monfd->name = g_strdup(fdname);
monfd->fd = fd;
@@ -640,7 +640,7 @@ VLANState *qemu_find_vlan(int id, int allocate)
return NULL;
}
- vlan = g_malloc0(sizeof(VLANState));
+ vlan = g_new0(VLANState, 1);
vlan->id = id;
QTAILQ_INIT(&vlan->clients);
@@ -63,7 +63,7 @@ NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver,
{
NetQueue *queue;
- queue = g_malloc0(sizeof(NetQueue));
+ queue = g_new0(NetQueue, 1);
queue->deliver = deliver;
queue->deliver_iov = deliver_iov;
@@ -614,7 +614,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
goto fail_syntax;
}
- fwd = g_malloc(sizeof(struct GuestFwd));
+ fwd = g_new(struct GuestFwd, 1);
snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port);
fwd->hd = qemu_chr_new(buf, p, NULL);
if (!fwd->hd) {
@@ -404,7 +404,7 @@ static int net_socket_listen_init(VLANState *vlan,
if (parse_host_port(&saddr, host_str) < 0)
return -1;
- s = g_malloc0(sizeof(NetSocketListenState));
+ s = g_new0(NetSocketListenState, 1);
fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
if (fd < 0) {
@@ -62,7 +62,7 @@ static PollingEntry *first_polling_entry;
int qemu_add_polling_cb(PollingFunc *func, void *opaque)
{
PollingEntry **ppe, *pe;
- pe = g_malloc0(sizeof(PollingEntry));
+ pe = g_new0(PollingEntry, 1);
pe->func = func;
pe->opaque = opaque;
for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
@@ -156,7 +156,7 @@ static void convert_generic(QemuPfConv *conv, void *dst, void *src, uint32_t cnt
QemuPfConv *qemu_pf_conv_get(PixelFormat *dst, PixelFormat *src)
{
- QemuPfConv *conv = g_malloc0(sizeof(QemuPfConv));
+ QemuPfConv *conv = g_new0(QemuPfConv, 1);
conv->src = *src;
conv->dst = *dst;
@@ -662,7 +662,7 @@ int paio_init(void)
if (posix_aio_state)
return 0;
- s = g_malloc(sizeof(PosixAioState));
+ s = g_new(PosixAioState, 1);
s->first_aio = NULL;
if (qemu_pipe(fds) == -1) {
@@ -222,7 +222,7 @@ static int qemu_chr_open_null(QemuOpts *opts, CharDriverState **_chr)
{
CharDriverState *chr;
- chr = g_malloc0(sizeof(CharDriverState));
+ chr = g_new0(CharDriverState, 1);
chr->chr_write = null_chr_write;
*_chr= chr;
@@ -471,8 +471,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
CharDriverState *chr;
MuxDriver *d;
- chr = g_malloc0(sizeof(CharDriverState));
- d = g_malloc0(sizeof(MuxDriver));
+ chr = g_new0(CharDriverState, 1);
+ d = g_new0(MuxDriver, 1);
chr->opaque = d;
d->drv = drv;
@@ -621,8 +621,8 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
CharDriverState *chr;
FDCharDriver *s;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(FDCharDriver));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(FDCharDriver, 1);
s->fd_in = fd_in;
s->fd_out = fd_out;
chr->opaque = s;
@@ -993,8 +993,8 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)
#define q_ptsname(x) ptsname(x)
#endif
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(PtyCharDriver));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(PtyCharDriver, 1);
if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) {
return -errno;
@@ -1373,11 +1373,11 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)
return -errno;
}
- drv = g_malloc0(sizeof(ParallelCharDriver));
+ drv = g_new0(ParallelCharDriver, 1);
drv->fd = fd;
drv->mode = IEEE1284_MODE_COMPAT;
- chr = g_malloc0(sizeof(CharDriverState));
+ chr = g_new0(CharDriverState, 1);
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
chr->chr_close = pp_close;
@@ -1439,7 +1439,7 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)
return -errno;
}
- chr = g_malloc0(sizeof(CharDriverState));
+ chr = g_new0(CharDriverState, 1);
chr->opaque = (void *)(intptr_t)fd;
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
@@ -1657,8 +1657,8 @@ static int qemu_chr_open_win(QemuOpts *opts, CharDriverState **_chr)
CharDriverState *chr;
WinCharState *s;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(WinCharState));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(WinCharState, 1);
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_close = win_chr_close;
@@ -1759,8 +1759,8 @@ static int qemu_chr_open_win_pipe(QemuOpts *opts, CharDriverState **_chr)
CharDriverState *chr;
WinCharState *s;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(WinCharState));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(WinCharState, 1);
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_close = win_chr_close;
@@ -1781,8 +1781,8 @@ static int qemu_chr_open_win_file(HANDLE fd_out, CharDriverState **pchr)
CharDriverState *chr;
WinCharState *s;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(WinCharState));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(WinCharState, 1);
s->hcom = fd_out;
chr->opaque = s;
chr->chr_write = win_chr_write;
@@ -1895,8 +1895,8 @@ static int qemu_chr_open_udp(QemuOpts *opts, CharDriverState **_chr)
int fd = -1;
int ret;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(NetCharDriver));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(NetCharDriver, 1);
fd = inet_dgram_opts(opts);
if (fd < 0) {
@@ -2233,8 +2233,8 @@ static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr)
if (!is_listen)
is_waitconnect = 0;
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(TCPCharDriver));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(TCPCharDriver, 1);
if (is_unix) {
if (is_listen) {
@@ -610,7 +610,7 @@ int main(int argc, char **argv)
become_daemon(pidfile);
}
- s = g_malloc0(sizeof(GAState));
+ s = g_new0(GAState, 1);
s->conn_channel = NULL;
s->path = path;
s->method = method;
@@ -750,7 +750,7 @@ static int img_convert(int argc, char **argv)
qemu_progress_init(progress, 2.0);
qemu_progress_print(0, 100);
- bs = g_malloc0(bs_n * sizeof(BlockDriverState *));
+ bs = g_new0(BlockDriverState *, bs_n);
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
@@ -430,7 +430,7 @@ int main(int argc, char **argv)
/* children */
}
- sharing_fds = g_malloc((shared + 1) * sizeof(int));
+ sharing_fds = g_new(int, (shared + 1));
if (socket) {
sharing_fds[0] = unix_socket_incoming(socket);
@@ -364,7 +364,7 @@ static QEMUClock *qemu_new_clock(int type)
{
QEMUClock *clock;
- clock = g_malloc0(sizeof(QEMUClock));
+ clock = g_new0(QEMUClock, 1);
clock->type = type;
clock->enabled = 1;
notifier_list_init(&clock->reset_notifiers);
@@ -469,7 +469,7 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
{
QEMUTimer *ts;
- ts = g_malloc0(sizeof(QEMUTimer));
+ ts = g_new0(QEMUTimer, 1);
ts->clock = clock;
ts->cb = cb;
ts->opaque = opaque;
@@ -27,7 +27,7 @@ void ga_command_state_add(GACommandState *cs,
void (*init)(void),
void (*cleanup)(void))
{
- GACommandGroup *cg = g_malloc0(sizeof(GACommandGroup));
+ GACommandGroup *cg = g_new0(GACommandGroup, 1);
cg->init = init;
cg->cleanup = cleanup;
cs->groups = g_slist_append(cs->groups, cg);
@@ -67,7 +67,7 @@ void ga_command_state_cleanup_all(GACommandState *cs)
GACommandState *ga_command_state_new(void)
{
- GACommandState *cs = g_malloc0(sizeof(GACommandState));
+ GACommandState *cs = g_new0(GACommandState, 1);
cs->groups = NULL;
return cs;
}
@@ -56,7 +56,7 @@ void qmp_guest_ping(Error **err)
struct GuestAgentInfo *qmp_guest_info(Error **err)
{
- GuestAgentInfo *info = g_malloc0(sizeof(GuestAgentInfo));
+ GuestAgentInfo *info = g_new0(GuestAgentInfo, 1);
info->version = g_strdup(QGA_VERSION);
@@ -114,7 +114,7 @@ static void guest_file_handle_add(FILE *fh)
{
GuestFileHandle *gfh;
- gfh = g_malloc0(sizeof(GuestFileHandle));
+ gfh = g_new0(GuestFileHandle, 1);
gfh->id = fileno(fh);
gfh->fh = fh;
QTAILQ_INSERT_TAIL(&guest_file_state.filehandles, gfh, next);
@@ -217,7 +217,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
error_set(err, QERR_QGA_COMMAND_FAILED, "fread() failed");
} else {
buf[read_count] = 0;
- read_data = g_malloc0(sizeof(GuestFileRead));
+ read_data = g_new0(GuestFileRead, 1);
read_data->count = read_count;
read_data->eof = feof(fh);
if (read_count) {
@@ -261,7 +261,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
slog("guest-file-write failed, handle: %ld", handle);
error_set(err, QERR_QGA_COMMAND_FAILED, "fwrite() error");
} else {
- write_data = g_malloc0(sizeof(GuestFileWrite));
+ write_data = g_new0(GuestFileWrite, 1);
write_data->count = write_count;
write_data->eof = feof(fh);
}
@@ -379,7 +379,7 @@ static int guest_fsfreeze_build_mount_list(void)
continue;
}
- mount = g_malloc0(sizeof(GuestFsfreezeMount));
+ mount = g_new0(GuestFsfreezeMount, 1);
mount->dirname = g_strdup(ment->mnt_dir);
mount->devtype = g_strdup(ment->mnt_type);
@@ -255,7 +255,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode)
return NULL;
}
- s = g_malloc0(sizeof(QEMUFileStdio));
+ s = g_new0(QEMUFileStdio, 1);
s->stdio_file = stdio_file;
@@ -303,7 +303,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
return NULL;
}
- s = g_malloc0(sizeof(QEMUFileStdio));
+ s = g_new0(QEMUFileStdio, 1);
s->stdio_file = fdopen(fd, mode);
if (!s->stdio_file)
goto fail;
@@ -324,7 +324,7 @@ fail:
QEMUFile *qemu_fopen_socket(int fd)
{
- QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
+ QEMUFileSocket *s = g_new0(QEMUFileSocket, 1);
s->fd = fd;
s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close,
@@ -358,7 +358,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
return NULL;
}
- s = g_malloc0(sizeof(QEMUFileStdio));
+ s = g_new0(QEMUFileStdio, 1);
s->stdio_file = fopen(filename, mode);
if (!s->stdio_file)
@@ -411,7 +411,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
{
QEMUFile *f;
- f = g_malloc0(sizeof(QEMUFile));
+ f = g_new0(QEMUFile, 1);
f->opaque = opaque;
f->put_buffer = put_buffer;
@@ -1114,7 +1114,7 @@ int register_savevm_live(DeviceState *dev,
{
SaveStateEntry *se;
- se = g_malloc0(sizeof(SaveStateEntry));
+ se = g_new0(SaveStateEntry, 1);
se->version_id = version_id;
se->section_id = global_section_id++;
se->set_params = set_params;
@@ -1225,7 +1225,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
/* If this triggers, alias support can be dropped for the vmsd. */
assert(alias_id == -1 || required_for_version >= vmsd->minimum_version_id);
- se = g_malloc0(sizeof(SaveStateEntry));
+ se = g_new0(SaveStateEntry, 1);
se->version_id = vmsd->version_id;
se->section_id = global_section_id++;
se->save_live_state = NULL;
@@ -2141,7 +2141,7 @@ void do_info_snapshots(Monitor *mon)
return;
}
- available_snapshots = g_malloc0(sizeof(int) * nb_sns);
+ available_snapshots = g_new0(int, nb_sns);
total = 0;
for (i = 0; i < nb_sns; i++) {
sn = &sn_tab[i];
@@ -202,7 +202,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, void *opaque)
{
- Slirp *slirp = g_malloc0(sizeof(Slirp));
+ Slirp *slirp = g_new0(Slirp, 1);
slirp_init_once();
@@ -185,8 +185,8 @@ int qemu_chr_open_spice(QemuOpts *opts, CharDriverState **_chr)
return -EINVAL;
}
- chr = g_malloc0(sizeof(CharDriverState));
- s = g_malloc0(sizeof(SpiceCharDriver));
+ chr = g_new0(CharDriverState, 1);
+ s = g_new0(SpiceCharDriver, 1);
s->chr = chr;
s->debug = debug;
s->active = false;
@@ -3494,7 +3494,7 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
CPUAlphaState *env;
int implver, amask, i, max;
- env = g_malloc0(sizeof(CPUAlphaState));
+ env = g_new0(CPUAlphaState, 1);
cpu_exec_init(env);
alpha_translate_init();
tlb_flush(env, 1);
@@ -384,7 +384,7 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
id = cpu_arm_find_by_name(cpu_model);
if (id == 0)
return NULL;
- env = g_malloc0(sizeof(CPUARMState));
+ env = g_new0(CPUARMState, 1);
cpu_exec_init(env);
if (!inited) {
inited = 1;
@@ -3516,7 +3516,7 @@ CPUCRISState *cpu_cris_init (const char *cpu_model)
static int tcg_initialized = 0;
int i;
- env = g_malloc0(sizeof(CPUCRISState));
+ env = g_new0(CPUCRISState, 1);
env->pregs[PR_VR] = vr_by_name(cpu_model);
cpu_exec_init(env);
@@ -1009,7 +1009,7 @@ static int cpudef_setfield(const char *name, const char *str, void *opaque)
*/
static int cpudef_register(QemuOpts *opts, void *opaque)
{
- x86_def_t *def = g_malloc0(sizeof (x86_def_t));
+ x86_def_t *def = g_new0(x86_def_t, 1);
qemu_opt_foreach(opts, cpudef_setfield, def, 1);
def->next = x86_defs;
@@ -1239,7 +1239,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
CPUX86State *env;
static int inited;
- env = g_malloc0(sizeof(CPUX86State));
+ env = g_new0(CPUX86State, 1);
cpu_exec_init(env);
env->cpu_model_str = cpu_model;
@@ -201,7 +201,7 @@ static void kvm_hwpoison_page_add(ram_addr_t ram_addr)
return;
}
}
- page = g_malloc(sizeof(HWPoisonPage));
+ page = g_new(HWPoisonPage, 1);
page->ram_addr = ram_addr;
QLIST_INSERT_HEAD(&hwpoison_page_list, page, list);
}
@@ -208,7 +208,7 @@ CPUState *cpu_lm32_init(const char *cpu_model)
return NULL;
}
- env = g_malloc0(sizeof(CPUState));
+ env = g_new0(CPUState, 1);
env->features = def->features;
env->num_bps = def->num_breakpoints;
@@ -172,7 +172,7 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model)
CPUM68KState *env;
static int inited;
- env = g_malloc0(sizeof(CPUM68KState));
+ env = g_new0(CPUM68KState, 1);
cpu_exec_init(env);
if (!inited) {
inited = 1;
@@ -1851,7 +1851,7 @@ CPUState *cpu_mb_init (const char *cpu_model)
static int tcg_initialized = 0;
int i;
- env = g_malloc0(sizeof(CPUState));
+ env = g_new0(CPUState, 1);
cpu_exec_init(env);
cpu_reset(env);
@@ -12704,7 +12704,7 @@ CPUMIPSState *cpu_mips_init (const char *cpu_model)
def = cpu_mips_find_by_name(cpu_model);
if (!def)
return NULL;
- env = g_malloc0(sizeof(CPUMIPSState));
+ env = g_new0(CPUMIPSState, 1);
env->cpu_model = def;
env->cpu_model_str = cpu_model;
@@ -3184,7 +3184,7 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
if (!def)
return NULL;
- env = g_malloc0(sizeof(CPUPPCState));
+ env = g_new0(CPUPPCState, 1);
cpu_exec_init(env);
if (tcg_enabled()) {
ppc_translate_init();
@@ -79,7 +79,7 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
static int inited = 0;
static int cpu_num = 0;
- env = g_malloc0(sizeof(CPUS390XState));
+ env = g_new0(CPUS390XState, 1);
cpu_exec_init(env);
if (tcg_enabled() && !inited) {
inited = 1;
@@ -279,7 +279,7 @@ CPUSH4State *cpu_sh4_init(const char *cpu_model)
def = cpu_sh4_find_by_name(cpu_model);
if (!def)
return NULL;
- env = g_malloc0(sizeof(CPUSH4State));
+ env = g_new0(CPUSH4State, 1);
env->features = def->features;
cpu_exec_init(env);
env->movcal_backup_tail = &(env->movcal_backup);
@@ -1208,7 +1208,7 @@ CPUSPARCState *cpu_sparc_init(const char *cpu_model)
{
CPUSPARCState *env;
- env = g_malloc0(sizeof(CPUSPARCState));
+ env = g_new0(CPUSPARCState, 1);
cpu_exec_init(env);
gen_intermediate_code_init(env);
@@ -53,7 +53,7 @@ CPUState *uc32_cpu_init(const char *cpu_model)
uint32_t id;
static int inited = 1;
- env = g_malloc0(sizeof(CPUState));
+ env = g_new0(CPUState, 1);
cpu_exec_init(env);
id = uc32_cpu_find_by_name(cpu_model);
@@ -243,8 +243,8 @@ void tcg_context_init(TCGContext *s)
total_args += n;
}
- args_ct = g_malloc(sizeof(TCGArgConstraint) * total_args);
- sorted_args = g_malloc(sizeof(int) * total_args);
+ args_ct = g_new(TCGArgConstraint, total_args);
+ sorted_args = g_new(int, total_args);
for(op = 0; op < NB_OPS; op++) {
def = &tcg_op_defs[op];
@@ -15,15 +15,15 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp)
UserDefTwo * qmp_user_def_cmd2(UserDefOne * ud1a, UserDefOne * ud1b, Error **errp)
{
UserDefTwo *ret;
- UserDefOne *ud1c = g_malloc0(sizeof(UserDefOne));
- UserDefOne *ud1d = g_malloc0(sizeof(UserDefOne));
+ UserDefOne *ud1c = g_new0(UserDefOne, 1);
+ UserDefOne *ud1d = g_new0(UserDefOne, 1);
ud1c->string = strdup(ud1a->string);
ud1c->integer = ud1a->integer;
ud1d->string = strdup(ud1b->string);
ud1d->integer = ud1b->integer;
- ret = g_malloc0(sizeof(UserDefTwo));
+ ret = g_new0(UserDefTwo, 1);
ret->string = strdup("blah1");
ret->dict.string = strdup("blah2");
ret->dict.dict.userdef = ud1c;
@@ -104,21 +104,21 @@ static void test_dealloc_types(void)
UserDefOne *ud1test, *ud1a, *ud1b;
UserDefOneList *ud1list;
- ud1test = g_malloc0(sizeof(UserDefOne));
+ ud1test = g_new0(UserDefOne, 1);
ud1test->integer = 42;
ud1test->string = g_strdup("hi there 42");
qapi_free_UserDefOne(ud1test);
- ud1a = g_malloc0(sizeof(UserDefOne));
+ ud1a = g_new0(UserDefOne, 1);
ud1a->integer = 43;
ud1a->string = g_strdup("hi there 43");
- ud1b = g_malloc0(sizeof(UserDefOne));
+ ud1b = g_new0(UserDefOne, 1);
ud1b->integer = 44;
ud1b->string = g_strdup("hi there 44");
- ud1list = g_malloc0(sizeof(UserDefOneList));
+ ud1list = g_new0(UserDefOneList, 1);
ud1list->value = ud1a;
ud1list->next = g_malloc0(sizeof(UserDefOneList));
ud1list->next->value = ud1b;
@@ -282,7 +282,7 @@ static void test_nested_enums(void)
QObject *obj;
QString *str;
- nested_enums = g_malloc0(sizeof(NestedEnumsOne));
+ nested_enums = g_new0(NestedEnumsOne, 1);
nested_enums->enum1 = ENUM_ONE_VALUE1;
nested_enums->enum2 = ENUM_ONE_VALUE2;
nested_enums->enum3 = ENUM_ONE_VALUE3;
@@ -94,7 +94,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
if (!k)
- k = g_malloc0(sizeof(kbd_layout_t));
+ k = g_new0(kbd_layout_t, 1);
if (!(filename && (f = fopen(filename, "r")))) {
fprintf(stderr,
"Could not read keymap file: '%s'\n", language);
@@ -1019,7 +1019,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
sdl_grab_start();
}
- dcl = g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->dpy_update = sdl_update;
dcl->dpy_resize = sdl_resize;
dcl->dpy_refresh = sdl_refresh;
@@ -1029,7 +1029,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
ds->cursor_define = sdl_mouse_define;
register_displaychangelistener(ds, dcl);
- da = g_malloc0(sizeof(DisplayAllocator));
+ da = g_new0(DisplayAllocator, 1);
da->create_displaysurface = sdl_create_displaysurface;
da->resize_displaysurface = sdl_resize_displaysurface;
da->free_displaysurface = sdl_free_displaysurface;
@@ -77,7 +77,7 @@ static void vnc_unlock_queue(VncJobQueue *queue)
VncJob *vnc_job_new(VncState *vs)
{
- VncJob *job = g_malloc0(sizeof(VncJob));
+ VncJob *job = g_new0(VncJob, 1);
job->vs = vs;
vnc_lock_queue(queue);
@@ -88,7 +88,7 @@ VncJob *vnc_job_new(VncState *vs)
int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h)
{
- VncRectEntry *entry = g_malloc0(sizeof(VncRectEntry));
+ VncRectEntry *entry = g_new0(VncRectEntry, 1);
entry->rect.x = x;
entry->rect.y = y;
@@ -282,7 +282,7 @@ disconnected:
static VncJobQueue *vnc_queue_init(void)
{
- VncJobQueue *queue = g_malloc0(sizeof(VncJobQueue));
+ VncJobQueue *queue = g_new0(VncJobQueue, 1);
qemu_cond_init(&queue->cond);
qemu_mutex_init(&queue->mutex);
@@ -2496,7 +2496,7 @@ static void vnc_remove_timer(VncDisplay *vd)
static void vnc_connect(VncDisplay *vd, int csock, int skipauth)
{
- VncState *vs = g_malloc0(sizeof(VncState));
+ VncState *vs = g_new0(VncState, 1);
int i;
vs->csock = csock;
@@ -2578,7 +2578,7 @@ void vnc_display_init(DisplayState *ds)
{
VncDisplay *vs = g_new0(VncDisplay, 1);
- dcl = g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
ds->opaque = vs;
dcl->idle = 1;
@@ -287,7 +287,7 @@ struct AsyncURB
static AsyncURB *async_alloc(USBHostDevice *s)
{
- AsyncURB *aurb = g_malloc0(sizeof(AsyncURB));
+ AsyncURB *aurb = g_new0(AsyncURB, 1);
aurb->hdev = s;
QLIST_INSERT_HEAD(&s->aurbs, aurb, next);
return aurb;
@@ -286,7 +286,7 @@ static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)
static struct buf_packet *bufp_alloc(USBRedirDevice *dev,
uint8_t *data, int len, int status, uint8_t ep)
{
- struct buf_packet *bufp = g_malloc(sizeof(struct buf_packet));
+ struct buf_packet *bufp = g_new(struct buf_packet, 1);
bufp->data = data;
bufp->len = len;
bufp->status = status;
@@ -564,7 +564,7 @@ static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
if (vlan->id == id)
return &vlan->net;
}
- vlan = g_malloc0(sizeof(struct bt_vlan_s));
+ vlan = g_new0(struct bt_vlan_s, 1);
vlan->id = id;
pvlan = &first_bt_vlan;
while (*pvlan != NULL)
@@ -853,7 +853,7 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,
assert(dev != NULL || suffix != NULL);
- node = g_malloc0(sizeof(FWBootEntry));
+ node = g_new0(FWBootEntry, 1);
node->bootindex = bootindex;
node->suffix = suffix ? g_strdup(suffix) : NULL;
node->dev = dev;
@@ -1112,7 +1112,7 @@ void pcmcia_socket_register(PCMCIASocket *socket)
{
struct pcmcia_socket_entry_s *entry;
- entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
+ entry = g_new(struct pcmcia_socket_entry_s, 1);
entry->socket = socket;
entry->next = pcmcia_sockets;
pcmcia_sockets = entry;
@@ -1339,7 +1339,7 @@ static bool qemu_vmstop_requested(RunState *r)
void qemu_register_reset(QEMUResetHandler *func, void *opaque)
{
- QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
+ QEMUResetEntry *re = g_new0(QEMUResetEntry, 1);
re->func = func;
re->opaque = opaque;
@@ -267,7 +267,7 @@ go_physmap:
}
}
- physmap = g_malloc(sizeof (XenPhysmap));
+ physmap = g_new(XenPhysmap, 1);
physmap->start_addr = start_addr;
physmap->size = size;
@@ -890,7 +890,7 @@ int xen_hvm_init(void)
unsigned long ioreq_pfn;
XenIOState *state;
- state = g_malloc0(sizeof (XenIOState));
+ state = g_new0(XenIOState, 1);
state->xce_handle = xen_xc_evtchn_open(NULL, 0);
if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
@@ -94,7 +94,7 @@ void xen_map_cache_init(void)
unsigned long size;
struct rlimit rlimit_as;
- mapcache = g_malloc0(sizeof (MapCache));
+ mapcache = g_new0(MapCache, 1);
QTAILQ_INIT(&mapcache->locked_entries);
mapcache->last_address_index = -1;
@@ -145,8 +145,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,
trace_xen_remap_bucket(address_index);
- pfns = g_malloc0(nb_pfn * sizeof (xen_pfn_t));
- err = g_malloc0(nb_pfn * sizeof (int));
+ pfns = g_new0(xen_pfn_t, nb_pfn);
+ err = g_new0(int, nb_pfn);
if (entry->vaddr_base != NULL) {
if (munmap(entry->vaddr_base, entry->size) != 0) {
@@ -220,7 +220,7 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
entry = entry->next;
}
if (!entry) {
- entry = g_malloc0(sizeof (MapCacheEntry));
+ entry = g_new0(MapCacheEntry, 1);
pentry->next = entry;
xen_remap_bucket(entry, __size, address_index);
} else if (!entry->lock) {
@@ -242,7 +242,7 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
mapcache->last_address_index = address_index;
mapcache->last_address_vaddr = entry->vaddr_base;
if (lock) {
- MapCacheRev *reventry = g_malloc0(sizeof(MapCacheRev));
+ MapCacheRev *reventry = g_new0(MapCacheRev, 1);
entry->lock++;
reventry->vaddr_req = mapcache->last_address_vaddr + address_offset;
reventry->paddr_index = mapcache->last_address_index;
Convert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the size passed to g_malloc() is specified in terms of sizeof(type) where the result is assigned to a variable of the same type. This was achieved using Coccinelle with the following semantic patch: @@ type T; T *E; @@ -E = g_malloc(sizeof(T)) +E = g_new(T, 1) @@ type T; T *E; @@ -E = g_malloc0(sizeof(T)) +E = g_new0(T, 1) @@ type T; T *E; expression N; @@ -E = g_malloc(sizeof(T) * N) +E = g_new(T, N) @@ type T; T *E; expression N; @@ -E = g_malloc0(sizeof(T) * N) +E = g_new0(T, N) Signed-off-by: Stuart Brady <sdb@zubnet.me.uk> --- aio.c | 2 +- async.c | 2 +- block-migration.c | 6 ++-- block.c | 2 +- block/qcow.c | 4 +- block/qcow2-cluster.c | 2 +- block/qcow2-refcount.c | 4 +- block/qcow2-snapshot.c | 6 ++-- block/rbd.c | 4 +- block/sheepdog.c | 2 +- block/vdi.c | 2 +- block/vmdk.c | 3 +- bt-host.c | 2 +- bt-vhci.c | 2 +- console.c | 8 +++--- cutils.c | 2 +- exec.c | 10 ++++---- gdbstub.c | 4 +- hw/9pfs/virtio-9p-handle.c | 2 +- hw/9pfs/virtio-9p.c | 6 ++-- hw/adb.c | 4 +- hw/applesmc.c | 2 +- hw/baum.c | 4 +- hw/bitbang_i2c.c | 2 +- hw/blizzard.c | 3 +- hw/bt-hci.c | 4 +- hw/bt-l2cap.c | 4 +- hw/bt.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dp8393x.c | 2 +- hw/heathrow_pic.c | 2 +- hw/i8259.c | 2 +- hw/ide/macio.c | 2 +- hw/ide/mmio.c | 2 +- hw/irq.c | 2 +- hw/ivshmem.c | 6 ++-- hw/jazz_led.c | 2 +- hw/leon3.c | 2 +- hw/lm32_boards.c | 4 +- hw/lm32_hwsetup.h | 2 +- hw/mac_dbdma.c | 2 +- hw/mac_nvram.c | 2 +- hw/mcf_intc.c | 2 +- hw/mcf_uart.c | 2 +- hw/milkymist.c | 2 +- hw/mips_mipssim.c | 2 +- hw/mips_r4k.c | 2 +- hw/msmouse.c | 2 +- hw/omap.h | 2 +- hw/omap_gpio.c | 4 +- hw/omap_l4.c | 2 +- hw/parallel.c | 2 +- hw/pckbd.c | 2 +- hw/pflash_cfi01.c | 2 +- hw/pflash_cfi02.c | 2 +- hw/ppc.c | 8 +++--- hw/ppc405_boards.c | 4 +- hw/ppc405_uc.c | 28 +++++++++++++------------- hw/ppc440.c | 4 +- hw/ppc4xx_devs.c | 4 +- hw/ppc4xx_pci.c | 2 +- hw/ppc_booke.c | 4 +- hw/ppc_newworld.c | 2 +- hw/ppc_oldworld.c | 2 +- hw/ppc_prep.c | 2 +- hw/ppce500_mpc8544ds.c | 4 +- hw/prep_pci.c | 2 +- hw/pxa2xx_dma.c | 2 +- hw/qxl.c | 2 +- hw/r2d.c | 4 +- hw/rc4030.c | 2 +- hw/s390-virtio.c | 2 +- hw/serial.c | 4 +- hw/sh7750.c | 2 +- hw/sh_serial.c | 2 +- hw/slavio_timer.c | 2 +- hw/strongarm.c | 2 +- hw/sun4u.c | 4 +- hw/syborg_interrupt.c | 2 +- hw/usb-uhci.c | 2 +- hw/vga.c | 2 +- hw/virtex_ml507.c | 2 +- hw/xenfb.c | 4 +- hw/xics.c | 4 +- hw/xtensa_lx60.c | 2 +- input.c | 4 +- iohandler.c | 4 +- kvm-all.c | 4 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- monitor.c | 2 +- net.c | 2 +- net/queue.c | 2 +- net/slirp.c | 2 +- net/socket.c | 2 +- os-win32.c | 2 +- pflib.c | 2 +- posix-aio-compat.c | 2 +- qemu-char.c | 40 +++++++++++++++++++------------------- qemu-ga.c | 2 +- qemu-img.c | 2 +- qemu-nbd.c | 2 +- qemu-timer.c | 4 +- qga/guest-agent-command-state.c | 4 +- qga/guest-agent-commands.c | 10 ++++---- savevm.c | 16 +++++++------- slirp/slirp.c | 2 +- spice-qemu-char.c | 4 +- target-alpha/translate.c | 2 +- target-arm/helper.c | 2 +- target-cris/translate.c | 2 +- target-i386/cpuid.c | 2 +- target-i386/helper.c | 2 +- target-i386/kvm.c | 2 +- target-lm32/helper.c | 2 +- target-m68k/helper.c | 2 +- target-microblaze/translate.c | 2 +- target-mips/translate.c | 2 +- target-ppc/helper.c | 2 +- target-s390x/helper.c | 2 +- target-sh4/translate.c | 2 +- target-sparc/helper.c | 2 +- target-unicore32/helper.c | 2 +- tcg/tcg.c | 4 +- test-qmp-commands.c | 14 ++++++------ test-visitor.c | 2 +- ui/keymaps.c | 2 +- ui/sdl.c | 4 +- ui/vnc-jobs-async.c | 6 ++-- ui/vnc.c | 4 +- usb-linux.c | 2 +- usb-redir.c | 2 +- vl.c | 8 +++--- xen-all.c | 4 +- xen-mapcache.c | 10 ++++---- 135 files changed, 241 insertions(+), 243 deletions(-)