@@ -55,7 +55,7 @@ qemu_acl *qemu_acl_init(const char *aclname)
if (acl)
return acl;
- acl = g_malloc(sizeof(*acl));
+ acl = g_new(qemu_acl, 1);
acl->aclname = g_strdup(aclname);
/* Deny by default, so there is no window of "open
* access" between QEMU starting, and the user setting
@@ -116,7 +116,7 @@ int qemu_acl_append(qemu_acl *acl,
{
qemu_acl_entry *entry;
- entry = g_malloc(sizeof(*entry));
+ entry = g_new(qemu_acl_entry, 1);
entry->match = g_strdup(match);
entry->deny = deny;
@@ -142,7 +142,7 @@ int qemu_acl_insert(qemu_acl *acl,
return qemu_acl_append(acl, deny, match);
- entry = g_malloc(sizeof(*entry));
+ entry = g_new(qemu_acl_entry, 1);
entry->match = g_strdup(match);
entry->deny = deny;
@@ -237,7 +237,7 @@ static void sort_ram_list(void)
QLIST_FOREACH(block, &ram_list.blocks, next) {
++n;
}
- blocks = g_malloc(n * sizeof *blocks);
+ blocks = g_new(RAMBlock *, n);
n = 0;
QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
blocks[n++] = block;
@@ -143,7 +143,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
ops.capture = wav_capture;
ops.destroy = wav_destroy;
- wav = g_malloc0 (sizeof (*wav));
+ wav = g_new0(WAVState, 1);
shift = bits16 + stereo;
hdr[34] = bits16 ? 0x10 : 0x08;
@@ -2472,7 +2472,7 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs,
if (merge) {
size_t size;
- QEMUIOVector *qiov = g_malloc0(sizeof(*qiov));
+ QEMUIOVector *qiov = g_new0(QEMUIOVector, 1);
qemu_iovec_init(qiov,
reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1);
@@ -214,7 +214,7 @@ static int add_rule(QemuOpts *opts, void *opaque)
}
/* Set attributes common for all actions */
- rule = g_malloc0(sizeof(*rule));
+ rule = g_new0(struct BlkdebugRule, 1);
*rule = (struct BlkdebugRule) {
.event = event,
.action = d->action,
@@ -49,7 +49,7 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
Qcow2Cache *c;
int i;
- c = g_malloc0(sizeof(*c));
+ c = g_new0(Qcow2Cache, 1);
c->size = num_tables;
c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
c->writethrough = writethrough;
@@ -152,7 +152,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,
return;
}
- find_cluster_cb = g_malloc(sizeof(*find_cluster_cb));
+ find_cluster_cb = g_new(QEDFindClusterCB, 1);
find_cluster_cb->s = s;
find_cluster_cb->pos = pos;
find_cluster_cb->len = len;
@@ -89,7 +89,7 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache)
{
CachedL2Table *entry;
- entry = g_malloc0(sizeof(*entry));
+ entry = g_new0(CachedL2Table, 1);
entry->ref++;
trace_qed_alloc_l2_cache_entry(l2_cache, entry);
@@ -800,7 +800,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
int max_snaps = RBD_MAX_SNAPS;
do {
- snaps = g_malloc(sizeof(*snaps) * max_snaps);
+ snaps = g_new(rbd_snap_info_t, max_snaps);
snap_count = rbd_snap_list(s->image, snaps, &max_snaps);
if (snap_count < 0) {
g_free(snaps);
@@ -369,7 +369,7 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb,
{
AIOReq *aio_req;
- aio_req = g_malloc(sizeof(*aio_req));
+ aio_req = g_new(AIOReq, 1);
aio_req->aiocb = acb;
aio_req->iov_offset = iov_offset;
aio_req->oid = oid;
@@ -1956,7 +1956,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
goto out;
}
- sn_tab = g_malloc0(nr * sizeof(*sn_tab));
+ sn_tab = g_new0(QEMUSnapshotInfo, nr);
/* calculate a vdi id with hash function */
hval = fnv_64a_buf(s->name, strlen(s->name), FNV1A_64_INIT);
@@ -432,7 +432,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
/* init */
- dinfo = g_malloc0(sizeof(*dinfo));
+ dinfo = g_new0(DriveInfo, 1);
if ((buf = qemu_opts_id(opts)) != NULL) {
dinfo->id = g_strdup(buf);
} else {
@@ -259,7 +259,7 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
{
QEMUFileBuffered *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(QEMUFileBuffered, 1);
s->opaque = opaque;
s->xfer_limit = bytes_per_sec / 10;
@@ -71,7 +71,7 @@ Coroutine *qemu_coroutine_new(void)
{
CoroutineGThread *co;
- co = g_malloc0(sizeof(*co));
+ co = g_new0(CoroutineGThread, 1);
co->thread = g_thread_create_full(coroutine_thread, co, 0, TRUE, TRUE,
G_THREAD_PRIORITY_NORMAL, NULL);
if (!co->thread) {
@@ -115,7 +115,7 @@ Coroutine *qemu_coroutine_self(void)
CoroutineGThread *co = g_static_private_get(&coroutine_key);
if (!co) {
- co = g_malloc0(sizeof(*co));
+ co = g_new0(CoroutineGThread, 1);
co->runnable = true;
g_static_private_set(&coroutine_key, co, (GDestroyNotify)g_free);
}
@@ -73,7 +73,7 @@ static CoroutineThreadState *coroutine_get_thread_state(void)
CoroutineThreadState *s = pthread_getspecific(thread_state_key);
if (!s) {
- s = g_malloc0(sizeof(*s));
+ s = g_new0(CoroutineThreadState, 1);
s->current = &s->leader.base;
QLIST_INIT(&s->pool);
pthread_setspecific(thread_state_key, s);
@@ -146,7 +146,7 @@ static Coroutine *coroutine_new(void)
abort();
}
- co = g_malloc0(sizeof(*co));
+ co = g_new0(CoroutineUContext, 1);
co->stack = g_malloc(stack_size);
co->base.entry_arg = &old_env; /* stash away our jmp_buf */
@@ -64,7 +64,7 @@ Coroutine *qemu_coroutine_new(void)
const size_t stack_size = 1 << 20;
CoroutineWin32 *co;
- co = g_malloc0(sizeof(*co));
+ co = g_new0(CoroutineWin32, 1);
co->fiber = CreateFiber(stack_size, coroutine_trampoline, &co->base);
return &co->base;
}
@@ -32,7 +32,7 @@ void error_set(Error **errp, const char *fmt, ...)
return;
}
- err = g_malloc0(sizeof(*err));
+ err = g_new0(Error, 1);
va_start(ap, fmt);
err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
@@ -137,7 +137,7 @@ void error_set_qobject(Error **errp, QObject *obj)
if (errp == NULL) {
return;
}
- err = g_malloc0(sizeof(*err));
+ err = g_new0(Error, 1);
err->obj = qobject_to_qdict(obj);
qobject_incref(obj);
@@ -1444,7 +1444,7 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
TARGET_FMT_lx ", len=" TARGET_FMT_lu "\n", addr, len);
return -EINVAL;
}
- wp = g_malloc(sizeof(*wp));
+ wp = g_new(CPUWatchpoint, 1);
wp->vaddr = addr;
wp->len_mask = len_mask;
@@ -1509,7 +1509,7 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
#if defined(TARGET_HAS_ICE)
CPUBreakpoint *bp;
- bp = g_malloc(sizeof(*bp));
+ bp = g_new(CPUBreakpoint, 1);
bp->pc = pc;
bp->flags = flags;
@@ -2917,7 +2917,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
RAMBlock *new_block, *block;
size = TARGET_PAGE_ALIGN(size);
- new_block = g_malloc0(sizeof(*new_block));
+ new_block = g_new0(RAMBlock, 1);
if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
char *id = dev->parent_bus->info->get_dev_path(dev);
@@ -3824,11 +3824,11 @@ static void io_mem_init(void)
static void memory_map_init(void)
{
- system_memory = g_malloc(sizeof(*system_memory));
+ system_memory = g_new(MemoryRegion, 1);
memory_region_init(system_memory, "system", INT64_MAX);
set_system_memory_map(system_memory);
- system_io = g_malloc(sizeof(*system_io));
+ system_io = g_new(MemoryRegion, 1);
memory_region_init(system_io, "io", 65536);
set_system_io_map(system_io);
}
@@ -4044,7 +4044,7 @@ static QLIST_HEAD(map_client_list, MapClient) map_client_list
void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque))
{
- MapClient *client = g_malloc(sizeof(*client));
+ MapClient *client = g_new(MapClient, 1);
client->opaque = opaque;
client->callback = callback;
@@ -66,7 +66,7 @@ int qemu_fsdev_add(QemuOpts *opts)
return -1;
}
- fsle = g_malloc(sizeof(*fsle));
+ fsle = g_new(struct FsTypeListEntry, 1);
fsle->fse.fsdev_id = g_strdup(fsdev_id);
fsle->fse.path = g_strdup(path);
@@ -2886,7 +2886,7 @@ int gdbserver_start(const char *device)
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
/* Initialize a monitor terminal for gdb */
- mon_chr = g_malloc0(sizeof(*mon_chr));
+ mon_chr = g_new0(CharDriverState, 1);
mon_chr->chr_write = gdb_monitor_write;
monitor_init(mon_chr, 0);
} else {
@@ -2861,7 +2861,7 @@ static void v9fs_lock(void *opaque)
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
- flock = g_malloc(sizeof(*flock));
+ flock = g_new(V9fsFlock, 1);
pdu_unmarshal(pdu, offset, "dbdqqds", &fid, &flock->type,
&flock->flags, &flock->start, &flock->length,
&flock->proc_id, &flock->client_id);
@@ -2906,7 +2906,7 @@ static void v9fs_getlock(void *opaque)
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
- glock = g_malloc(sizeof(*glock));
+ glock = g_new(V9fsGetlock, 1);
pdu_unmarshal(pdu, offset, "dbqqds", &fid, &glock->type,
&glock->start, &glock->length, &glock->proc_id,
&glock->client_id);
@@ -517,7 +517,7 @@ enum peripheral_minor_class {
static struct bt_device_s *bt_hid_init(struct bt_scatternet_s *net,
enum peripheral_minor_class minor)
{
- struct bt_hid_device_s *s = g_malloc0(sizeof(*s));
+ struct bt_hid_device_s *s = g_new0(struct bt_hid_device_s, 1);
uint32_t class =
/* Format type */
(0 << 0) |
@@ -410,7 +410,7 @@ static struct l2cap_chan_s *l2cap_channel_open(struct l2cap_instance_s *l2cap,
if (psm_info) {
/* Device supports this use-case. */
- ch = g_malloc0(sizeof(*ch));
+ ch = g_new0(struct l2cap_chan_s, 1);
ch->params.sdu_out = l2cap_bframe_out;
ch->params.sdu_submit = l2cap_bframe_submit;
ch->frame_in = l2cap_bframe_in;
@@ -1353,7 +1353,7 @@ void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm, int min_mtu,
exit(-1);
}
- new_psm = g_malloc0(sizeof(*new_psm));
+ new_psm = g_new0(struct bt_l2cap_psm_s, 1);
new_psm->psm = psm;
new_psm->min_mtu = min_mtu;
new_psm->new_channel = new_channel;
@@ -708,10 +708,9 @@ static void sdp_service_record_build(struct sdp_service_record_s *record,
&record->uuids);
}
record->uuids = 1 << ffs(record->uuids - 1);
- record->attribute_list =
- g_malloc0(record->attributes * sizeof(*record->attribute_list));
- record->uuid =
- g_malloc0(record->uuids * sizeof(*record->uuid));
+ record->attribute_list = g_new0(struct sdp_service_attribute_s,
+ record->attributes);
+ record->uuid = g_new0(int, record->uuids);
data = g_malloc(len);
record->attributes = 0;
@@ -752,8 +751,7 @@ static void sdp_service_db_build(struct bt_l2cap_sdp_state_s *sdp,
sdp->services = 0;
while (service[sdp->services])
sdp->services ++;
- sdp->service_list =
- g_malloc0(sdp->services * sizeof(*sdp->service_list));
+ sdp->service_list = g_new0(struct sdp_service_record_s, sdp->services);
sdp->services = 0;
while (*service) {
@@ -942,7 +940,7 @@ SERVICE(pnp,
static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
struct bt_l2cap_conn_params_s *params)
{
- struct bt_l2cap_sdp_state_s *sdp = g_malloc0(sizeof(*sdp));
+ struct bt_l2cap_sdp_state_s *sdp = g_new0(struct bt_l2cap_sdp_state_s, 1);
struct sdp_def_service_s *services[] = {
&sdp_service_sdp_s,
&sdp_service_hid_s,
@@ -2384,7 +2384,7 @@ static void map_linear_vram_bank(CirrusVGAState *s, unsigned bank)
&& !((s->vga.gr[0x0B] & 0x14) == 0x14)
&& !(s->vga.gr[0x0B] & 0x02)) {
- mr = g_malloc(sizeof(*mr));
+ mr = g_new(MemoryRegion, 1);
memory_region_init_alias(mr, names[bank], &s->vga.vram,
s->cirrus_bank_base[bank], 0x8000);
memory_region_add_subregion_overlap(
@@ -750,7 +750,7 @@ void *etraxfs_dmac_init(target_phys_addr_t base, int nr_channels)
{
struct fs_dma_ctrl *ctrl = NULL;
- ctrl = g_malloc0(sizeof *ctrl);
+ ctrl = g_new0(struct fs_dma_ctrl, 1);
ctrl->bh = qemu_bh_new(DMA_run, ctrl);
@@ -345,7 +345,7 @@ static int grlib_irqmp_init(SysBusDevice *dev)
grlib_irqmp_write,
irqmp, DEVICE_NATIVE_ENDIAN);
- irqmp->state = g_malloc0(sizeof *irqmp->state);
+ irqmp->state = g_new0(IRQMPState, 1);
if (irqmp_regs < 0) {
return -1;
@@ -74,7 +74,7 @@ void isa_mmio_setup(MemoryRegion *mr, target_phys_addr_t size)
void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size)
{
- MemoryRegion *mr = g_malloc(sizeof(*mr));
+ MemoryRegion *mr = g_new(MemoryRegion, 1);
isa_mmio_setup(mr, size);
memory_region_add_subregion(get_system_memory(), base, mr);
@@ -564,7 +564,7 @@ int rom_add_file(const char *file, const char *fw_dir,
int rc, fd = -1;
char devpath[100];
- rom = g_malloc0(sizeof(*rom));
+ rom = g_new0(Rom, 1);
rom->name = g_strdup(file);
rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
if (rom->path == NULL) {
@@ -630,7 +630,7 @@ int rom_add_blob(const char *name, const void *blob, size_t len,
{
Rom *rom;
- rom = g_malloc0(sizeof(*rom));
+ rom = g_new0(Rom, 1);
rom->name = g_strdup(name);
rom->addr = addr;
rom->romsize = len;
@@ -219,8 +219,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
if (nentries > MSIX_MAX_ENTRIES)
return -EINVAL;
- dev->msix_entry_used = g_malloc0(MSIX_MAX_ENTRIES *
- sizeof *dev->msix_entry_used);
+ dev->msix_entry_used = g_new0(unsigned, MSIX_MAX_ENTRIES);
dev->msix_table_page = g_malloc0(MSIX_PAGE_SIZE);
msix_mask_all(dev, nentries);
@@ -128,7 +128,7 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)
#ifdef L4_MUX_HACK
omap_l4_io_entries = 1;
- omap_l4_io_entry = g_malloc0(125 * sizeof(*omap_l4_io_entry));
+ omap_l4_io_entry = g_new0(struct omap_l4_entry, 125);
omap_cpu_io_entry =
cpu_register_io_memory(omap_l4_io_readfn,
@@ -86,7 +86,7 @@ static CPUWriteMemoryFunc * const omap_synctimer_writefn[] = {
struct omap_synctimer_s *omap_synctimer_init(struct omap_target_agent_s *ta,
struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
{
- struct omap_synctimer_s *s = g_malloc0(sizeof(*s));
+ struct omap_synctimer_s *s = g_new0(struct omap_synctimer_s, 1);
omap_synctimer_reset(s);
omap_l4_attach(ta, 0, l4_register_io_memory(
@@ -987,16 +987,16 @@ void pc_memory_init(MemoryRegion *system_memory,
* aliases to address portions of it, mostly for backwards compatiblity
* with older qemus that used qemu_ram_alloc().
*/
- ram = g_malloc(sizeof(*ram));
+ ram = g_new(MemoryRegion, 1);
memory_region_init_ram(ram, NULL, "pc.ram",
below_4g_mem_size + above_4g_mem_size);
*ram_memory = ram;
- ram_below_4g = g_malloc(sizeof(*ram_below_4g));
+ ram_below_4g = g_new(MemoryRegion, 1);
memory_region_init_alias(ram_below_4g, "ram-below-4g", ram,
0, below_4g_mem_size);
memory_region_add_subregion(system_memory, 0, ram_below_4g);
if (above_4g_mem_size > 0) {
- ram_above_4g = g_malloc(sizeof(*ram_above_4g));
+ ram_above_4g = g_new(MemoryRegion, 1);
memory_region_init_alias(ram_above_4g, "ram-above-4g", ram,
below_4g_mem_size, above_4g_mem_size);
memory_region_add_subregion(system_memory, 0x100000000ULL,
@@ -1016,7 +1016,7 @@ void pc_memory_init(MemoryRegion *system_memory,
(bios_size % 65536) != 0) {
goto bios_error;
}
- bios = g_malloc(sizeof(*bios));
+ bios = g_new(MemoryRegion, 1);
memory_region_init_ram(bios, NULL, "pc.bios", bios_size);
memory_region_set_readonly(bios, true);
ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
@@ -1032,7 +1032,7 @@ void pc_memory_init(MemoryRegion *system_memory,
isa_bios_size = bios_size;
if (isa_bios_size > (128 * 1024))
isa_bios_size = 128 * 1024;
- isa_bios = g_malloc(sizeof(*isa_bios));
+ isa_bios = g_new(MemoryRegion, 1);
memory_region_init_alias(isa_bios, "isa-bios", bios,
bios_size - isa_bios_size, isa_bios_size);
memory_region_add_subregion_overlap(rom_memory,
@@ -1041,7 +1041,7 @@ void pc_memory_init(MemoryRegion *system_memory,
1);
memory_region_set_readonly(isa_bios, true);
- option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+ option_rom_mr = g_new(MemoryRegion, 1);
memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE);
memory_region_add_subregion_overlap(rom_memory,
PC_ROM_MIN_VGA,
@@ -130,7 +130,7 @@ static void pc_init1(MemoryRegion *system_memory,
pci_enabled ? rom_memory : system_memory, &ram_memory);
}
- gsi_state = g_malloc0(sizeof(*gsi_state));
+ gsi_state = g_new0(GSIState, 1);
gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
if (pci_enabled) {
@@ -223,7 +223,7 @@ static int pcibus_reset(BusState *qbus)
static void pci_host_bus_register(int domain, PCIBus *bus)
{
struct PCIHostBus *host;
- host = g_malloc0(sizeof(*host));
+ host = g_new0(struct PCIHostBus, 1);
host->domain = domain;
host->bus = bus;
QLIST_INSERT_HEAD(&host_buses, host, next);
@@ -288,7 +288,7 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name,
{
PCIBus *bus;
- bus = g_malloc0(sizeof(*bus));
+ bus = g_new0(PCIBus, 1);
bus->qbus.qdev_allocated = 1;
pci_bus_new_inplace(bus, parent, name, address_space_mem,
address_space_io, devfn_min);
@@ -76,7 +76,7 @@ void pcie_chassis_create(uint8_t chassis_number)
if (c) {
return;
}
- c = g_malloc0(sizeof(*c));
+ c = g_new0(struct PCIEChassis, 1);
c->number = chassis_number;
QLIST_INIT(&c->slots);
QLIST_INSERT_HEAD(&chassis, c, next);
@@ -184,7 +184,7 @@ static void ref405ep_init (ram_addr_t ram_size,
MemoryRegion *bios;
MemoryRegion *sram = g_new(MemoryRegion, 1);
ram_addr_t bdloc;
- MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
+ MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
target_phys_addr_t ram_bases[2], ram_sizes[2];
target_ulong sram_size;
long bios_size;
@@ -503,7 +503,7 @@ static void taihu_405ep_init(ram_addr_t ram_size,
qemu_irq *pic;
MemoryRegion *sysmem = get_system_memory();
MemoryRegion *bios;
- MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
+ MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
target_phys_addr_t ram_bases[2], ram_sizes[2];
long bios_size;
target_ulong kernel_base, initrd_base;
@@ -38,8 +38,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,
PCIBus **pcip, const unsigned int pci_irq_nrs[4],
int do_init, const char *cpu_model)
{
- MemoryRegion *ram_memories
- = g_malloc(PPC440EP_SDRAM_NR_BANKS * sizeof(*ram_memories));
+ MemoryRegion *ram_memories = g_new(MemoryRegion, PPC440EP_SDRAM_NR_BANKS);
target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS];
target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS];
CPUState *env;
@@ -799,7 +799,7 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
{
GlobalProperty *g;
- g = g_malloc0(sizeof(*g));
+ g = g_new0(GlobalProperty, 1);
g->driver = qemu_opt_get(opts, "driver");
g->property = qemu_opt_get(opts, "property");
g->value = qemu_opt_get(opts, "value");
@@ -330,7 +330,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,
long pteg_shift = 17;
char *filename;
- spapr = g_malloc(sizeof(*spapr));
+ spapr = g_new(sPAPREnvironment, 1);
cpu_ppc_hypercall = emulate_spapr_hypercall;
/* We place the device tree just below either the top of RAM, or
@@ -166,7 +166,7 @@ void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init)
{
SysBusDeviceInfo *info;
- info = g_malloc0(sizeof(*info));
+ info = g_new0(SysBusDeviceInfo, 1);
info->qdev.name = g_strdup(name);
info->qdev.size = size;
info->init = init;
@@ -283,7 +283,7 @@ void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
}
}
if (s == NULL) {
- s = g_malloc0(sizeof(*s));
+ s = g_new0(USBDescString, 1);
s->index = index;
QLIST_INSERT_HEAD(&dev->strings, s, next);
}
@@ -660,7 +660,7 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, int async)
{
EHCIQueue *q;
- q = g_malloc0(sizeof(*q));
+ q = g_new0(EHCIQueue, 1);
q->ehci = ehci;
q->async_schedule = async;
QTAILQ_INSERT_HEAD(&ehci->queues, q, next);
@@ -374,7 +374,7 @@ void musb_reset(MUSBState *s)
struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)
{
- MUSBState *s = g_malloc0(sizeof(*s));
+ MUSBState *s = g_new0(MUSBState, 1);
int i;
for (i = 0; i < musb_irq_max; i++) {
@@ -102,11 +102,11 @@ static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,
MemoryRegion *s_ioport_ctrl, *vga_io_memory;
s->it_shift = it_shift;
- s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
+ s_ioport_ctrl = g_new(MemoryRegion, 1);
memory_region_init_io(s_ioport_ctrl, &vga_mm_ctrl_ops, s,
"vga-mm-ctrl", 0x100000);
- vga_io_memory = g_malloc(sizeof(*vga_io_memory));
+ vga_io_memory = g_new(MemoryRegion, 1);
/* XXX: endianness? */
memory_region_init_io(vga_io_memory, &vga_mem_ops, &s->vga,
"vga-mem", 0x20000);
@@ -126,7 +126,7 @@ int isa_vga_mm_init(target_phys_addr_t vram_base,
{
ISAVGAMMState *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(ISAVGAMMState, 1);
vga_common_init(&s->vga, VGA_RAM_SIZE);
vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
@@ -182,7 +182,7 @@ static void vga_update_memory_access(VGACommonState *s)
break;
}
base += isa_mem_base;
- region = g_malloc(sizeof(*region));
+ region = g_new(MemoryRegion, 1);
memory_region_init_alias(region, "vga.chain4", &s->vram, offset, size);
memory_region_add_subregion_overlap(s->legacy_address_space, base,
region, 2);
@@ -2279,7 +2279,7 @@ MemoryRegion *vga_init_io(VGACommonState *s,
*vbe_ports = vbe_portio_list;
#endif
- vga_mem = g_malloc(sizeof(*vga_mem));
+ vga_mem = g_new(MemoryRegion, 1);
memory_region_init_io(vga_mem, &vga_mem_ops, s,
"vga-lowmem", 0x20000);
@@ -252,7 +252,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)
uint64_t log_base;
int r;
if (size) {
- log = g_malloc0(size * sizeof *log);
+ log = g_new0(vhost_log_chunk_t, size);
} else {
log = NULL;
}
@@ -92,7 +92,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, int devfd,
bool force)
{
int r;
- struct vhost_net *net = g_malloc(sizeof *net);
+ struct vhost_net *net = g_new(struct vhost_net, 1);
if (!backend) {
fprintf(stderr, "vhost-net requires backend to be setup\n");
goto fail;
@@ -123,7 +123,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
{
- VirtIOBlockReq *req = g_malloc(sizeof(*req));
+ VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
req->dev = s;
req->qiov.size = 0;
req->next = NULL;
@@ -14,7 +14,7 @@ static void xen_config_cleanup_dir(char *dir)
{
struct xs_dirs *d;
- d = g_malloc(sizeof(*d));
+ d = g_new(struct xs_dirs, 1);
d->xs_dir = dir;
QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
}
@@ -125,7 +125,7 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
goto out;
}
/* allocate new struct */
- ioreq = g_malloc0(sizeof(*ioreq));
+ ioreq = g_new0(struct ioreq, 1);
ioreq->blkdev = blkdev;
blkdev->requests_total++;
qemu_iovec_init(&ioreq->v, BLKIF_MAX_SEGMENTS_PER_REQUEST);
@@ -437,7 +437,7 @@ struct icp_state *xics_system_init(int nr_irqs)
}
}
- icp = g_malloc0(sizeof(*icp));
+ 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));
@@ -464,7 +464,7 @@ struct icp_state *xics_system_init(int nr_irqs)
}
}
- ics = g_malloc0(sizeof(*ics));
+ 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));
@@ -127,7 +127,7 @@ static void lx60_net_init(MemoryRegion *address_space,
memory_region_add_subregion(address_space, descriptors,
sysbus_mmio_get_region(s, 1));
- ram = g_malloc(sizeof(*ram));
+ ram = g_new(MemoryRegion, 1);
memory_region_init_ram(ram, NULL, "open_eth.ram", 16384);
memory_region_add_subregion(address_space, buffers, ram);
}
@@ -171,15 +171,15 @@ static void lx60_init(ram_addr_t ram_size,
cpu_reset(env);
}
- ram = g_malloc(sizeof(*ram));
+ ram = g_new(MemoryRegion, 1);
memory_region_init_ram(ram, NULL, "xtensa.sram", ram_size);
memory_region_add_subregion(system_memory, 0, ram);
- rom = g_malloc(sizeof(*rom));
+ rom = g_new(MemoryRegion, 1);
memory_region_init_ram(rom, NULL, "xtensa.rom", 0x1000);
memory_region_add_subregion(system_memory, 0xfe000000, rom);
- system_io = g_malloc(sizeof(*system_io));
+ system_io = g_new(MemoryRegion, 1);
memory_region_init(system_io, "system.io", 224 * 1024 * 1024);
memory_region_add_subregion(system_memory, 0xf0000000, system_io);
lx60_fpga_init(system_io, 0x0d020000);
@@ -65,11 +65,11 @@ static void sim_init(ram_addr_t ram_size,
sim_reset(env);
}
- ram = g_malloc(sizeof(*ram));
+ ram = g_new(MemoryRegion, 1);
memory_region_init_ram(ram, NULL, "xtensa.sram", ram_size);
memory_region_add_subregion(get_system_memory(), 0, ram);
- rom = g_malloc(sizeof(*rom));
+ rom = g_new(MemoryRegion, 1);
memory_region_init_ram(rom, NULL, "xtensa.rom", 0x1000);
memory_region_add_subregion(get_system_memory(), 0xfe000000, rom);
@@ -207,7 +207,7 @@ void *laio_init(void)
{
struct qemu_laio_state *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(struct qemu_laio_state, 1);
s->efd = eventfd(0, 0);
if (s->efd == -1)
goto out_free_state;
@@ -2115,7 +2115,7 @@ static struct mm_struct *vma_init(void)
{
struct mm_struct *mm;
- if ((mm = g_malloc(sizeof (*mm))) == NULL)
+ if ((mm = g_new(struct mm_struct, 1)) == NULL)
return (NULL);
mm->mm_count = 0;
@@ -2140,7 +2140,7 @@ static int vma_add_mapping(struct mm_struct *mm, abi_ulong start,
{
struct vm_area_struct *vma;
- if ((vma = g_malloc0(sizeof (*vma))) == NULL)
+ if ((vma = g_new0(struct vm_area_struct, 1)) == NULL)
return (-1);
vma->vma_start = start;
@@ -2464,7 +2464,7 @@ static void fill_thread_info(struct elf_note_info *info, const CPUState *env)
TaskState *ts = (TaskState *)env->opaque;
struct elf_thread_status *ets;
- ets = g_malloc0(sizeof (*ets));
+ ets = g_new0(struct elf_thread_status, 1);
ets->num_notes = 1; /* only prstatus is dumped */
fill_prstatus(&ets->prstatus, ts, 0);
elf_core_copy_regs(&ets->prstatus.pr_reg, env);
@@ -1123,7 +1123,7 @@ void memory_region_add_coalescing(MemoryRegion *mr,
target_phys_addr_t offset,
uint64_t size)
{
- CoalescedMemoryRange *cmr = g_malloc(sizeof(*cmr));
+ CoalescedMemoryRange *cmr = g_new(CoalescedMemoryRange, 1);
cmr->addr = addrrange_make(offset, size);
QTAILQ_INSERT_TAIL(&mr->coalesced, cmr, link);
@@ -71,7 +71,7 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,
FdMigrationState *s;
FILE *f;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(FdMigrationState, 1);
f = popen(command, "w");
if (f == NULL) {
@@ -59,7 +59,7 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon,
{
FdMigrationState *s;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(FdMigrationState, 1);
s->fd = monitor_get_fd(mon, fdname);
if (s->fd == -1) {
@@ -89,7 +89,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
if (parse_host_port(&addr, host_port) < 0)
return NULL;
- s = g_malloc0(sizeof(*s));
+ s = g_new0(FdMigrationState, 1);
s->get_error = socket_errno;
s->write = socket_write;
@@ -88,7 +88,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
- s = g_malloc0(sizeof(*s));
+ s = g_new0(FdMigrationState, 1);
s->get_error = unix_errno;
s->write = unix_write;
@@ -59,7 +59,7 @@ void register_module_init(void (*fn)(void), module_init_type type)
ModuleEntry *e;
ModuleTypeList *l;
- e = g_malloc0(sizeof(*e));
+ e = g_new0(ModuleEntry, 1);
e->init = fn;
l = find_type(type);
@@ -674,7 +674,7 @@ static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
{
int ret;
- MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data));
+ MonitorCompletionData *cb_data = g_new(MonitorCompletionData, 1);
cb_data->mon = mon;
cb_data->user_print = cmd->user_print;
monitor_suspend(mon);
@@ -690,7 +690,7 @@ static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd)
{
int ret;
- MonitorCompletionData *cb_data = g_malloc(sizeof(*cb_data));
+ MonitorCompletionData *cb_data = g_new(MonitorCompletionData, 1);
cb_data->mon = mon;
cb_data->user_print = cmd->user_print;
monitor_suspend(mon);
@@ -743,7 +743,7 @@ static CommandInfoList *alloc_cmd_entry(const char *cmd_name)
{
CommandInfoList *info;
- info = g_malloc0(sizeof(*info));
+ info = g_new0(CommandInfoList, 1);
info->value = g_malloc0(sizeof(*info->value));
info->value->name = g_strdup(cmd_name);
@@ -2480,7 +2480,7 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict)
int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
CaptureState *s;
- s = g_malloc0 (sizeof (*s));
+ s = g_new0(CaptureState, 1);
freq = has_freq ? freq : 44100;
bits = has_bits ? bits : 16;
@@ -5114,7 +5114,7 @@ void monitor_init(CharDriverState *chr, int flags)
is_first_init = 0;
}
- mon = g_malloc0(sizeof(*mon));
+ mon = g_new0(Monitor, 1);
mon->chr = chr;
mon->flags = flags;
@@ -450,7 +450,7 @@ int net_slirp_redir(const char *redir_str)
struct slirp_config_str *config;
if (QTAILQ_EMPTY(&slirp_stacks)) {
- config = g_malloc(sizeof(*config));
+ config = g_new(struct slirp_config_str, 1);
pstrcpy(config->str, sizeof(config->str), redir_str);
config->flags = SLIRP_CFG_HOSTFWD | SLIRP_CFG_LEGACY;
config->next = slirp_configs;
@@ -662,7 +662,7 @@ static int net_init_slirp_configs(const char *name, const char *value, void *opa
return 0;
}
- config = g_malloc0(sizeof(*config));
+ config = g_new0(struct slirp_config_str, 1);
pstrcpy(config->str, sizeof(config->str), value);
@@ -764,7 +764,7 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
if (QTAILQ_EMPTY(&slirp_stacks)) {
struct slirp_config_str *config;
- config = g_malloc(sizeof(*config));
+ config = g_new(struct slirp_config_str, 1);
pstrcpy(config->str, sizeof(config->str), optarg);
config->flags = SLIRP_CFG_LEGACY;
config->next = slirp_configs;
@@ -37,7 +37,7 @@ static QapiDeallocVisitor *to_qov(Visitor *v)
static void qapi_dealloc_push(QapiDeallocVisitor *qov, void *value)
{
- StackEntry *e = g_malloc0(sizeof(*e));
+ StackEntry *e = g_new0(StackEntry, 1);
e->value = value;
@@ -152,7 +152,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void)
{
QapiDeallocVisitor *v;
- v = g_malloc0(sizeof(*v));
+ v = g_new0(QapiDeallocVisitor, 1);
v->visitor.start_struct = qapi_dealloc_start_struct;
v->visitor.end_struct = qapi_dealloc_end_struct;
@@ -135,7 +135,7 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list,
return NULL;
}
- entry = g_malloc0(sizeof(*entry));
+ entry = g_new0(GenericList, 1);
if (*list) {
so->entry = qlist_next(so->entry);
if (so->entry == NULL) {
@@ -279,7 +279,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
{
QmpInputVisitor *v;
- v = g_malloc0(sizeof(*v));
+ v = g_new0(QmpInputVisitor, 1);
v->visitor.start_struct = qmp_input_start_struct;
v->visitor.end_struct = qmp_input_end_struct;
@@ -43,7 +43,7 @@ static QmpOutputVisitor *to_qov(Visitor *v)
static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value)
{
- QStackEntry *e = g_malloc0(sizeof(*e));
+ QStackEntry *e = g_new0(QStackEntry, 1);
e->value = value;
if (qobject_type(e->value) == QTYPE_QLIST) {
@@ -232,7 +232,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void)
{
QmpOutputVisitor *v;
- v = g_malloc0(sizeof(*v));
+ v = g_new0(QmpOutputVisitor, 1);
v->visitor.start_struct = qmp_output_start_struct;
v->visitor.end_struct = qmp_output_end_struct;
@@ -19,7 +19,7 @@ static QTAILQ_HEAD(, QmpCommand) qmp_commands =
void qmp_register_command(const char *name, QmpCommandFunc *fn)
{
- QmpCommand *cmd = g_malloc0(sizeof(*cmd));
+ QmpCommand *cmd = g_new0(QmpCommand, 1);
cmd->name = name;
cmd->type = QCT_NORMAL;
@@ -31,7 +31,7 @@ QBool *qbool_from_int(int value)
{
QBool *qb;
- qb = g_malloc(sizeof(*qb));
+ qb = g_new(QBool, 1);
qb->value = value;
QOBJECT_INIT(qb, &qbool_type);
@@ -35,7 +35,7 @@ QDict *qdict_new(void)
{
QDict *qdict;
- qdict = g_malloc0(sizeof(*qdict));
+ qdict = g_new0(QDict, 1);
QOBJECT_INIT(qdict, &qdict_type);
return qdict;
@@ -75,7 +75,7 @@ static QDictEntry *alloc_entry(const char *key, QObject *value)
{
QDictEntry *entry;
- entry = g_malloc0(sizeof(*entry));
+ entry = g_new0(QDictEntry, 1);
entry->key = g_strdup(key);
entry->value = value;
@@ -2348,7 +2348,7 @@ void qemu_chr_init_mem(CharDriverState *chr)
{
MemoryDriver *d;
- d = g_malloc(sizeof(*d));
+ d = g_new(MemoryDriver, 1);
d->outbuf_size = 0;
d->outbuf_capacity = 4096;
d->outbuf = g_malloc0(d->outbuf_capacity);
@@ -2656,7 +2656,7 @@ ChardevInfoList *qmp_query_chardev(Error **errp)
CharDriverState *chr;
QTAILQ_FOREACH(chr, &chardevs, next) {
- ChardevInfoList *info = g_malloc0(sizeof(*info));
+ ChardevInfoList *info = g_new0(ChardevInfoList, 1);
info->value = g_malloc0(sizeof(*info->value));
info->value->label = g_strdup(chr->label);
info->value->filename = g_strdup(chr->filename);
@@ -950,9 +950,9 @@ static int multiwrite_f(int argc, char **argv)
}
}
- reqs = g_malloc(nr_reqs * sizeof(*reqs));
- buf = g_malloc(nr_reqs * sizeof(*buf));
- qiovs = g_malloc(nr_reqs * sizeof(*qiovs));
+ reqs = g_new(BlockRequest, nr_reqs);
+ buf = g_new(char *, nr_reqs);
+ qiovs = g_new(QEMUIOVector, nr_reqs);
for (i = 0; i < nr_reqs; i++) {
int j;
@@ -619,7 +619,7 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
}
}
- opt = g_malloc0(sizeof(*opt));
+ opt = g_new0(QemuOpt, 1);
opt->name = g_strdup(name);
opt->opts = opts;
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
@@ -701,7 +701,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist
}
}
}
- opts = g_malloc0(sizeof(*opts));
+ opts = g_new0(QemuOpts, 1);
if (id) {
opts->id = g_strdup(id);
}
@@ -249,7 +249,7 @@ void qemu_thread_create(QemuThread *thread,
struct QemuThreadData *data;
qemu_thread_init();
- data = g_malloc(sizeof *data);
+ data = g_new(struct QemuThreadData, 1);
data->thread = thread;
data->start_routine = start_routine;
data->arg = arg;
@@ -246,7 +246,7 @@ QError *qerror_new(void)
{
QError *qerr;
- qerr = g_malloc0(sizeof(*qerr));
+ qerr = g_new0(QError, 1);
QOBJECT_INIT(qerr, &qerror_type);
return qerr;
@@ -31,7 +31,7 @@ QFloat *qfloat_from_double(double value)
{
QFloat *qf;
- qf = g_malloc(sizeof(*qf));
+ qf = g_new(QFloat, 1);
qf->value = value;
QOBJECT_INIT(qf, &qfloat_type);
@@ -30,7 +30,7 @@ QInt *qint_from_int(int64_t value)
{
QInt *qi;
- qi = g_malloc(sizeof(*qi));
+ qi = g_new(QInt, 1);
qi->value = value;
QOBJECT_INIT(qi, &qint_type);
@@ -31,7 +31,7 @@ QList *qlist_new(void)
{
QList *qlist;
- qlist = g_malloc(sizeof(*qlist));
+ qlist = g_new(QList, 1);
QTAILQ_INIT(&qlist->head);
QOBJECT_INIT(qlist, &qlist_type);
@@ -64,7 +64,7 @@ void qlist_append_obj(QList *qlist, QObject *value)
{
QListEntry *entry;
- entry = g_malloc(sizeof(*entry));
+ entry = g_new(QListEntry, 1);
entry->value = value;
QTAILQ_INSERT_TAIL(&qlist->head, entry, next);
@@ -19,7 +19,7 @@
NameInfo *qmp_query_name(Error **errp)
{
- NameInfo *info = g_malloc0(sizeof(*info));
+ NameInfo *info = g_new0(NameInfo, 1);
if (qemu_name) {
info->has_name = true;
@@ -31,7 +31,7 @@ NameInfo *qmp_query_name(Error **errp)
VersionInfo *qmp_query_version(Error **err)
{
- VersionInfo *info = g_malloc0(sizeof(*info));
+ VersionInfo *info = g_new0(VersionInfo, 1);
const char *version = QEMU_VERSION;
char *tmp;
@@ -47,7 +47,7 @@ VersionInfo *qmp_query_version(Error **err)
KvmInfo *qmp_query_kvm(Error **errp)
{
- KvmInfo *info = g_malloc0(sizeof(*info));
+ KvmInfo *info = g_new0(KvmInfo, 1);
info->enabled = kvm_enabled();
info->present = kvm_available();
@@ -57,7 +57,7 @@ KvmInfo *qmp_query_kvm(Error **errp)
UuidInfo *qmp_query_uuid(Error **errp)
{
- UuidInfo *info = g_malloc0(sizeof(*info));
+ UuidInfo *info = g_new0(UuidInfo, 1);
char uuid[64];
snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
@@ -40,7 +40,7 @@ QString *qstring_from_substr(const char *str, int start, int end)
{
QString *qstring;
- qstring = g_malloc(sizeof(*qstring));
+ qstring = g_new(QString, 1);
qstring->length = end - start + 1;
qstring->capacity = qstring->length;
@@ -466,7 +466,7 @@ const char *readline_get_history(ReadLineState *rs, unsigned int index)
ReadLineState *readline_init(Monitor *mon,
ReadLineCompletionFunc *completion_finder)
{
- ReadLineState *rs = g_malloc0(sizeof(*rs));
+ ReadLineState *rs = g_new0(ReadLineState, 1);
rs->hist_entry = -1;
rs->mon = mon;
@@ -74,7 +74,7 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model)
return NULL;
}
- env = g_malloc0(sizeof(*env));
+ env = g_new0(CPUXtensaState, 1);
env->config = config;
cpu_exec_init(env);
@@ -52,7 +52,7 @@ static void add_to_key_range(struct key_range **krp, int code) {
}
}
if (kr == NULL) {
- kr = g_malloc0(sizeof(*kr));
+ kr = g_new0(struct key_range, 1);
kr->start = kr->end = code;
kr->next = *krp;
*krp = kr;
@@ -57,7 +57,7 @@ static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque)
{
SpiceTimer *timer;
- timer = g_malloc0(sizeof(*timer));
+ timer = g_new0(SpiceTimer, 1);
timer->timer = qemu_new_timer_ms(rt_clock, func, opaque);
QTAILQ_INSERT_TAIL(&timers, timer, next);
return timer;
@@ -121,7 +121,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
{
SpiceWatch *watch;
- watch = g_malloc0(sizeof(*watch));
+ watch = g_new0(SpiceWatch, 1);
watch->fd = fd;
watch->func = func;
watch->opaque = opaque;
@@ -151,7 +151,7 @@ static void channel_list_add(SpiceChannelEventInfo *info)
{
ChannelList *item;
- item = g_malloc0(sizeof(*item));
+ item = g_new0(ChannelList, 1);
item->info = info;
QTAILQ_INSERT_TAIL(&channel_list, item, link);
}
@@ -142,7 +142,7 @@ static SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd)
ssd->dirty.left, ssd->dirty.right,
ssd->dirty.top, ssd->dirty.bottom);
- update = g_malloc0(sizeof(*update));
+ update = g_new0(SimpleSpiceUpdate, 1);
drawable = &update->drawable;
image = &update->image;
cmd = &update->ext.cmd;
@@ -200,12 +200,12 @@ void qemu_spice_input_init(void)
QemuSpiceKbd *kbd;
QemuSpicePointer *pointer;
- kbd = g_malloc0(sizeof(*kbd));
+ kbd = g_new0(QemuSpiceKbd, 1);
kbd->sin.base.sif = &kbd_interface.base;
qemu_spice_add_interface(&kbd->sin.base);
qemu_add_led_event_handler(kbd_leds, kbd);
- pointer = g_malloc0(sizeof(*pointer));
+ pointer = g_new0(QemuSpicePointer, 1);
pointer->mouse.base.sif = &mouse_interface.base;
pointer->tablet.base.sif = &tablet_interface.base;
qemu_spice_add_interface(&pointer->mouse.base);
@@ -55,7 +55,7 @@ VncPalette *palette_new(size_t max, int bpp)
{
VncPalette *palette;
- palette = g_malloc0(sizeof(*palette));
+ palette = g_new0(VncPalette, 1);
palette_init(palette, max, bpp);
return palette;
}
@@ -2576,7 +2576,7 @@ static void vnc_listen_read(void *opaque)
void vnc_display_init(DisplayState *ds)
{
- VncDisplay *vs = g_malloc0(sizeof(*vs));
+ VncDisplay *vs = g_new0(VncDisplay, 1);
dcl = g_malloc0(sizeof(DisplayChangeListener));
@@ -632,7 +632,7 @@ static AsyncURB *usb_host_alloc_iso(USBHostDevice *s, int pid, uint8_t ep)
AsyncURB *aurb;
int i, j, len = get_max_packet_size(s, pid, ep);
- aurb = g_malloc0(s->iso_urb_count * sizeof(*aurb));
+ aurb = g_new0(AsyncURB, s->iso_urb_count);
for (i = 0; i < s->iso_urb_count; i++) {
aurb[i].urb.endpoint = ep;
aurb[i].urb.buffer_length = ISO_FRAME_DESC_PER_URB * len;
@@ -409,7 +409,7 @@ int runstate_is_running(void)
StatusInfo *qmp_query_status(Error **errp)
{
- StatusInfo *info = g_malloc0(sizeof(*info));
+ StatusInfo *info = g_new0(StatusInfo, 1);
info->running = runstate_is_running();
info->singlestep = singlestep;
@@ -1958,7 +1958,7 @@ static void add_device_config(int type, const char *cmdline)
{
struct device_config *conf;
- conf = g_malloc0(sizeof(*conf));
+ conf = g_new0(struct device_config, 1);
conf->type = type;
conf->cmdline = cmdline;
QTAILQ_INSERT_TAIL(&device_configs, conf, next);
@@ -140,7 +140,7 @@ static void xen_ram_init(ram_addr_t ram_size)
RAMBlock *new_block;
ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
- new_block = g_malloc0(sizeof (*new_block));
+ new_block = g_new0(RAMBlock, 1);
pstrcpy(new_block->idstr, sizeof (new_block->idstr), "xen.ram");
new_block->host = NULL;
new_block->offset = 0;
@@ -190,7 +190,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)
trace_xen_ram_alloc(ram_addr, size);
nr_pfn = size >> TARGET_PAGE_BITS;
- pfn_list = g_malloc(sizeof (*pfn_list) * nr_pfn);
+ pfn_list = g_new(xen_pfn_t, nr_pfn);
for (i = 0; i < nr_pfn; i++) {
pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i;
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 as that of the type referenced by the pointer to which the result is assigned. This was achieved using Coccinelle with the following semantic patch: @@ type T; T *E; @@ -E = g_malloc(sizeof(*E)) +E = g_new(T, 1) @@ type T; T *E; @@ -E = g_malloc0(sizeof(*E)) +E = g_new0(T, 1) @@ type T; T *E; expression N; @@ -E = g_malloc(sizeof(*E) * N) +E = g_new(T, N) @@ type T; T *E; expression N; @@ -E = g_malloc0(sizeof(*E) * N) +E = g_new0(T, N) Signed-off-by: Stuart Brady <sdb@zubnet.me.uk> --- acl.c | 6 +++--- arch_init.c | 2 +- audio/wavcapture.c | 2 +- block.c | 2 +- block/blkdebug.c | 2 +- block/qcow2-cache.c | 2 +- block/qed-cluster.c | 2 +- block/qed-l2-cache.c | 2 +- block/rbd.c | 2 +- block/sheepdog.c | 4 ++-- blockdev.c | 2 +- buffered_file.c | 2 +- coroutine-gthread.c | 4 ++-- coroutine-ucontext.c | 4 ++-- coroutine-win32.c | 2 +- error.c | 4 ++-- exec.c | 12 ++++++------ fsdev/qemu-fsdev.c | 2 +- gdbstub.c | 2 +- hw/9pfs/virtio-9p.c | 4 ++-- hw/bt-hid.c | 2 +- hw/bt-l2cap.c | 4 ++-- hw/bt-sdp.c | 12 +++++------- hw/cirrus_vga.c | 2 +- hw/etraxfs_dma.c | 2 +- hw/grlib_irqmp.c | 2 +- hw/isa_mmio.c | 2 +- hw/loader.c | 4 ++-- hw/msix.c | 3 +-- hw/omap_l4.c | 2 +- hw/omap_synctimer.c | 2 +- hw/pc.c | 12 ++++++------ hw/pc_piix.c | 2 +- hw/pci.c | 4 ++-- hw/pcie_port.c | 2 +- hw/ppc405_boards.c | 4 ++-- hw/ppc440.c | 3 +-- hw/qdev-properties.c | 2 +- hw/spapr.c | 2 +- hw/sysbus.c | 2 +- hw/usb-desc.c | 2 +- hw/usb-ehci.c | 2 +- hw/usb-musb.c | 2 +- hw/vga-isa-mm.c | 6 +++--- hw/vga.c | 4 ++-- hw/vhost.c | 2 +- hw/vhost_net.c | 2 +- hw/virtio-blk.c | 2 +- hw/xen_devconfig.c | 2 +- hw/xen_disk.c | 2 +- hw/xics.c | 4 ++-- hw/xtensa_lx60.c | 8 ++++---- hw/xtensa_sim.c | 4 ++-- linux-aio.c | 2 +- linux-user/elfload.c | 6 +++--- memory.c | 2 +- migration-exec.c | 2 +- migration-fd.c | 2 +- migration-tcp.c | 2 +- migration-unix.c | 2 +- module.c | 2 +- monitor.c | 10 +++++----- net/slirp.c | 6 +++--- qapi/qapi-dealloc-visitor.c | 4 ++-- qapi/qmp-input-visitor.c | 4 ++-- qapi/qmp-output-visitor.c | 4 ++-- qapi/qmp-registry.c | 2 +- qbool.c | 2 +- qdict.c | 4 ++-- qemu-char.c | 4 ++-- qemu-io.c | 6 +++--- qemu-option.c | 4 ++-- qemu-thread-win32.c | 2 +- qerror.c | 2 +- qfloat.c | 2 +- qint.c | 2 +- qlist.c | 4 ++-- qmp.c | 8 ++++---- qstring.c | 2 +- readline.c | 2 +- target-xtensa/helper.c | 2 +- ui/keymaps.c | 2 +- ui/spice-core.c | 6 +++--- ui/spice-display.c | 2 +- ui/spice-input.c | 4 ++-- ui/vnc-palette.c | 2 +- ui/vnc.c | 2 +- usb-linux.c | 2 +- vl.c | 4 ++-- xen-all.c | 4 ++-- 90 files changed, 148 insertions(+), 152 deletions(-)