* [Qemu-devel] [PATCH 2/5] Convert use of ptr = g_malloc(sizeof(*ptr)) to g_new()
2011-10-20 8:03 [Qemu-devel] [PATCH 1/5] Convert calls to g_malloc() using casts to g_new() Stuart Brady
@ 2011-10-20 8:03 ` Stuart Brady
2011-10-20 8:03 ` [Qemu-devel] [PATCH 3/5] Convert use of ptr = g_malloc(sizeof(type)) " Stuart Brady
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Stuart Brady @ 2011-10-20 8:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Stuart Brady
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(-)
diff --git a/acl.c b/acl.c
index 0654f38..83788bd 100644
--- a/acl.c
+++ b/acl.c
@@ -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;
diff --git a/arch_init.c b/arch_init.c
index a6c69c7..13d572f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -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;
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 4f785f5..e11dd82 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -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;
diff --git a/block.c b/block.c
index 9873b57..cc69c87 100644
--- a/block.c
+++ b/block.c
@@ -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);
diff --git a/block/blkdebug.c b/block/blkdebug.c
index b3c5d42..d8ad4a8 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -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,
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 340a6f2..5723c48 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -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;
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
index f64b2af..1629cdf 100644
--- a/block/qed-cluster.c
+++ b/block/qed-cluster.c
@@ -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;
diff --git a/block/qed-l2-cache.c b/block/qed-l2-cache.c
index 02b81a2..aa1d2ef 100644
--- a/block/qed-l2-cache.c
+++ b/block/qed-l2-cache.c
@@ -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);
diff --git a/block/rbd.c b/block/rbd.c
index 3068c82..fce09e6 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -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);
diff --git a/block/sheepdog.c b/block/sheepdog.c
index ae857e2..313b995 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -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);
diff --git a/blockdev.c b/blockdev.c
index 0827bf7..a7eda8a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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 {
diff --git a/buffered_file.c b/buffered_file.c
index 486af57..f9a0742 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -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;
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
index fdea27a..256e1f2 100644
--- a/coroutine-gthread.c
+++ b/coroutine-gthread.c
@@ -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);
}
diff --git a/coroutine-ucontext.c b/coroutine-ucontext.c
index 2b8d3e9..e1b9a52 100644
--- a/coroutine-ucontext.c
+++ b/coroutine-ucontext.c
@@ -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 */
diff --git a/coroutine-win32.c b/coroutine-win32.c
index 4179609..eaf75b4 100644
--- a/coroutine-win32.c
+++ b/coroutine-win32.c
@@ -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;
}
diff --git a/error.c b/error.c
index 68c0039..dc18872 100644
--- a/error.c
+++ b/error.c
@@ -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);
diff --git a/exec.c b/exec.c
index d0cbf15..790dc1a 100644
--- a/exec.c
+++ b/exec.c
@@ -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;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 768819f..b7993c2 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -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);
diff --git a/gdbstub.c b/gdbstub.c
index 717c7d9..9b8103b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -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 {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c01c31a..e276ecc 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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);
diff --git a/hw/bt-hid.c b/hw/bt-hid.c
index 8d7a3da..4f75bd4 100644
--- a/hw/bt-hid.c
+++ b/hw/bt-hid.c
@@ -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) |
diff --git a/hw/bt-l2cap.c b/hw/bt-l2cap.c
index 2ccba60..48f0715 100644
--- a/hw/bt-l2cap.c
+++ b/hw/bt-l2cap.c
@@ -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;
diff --git a/hw/bt-sdp.c b/hw/bt-sdp.c
index 3e390ab..ca41470 100644
--- a/hw/bt-sdp.c
+++ b/hw/bt-sdp.c
@@ -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,
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index c7e365b..d62cee4 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -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(
diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c
index 02d0183..46d97f6 100644
--- a/hw/etraxfs_dma.c
+++ b/hw/etraxfs_dma.c
@@ -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);
diff --git a/hw/grlib_irqmp.c b/hw/grlib_irqmp.c
index 9490a78..44c419d 100644
--- a/hw/grlib_irqmp.c
+++ b/hw/grlib_irqmp.c
@@ -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;
diff --git a/hw/isa_mmio.c b/hw/isa_mmio.c
index fd755ab..65333ea 100644
--- a/hw/isa_mmio.c
+++ b/hw/isa_mmio.c
@@ -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);
diff --git a/hw/loader.c b/hw/loader.c
index 5676c18..8dbdf7e 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -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;
diff --git a/hw/msix.c b/hw/msix.c
index b15bafc..d482ebc 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -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);
diff --git a/hw/omap_l4.c b/hw/omap_l4.c
index a4a8883..e809352 100644
--- a/hw/omap_l4.c
+++ b/hw/omap_l4.c
@@ -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,
diff --git a/hw/omap_synctimer.c b/hw/omap_synctimer.c
index b47ca88..8e1d389 100644
--- a/hw/omap_synctimer.c
+++ b/hw/omap_synctimer.c
@@ -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(
diff --git a/hw/pc.c b/hw/pc.c
index f0802b7..ce533ea 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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,
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index c89042f..cea69a0 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -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) {
diff --git a/hw/pci.c b/hw/pci.c
index 749e8d8..a27eec1 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -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);
diff --git a/hw/pcie_port.c b/hw/pcie_port.c
index 8a36f5c..1cdd624 100644
--- a/hw/pcie_port.c
+++ b/hw/pcie_port.c
@@ -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);
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 672e934..c478c7b 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -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;
diff --git a/hw/ppc440.c b/hw/ppc440.c
index cd8a95d..483dedf 100644
--- a/hw/ppc440.c
+++ b/hw/ppc440.c
@@ -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;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index f0b811c..98e4184 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -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");
diff --git a/hw/spapr.c b/hw/spapr.c
index b118975..b2b7a06 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -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
diff --git a/hw/sysbus.c b/hw/sysbus.c
index 4fab5a4..b270a89 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -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;
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index ae2d384..7ff3638 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -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);
}
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index bd374c1..501c9ff 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -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);
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 01e2e7c..96b005f 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -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++) {
diff --git a/hw/vga-isa-mm.c b/hw/vga-isa-mm.c
index f8984c6..10f510b 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/vga-isa-mm.c
@@ -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);
diff --git a/hw/vga.c b/hw/vga.c
index ca79aa1..b89bb1e 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -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);
diff --git a/hw/vhost.c b/hw/vhost.c
index 0870cb7..30c48c7 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -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;
}
diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index 950a6b8..4db5ae1 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -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;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2a5d1a9..f11130a 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -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;
diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index 41accbb..0a57a4a 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -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);
}
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 8a9fac4..1146c70 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -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);
diff --git a/hw/xics.c b/hw/xics.c
index 1c5eaa4..29f2c78 100644
--- a/hw/xics.c
+++ b/hw/xics.c
@@ -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));
diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c
index 3cebca1..424ddf2 100644
--- a/hw/xtensa_lx60.c
+++ b/hw/xtensa_lx60.c
@@ -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);
diff --git a/hw/xtensa_sim.c b/hw/xtensa_sim.c
index a94e4e5..a9188e9 100644
--- a/hw/xtensa_sim.c
+++ b/hw/xtensa_sim.c
@@ -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);
diff --git a/linux-aio.c b/linux-aio.c
index 1c635ef..e4101e2 100644
--- a/linux-aio.c
+++ b/linux-aio.c
@@ -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;
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8677bba..56abc8c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -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);
diff --git a/memory.c b/memory.c
index dc5e35d..51017d5 100644
--- a/memory.c
+++ b/memory.c
@@ -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);
diff --git a/migration-exec.c b/migration-exec.c
index 2cfb6f2..ccb5dee 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -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) {
diff --git a/migration-fd.c b/migration-fd.c
index aee690a..6ae2c68 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -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) {
diff --git a/migration-tcp.c b/migration-tcp.c
index c431e03..5f03aee 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -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;
diff --git a/migration-unix.c b/migration-unix.c
index 6dc985d..905d2b1 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -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;
diff --git a/module.c b/module.c
index 91f0e61..50eb77f 100644
--- a/module.c
+++ b/module.c
@@ -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);
diff --git a/monitor.c b/monitor.c
index ffda0fe..1732616 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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;
diff --git a/net/slirp.c b/net/slirp.c
index c6cda5d..ce29404 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -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;
diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index a154523..7ed00a9 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -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;
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index 8cbc0ab..9ea1d90 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -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;
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index d67724e..ea4465a 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -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;
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index 5ff99cf..e84a701 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -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;
diff --git a/qbool.c b/qbool.c
index 590cd71..abbd01b 100644
--- a/qbool.c
+++ b/qbool.c
@@ -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);
diff --git a/qdict.c b/qdict.c
index 4bf308b..391ae32 100644
--- a/qdict.c
+++ b/qdict.c
@@ -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;
diff --git a/qemu-char.c b/qemu-char.c
index fb9e058..ab75c21 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -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);
diff --git a/qemu-io.c b/qemu-io.c
index e91af37..804ac06 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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;
diff --git a/qemu-option.c b/qemu-option.c
index 105d760..2fade1d 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -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);
}
diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c
index db8e744..9a6a41c 100644
--- a/qemu-thread-win32.c
+++ b/qemu-thread-win32.c
@@ -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;
diff --git a/qerror.c b/qerror.c
index 68998d4..761626c 100644
--- a/qerror.c
+++ b/qerror.c
@@ -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;
diff --git a/qfloat.c b/qfloat.c
index 98338f3..4610c6b 100644
--- a/qfloat.c
+++ b/qfloat.c
@@ -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);
diff --git a/qint.c b/qint.c
index ee51804..06a080b 100644
--- a/qint.c
+++ b/qint.c
@@ -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);
diff --git a/qlist.c b/qlist.c
index 88498b1..cf3dcf8 100644
--- a/qlist.c
+++ b/qlist.c
@@ -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);
diff --git a/qmp.c b/qmp.c
index bf58b05..f840379 100644
--- a/qmp.c
+++ b/qmp.c
@@ -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],
diff --git a/qstring.c b/qstring.c
index b7e12e4..ea076c1 100644
--- a/qstring.c
+++ b/qstring.c
@@ -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;
diff --git a/readline.c b/readline.c
index 6a3160a..bb4a756 100644
--- a/readline.c
+++ b/readline.c
@@ -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;
diff --git a/target-xtensa/helper.c b/target-xtensa/helper.c
index fc85815..445e61b 100644
--- a/target-xtensa/helper.c
+++ b/target-xtensa/helper.c
@@ -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);
diff --git a/ui/keymaps.c b/ui/keymaps.c
index f54a114..54bfee7 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -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;
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 3cbc721..14bb233 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -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);
}
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 6c302a3..60e8214 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -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;
diff --git a/ui/spice-input.c b/ui/spice-input.c
index af4223d..76df659 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -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);
diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index 63d5f64..64176a9 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -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;
}
diff --git a/ui/vnc.c b/ui/vnc.c
index fc3a612..2ae9121 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -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));
diff --git a/usb-linux.c b/usb-linux.c
index 7d4d1d7..77c0252 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -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;
diff --git a/vl.c b/vl.c
index 2dce3ae..df96c11 100644
--- a/vl.c
+++ b/vl.c
@@ -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);
diff --git a/xen-all.c b/xen-all.c
index b5e28ab..d0988c9 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -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;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 3/5] Convert use of ptr = g_malloc(sizeof(type)) to g_new()
2011-10-20 8:03 [Qemu-devel] [PATCH 1/5] Convert calls to g_malloc() using casts to g_new() Stuart Brady
2011-10-20 8:03 ` [Qemu-devel] [PATCH 2/5] Convert use of ptr = g_malloc(sizeof(*ptr)) " Stuart Brady
@ 2011-10-20 8:03 ` Stuart Brady
2011-10-20 8:03 ` [Qemu-devel] [PATCH 4/5] Convert remaining calls to g_malloc(sizeof(type)) using casts " Stuart Brady
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Stuart Brady @ 2011-10-20 8:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Stuart Brady
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(-)
diff --git a/aio.c b/aio.c
index 1239ca7..b01a87b 100644
--- a/aio.c
+++ b/aio.c
@@ -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);
}
diff --git a/async.c b/async.c
index ca13962..b76f85e 100644
--- a/async.c
+++ b/async.c
@@ -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;
diff --git a/block-migration.c b/block-migration.c
index e2775ee..1bf7328 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -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;
diff --git a/block.c b/block.c
index cc69c87..6a8560c 100644
--- a/block.c
+++ b/block.c
@@ -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);
diff --git a/block/qcow.c b/block/qcow.c
index eba5a04..d2f0717 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -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);
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 2f76311..d593b8c 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -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;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 9605367..4eb400e 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -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,
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index bdc33ba..4c170d86 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -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;
diff --git a/block/rbd.c b/block/rbd.c
index fce09e6..91d887d 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -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;
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 313b995..6147f04 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -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));
diff --git a/block/vdi.c b/block/vdi.c
index 1d5ad2b..1672e61 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -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. */
diff --git a/block/vmdk.c b/block/vmdk.c
index 5d16ec4..b99bd6c 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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);
diff --git a/bt-host.c b/bt-host.c
index df5b7cd..0c395e9 100644
--- a/bt-host.c
+++ b/bt-host.c
@@ -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;
diff --git a/bt-vhci.c b/bt-vhci.c
index bbc1029..0862451 100644
--- a/bt-vhci.c
+++ b/bt-vhci.c
@@ -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;
diff --git a/console.c b/console.c
index 2545252..efd6ea8 100644
--- a/console.c
+++ b/console.c
@@ -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");
diff --git a/cutils.c b/cutils.c
index c91f887..a57b423 100644
--- a/cutils.c
+++ b/cutils.c
@@ -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;
diff --git a/exec.c b/exec.c
index 790dc1a..248ff58 100644
--- a/exec.c
+++ b/exec.c
@@ -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 */
diff --git a/gdbstub.c b/gdbstub.c
index 9b8103b..b94f42b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -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);
diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index 5c8b5ed..f947dfb 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -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;
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e276ecc..5239672 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -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);
diff --git a/hw/adb.c b/hw/adb.c
index aa15f55..b543ee1 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -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");
diff --git a/hw/applesmc.c b/hw/applesmc.c
index c47b592..19b04ca 100644
--- a/hw/applesmc.c
+++ b/hw/applesmc.c
@@ -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;
diff --git a/hw/baum.c b/hw/baum.c
index 86d780a..f95befe 100644
--- a/hw/baum.c
+++ b/hw/baum.c
@@ -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;
diff --git a/hw/bitbang_i2c.c b/hw/bitbang_i2c.c
index 431359d..af54454 100644
--- a/hw/bitbang_i2c.c
+++ b/hw/bitbang_i2c.c
@@ -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;
diff --git a/hw/blizzard.c b/hw/blizzard.c
index b2c1b22..e413a02 100644
--- a/hw/blizzard.c
+++ b/hw/blizzard.c
@@ -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;
diff --git a/hw/bt-hci.c b/hw/bt-hci.c
index a3a7fb4..4537cca 100644
--- a/hw/bt-hci.c
+++ b/hw/bt-hci.c
@@ -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);
diff --git a/hw/bt-l2cap.c b/hw/bt-l2cap.c
index 48f0715..930f183 100644
--- a/hw/bt-l2cap.c
+++ b/hw/bt-l2cap.c
@@ -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;
diff --git a/hw/bt.c b/hw/bt.c
index dc99fc2..dcfa7bc 100644
--- a/hw/bt.c
+++ b/hw/bt.c
@@ -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;
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index d62cee4..2521063 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -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);
diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index f66844b..953f8fd 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -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;
diff --git a/hw/heathrow_pic.c b/hw/heathrow_pic.c
index 16f48d1..aac5ef2 100644
--- a/hw/heathrow_pic.c
+++ b/hw/heathrow_pic.c
@@ -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,
diff --git a/hw/i8259.c b/hw/i8259.c
index ab519de..96bd078 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -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);
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 37b8239..94053c3 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -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)
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
index 2ec21b0..b8f9749 100644
--- a/hw/ide/mmio.c
+++ b/hw/ide/mmio.c
@@ -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);
diff --git a/hw/irq.c b/hw/irq.c
index ab654e7..1730502 100644
--- a/hw/irq.c
+++ b/hw/irq.c
@@ -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];
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 6bd6ff6..68be030 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -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);
diff --git a/hw/jazz_led.c b/hw/jazz_led.c
index eb472a0..99d8621 100644
--- a/hw/jazz_led.c
+++ b/hw/jazz_led.c
@@ -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;
diff --git a/hw/leon3.c b/hw/leon3.c
index 607ec85..bb31f57 100644
--- a/hw/leon3.c
+++ b/hw/leon3.c
@@ -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);
diff --git a/hw/lm32_boards.c b/hw/lm32_boards.c
index 97e1c00..1c10968 100644
--- a/hw/lm32_boards.c
+++ b/hw/lm32_boards.c
@@ -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";
diff --git a/hw/lm32_hwsetup.h b/hw/lm32_hwsetup.h
index 8fc285e..b305789 100644
--- a/hw/lm32_hwsetup.h
+++ b/hw/lm32_hwsetup.h
@@ -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;
diff --git a/hw/mac_dbdma.c b/hw/mac_dbdma.c
index 5affdd1..7bfac0e 100644
--- a/hw/mac_dbdma.c
+++ b/hw/mac_dbdma.c
@@ -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;
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index ed0a2b7..f9c5b97 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -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;
diff --git a/hw/mcf_intc.c b/hw/mcf_intc.c
index 99092e7..40ccede 100644
--- a/hw/mcf_intc.c
+++ b/hw/mcf_intc.c
@@ -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);
diff --git a/hw/mcf_uart.c b/hw/mcf_uart.c
index e6b2ab0..546021e 100644
--- a/hw/mcf_uart.c
+++ b/hw/mcf_uart.c
@@ -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) {
diff --git a/hw/milkymist.c b/hw/milkymist.c
index b7a8c1c..4c5f810 100644
--- a/hw/milkymist.c
+++ b/hw/milkymist.c
@@ -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";
diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
index 7407158..cc2cdcb 100644
--- a/hw/mips_mipssim.c
+++ b/hw/mips_mipssim.c
@@ -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);
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index d0564d4..07fd053 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -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);
diff --git a/hw/msmouse.c b/hw/msmouse.c
index c3b57ea..8ab4254 100644
--- a/hw/msmouse.c
+++ b/hw/msmouse.c
@@ -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;
diff --git a/hw/omap.h b/hw/omap.h
index cc09a3c..5583be6 100644
--- a/hw/omap.h
+++ b/hw/omap.h
@@ -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;
diff --git a/hw/omap_gpio.c b/hw/omap_gpio.c
index 42e59c3..b933852 100644
--- a/hw/omap_gpio.c
+++ b/hw/omap_gpio.c
@@ -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++) {
diff --git a/hw/omap_l4.c b/hw/omap_l4.c
index e809352..2439fed 100644
--- a/hw/omap_l4.c
+++ b/hw/omap_l4.c
@@ -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;
diff --git a/hw/parallel.c b/hw/parallel.c
index 8494d94..dadecab 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -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;
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 06b40c5..536ede4 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -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;
diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c
index 69b8e3d..5bce298 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -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,
diff --git a/hw/pflash_cfi02.c b/hw/pflash_cfi02.c
index e5a63da..5c0966a 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/pflash_cfi02.c
@@ -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);
diff --git a/hw/ppc.c b/hw/ppc.c
index 25b59dd..d3506c3 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -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;
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index c478c7b..36a3628 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -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);
diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
index a6e7431..8b10013 100644
--- a/hw/ppc405_uc.c
+++ b/hw/ppc405_uc.c
@@ -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] =
diff --git a/hw/ppc440.c b/hw/ppc440.c
index 483dedf..2790620 100644
--- a/hw/ppc440.c
+++ b/hw/ppc440.c
@@ -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]];
diff --git a/hw/ppc4xx_devs.c b/hw/ppc4xx_devs.c
index d18caa4..630826e 100644
--- a/hw/ppc4xx_devs.c
+++ b/hw/ppc4xx_devs.c
@@ -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;
diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c
index 339b38e..73fadde 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc4xx_pci.c
@@ -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,
diff --git a/hw/ppc_booke.c b/hw/ppc_booke.c
index 8871945..075620c 100644
--- a/hw/ppc_booke.c
+++ b/hw/ppc_booke.c
@@ -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;
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index 8c84f9e..ec90742 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -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++) {
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index ebcaafa..ae253bd 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -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 */
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 6427baa..6e0225c 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -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);
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index 5bf8eab..ea26e86 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -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 {
diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index 149807a..ea6dfcf 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -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,
diff --git a/hw/pxa2xx_dma.c b/hw/pxa2xx_dma.c
index 07ec2db..fff2a40 100644
--- a/hw/pxa2xx_dma.c
+++ b/hw/pxa2xx_dma.c
@@ -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 ++)
diff --git a/hw/qxl.c b/hw/qxl.c
index 03848ed..c17f1cd 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -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;
diff --git a/hw/r2d.c b/hw/r2d.c
index 82377a0..96eeb80 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -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);
diff --git a/hw/rc4030.c b/hw/rc4030.c
index eab402a..fdeee6f 100644
--- a/hw/rc4030.c
+++ b/hw/rc4030.c
@@ -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);
diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index 778cffe..2e5077d 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -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;
diff --git a/hw/serial.c b/hw/serial.c
index d35c7a9..1dd684f 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -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;
diff --git a/hw/sh7750.c b/hw/sh7750.c
index 9f3ea92..506877a 100644
--- a/hw/sh7750.c
+++ b/hw/sh7750.c
@@ -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,
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
index a20c59e..b571a86 100644
--- a/hw/sh_serial.c
+++ b/hw/sh_serial.c
@@ -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;
diff --git a/hw/slavio_timer.c b/hw/slavio_timer.c
index 84449ba..89a70a8 100644
--- a/hw/slavio_timer.c
+++ b/hw/slavio_timer.c
@@ -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;
diff --git a/hw/strongarm.c b/hw/strongarm.c
index 6097ea2..09d0461 100644
--- a/hw/strongarm.c
+++ b/hw/strongarm.c
@@ -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";
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 96fc3d0..26a9f58 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -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);
diff --git a/hw/syborg_interrupt.c b/hw/syborg_interrupt.c
index 1b0f3bb..9f5d2e0 100644
--- a/hw/syborg_interrupt.c
+++ b/hw/syborg_interrupt.c
@@ -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);
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 171d787..9709d78 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -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;
diff --git a/hw/vga.c b/hw/vga.c
index b89bb1e..3778200 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -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;
diff --git a/hw/virtex_ml507.c b/hw/virtex_ml507.c
index d31a204..23e416d 100644
--- a/hw/virtex_ml507.c
+++ b/hw/virtex_ml507.c
@@ -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);
diff --git a/hw/xenfb.c b/hw/xenfb.c
index 1bcf171..08b0748 100644
--- a/hw/xenfb.c
+++ b/hw/xenfb.c
@@ -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,
diff --git a/hw/xics.c b/hw/xics.c
index 29f2c78..dcf52d0 100644
--- a/hw/xics.c
+++ b/hw/xics.c
@@ -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;
diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c
index 424ddf2..44f6222 100644
--- a/hw/xtensa_lx60.c
+++ b/hw/xtensa_lx60.c
@@ -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);
diff --git a/input.c b/input.c
index e2f7c92..810a6ca 100644
--- a/input.c
+++ b/input.c
@@ -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;
diff --git a/iohandler.c b/iohandler.c
index 4cc1c5a..6a7f5df 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -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;
diff --git a/kvm-all.c b/kvm-all.c
index e7faf5c..fe4647e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -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;
}
diff --git a/linux-user/main.c b/linux-user/main.c
index 186358b..fc092f5 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7735008..6beedd8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);
diff --git a/monitor.c b/monitor.c
index 1732616..87ce79f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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;
diff --git a/net.c b/net.c
index d05930c..839778b 100644
--- a/net.c
+++ b/net.c
@@ -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);
diff --git a/net/queue.c b/net/queue.c
index 1ab5247..e359405 100644
--- a/net/queue.c
+++ b/net/queue.c
@@ -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;
diff --git a/net/slirp.c b/net/slirp.c
index ce29404..a0007e2 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -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) {
diff --git a/net/socket.c b/net/socket.c
index e9ef128..6d2c4b4 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -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) {
diff --git a/os-win32.c b/os-win32.c
index f09f01f..9af4ab8 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -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);
diff --git a/pflib.c b/pflib.c
index 64cb2b3..4e8484a 100644
--- a/pflib.c
+++ b/pflib.c
@@ -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;
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index d3c1174..b64b49a 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -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) {
diff --git a/qemu-char.c b/qemu-char.c
index ab75c21..b0a521f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -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) {
diff --git a/qemu-ga.c b/qemu-ga.c
index 4932013..0e1ee24 100644
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -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;
diff --git a/qemu-img.c b/qemu-img.c
index 6a39731..0099f23 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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++) {
diff --git a/qemu-nbd.c b/qemu-nbd.c
index d8d3e15..f6cd213 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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);
diff --git a/qemu-timer.c b/qemu-timer.c
index ad1fc8b..e3413e9 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -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;
diff --git a/qga/guest-agent-command-state.c b/qga/guest-agent-command-state.c
index 969da23..128c549 100644
--- a/qga/guest-agent-command-state.c
+++ b/qga/guest-agent-command-state.c
@@ -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;
}
diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c
index 6da9904..52419c0 100644
--- a/qga/guest-agent-commands.c
+++ b/qga/guest-agent-commands.c
@@ -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);
diff --git a/savevm.c b/savevm.c
index bf4d0e7..51f71f7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -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];
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 19d69eb..b89f072 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -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();
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index ac52202..86c4c1b 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -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;
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index a961159..c808c32 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -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);
diff --git a/target-arm/helper.c b/target-arm/helper.c
index e2428eb..daad3ba 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -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;
diff --git a/target-cris/translate.c b/target-cris/translate.c
index 70abf8a..42ca59d 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -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);
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 1e8bcff..297019f 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -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;
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 5df40d4..7ee3aa8 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 90a6ffb..bcc645b 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -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);
}
diff --git a/target-lm32/helper.c b/target-lm32/helper.c
index fc0b444..f82beed 100644
--- a/target-lm32/helper.c
+++ b/target-lm32/helper.c
@@ -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;
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 674c8e6..81acc36 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -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;
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
index 366fd3e..90f8175 100644
--- a/target-microblaze/translate.c
+++ b/target-microblaze/translate.c
@@ -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);
diff --git a/target-mips/translate.c b/target-mips/translate.c
index d5b1c76..1bf2eb9 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -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;
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 6339be3..af1fc41 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -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();
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 96dd867..6cd06c0 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -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;
diff --git a/target-sh4/translate.c b/target-sh4/translate.c
index bad3577..62cc274 100644
--- a/target-sh4/translate.c
+++ b/target-sh4/translate.c
@@ -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);
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index c80531a..e70835c 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -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);
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index b5b1cb7..1cf38b0 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -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);
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 30f3aef..71f308a 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -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];
diff --git a/test-qmp-commands.c b/test-qmp-commands.c
index fa5a7bd..f44b6df 100644
--- a/test-qmp-commands.c
+++ b/test-qmp-commands.c
@@ -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;
diff --git a/test-visitor.c b/test-visitor.c
index 847ce14..9fa16ea 100644
--- a/test-visitor.c
+++ b/test-visitor.c
@@ -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;
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 54bfee7..1f5980c 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -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);
diff --git a/ui/sdl.c b/ui/sdl.c
index 298bacd..4590961 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -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;
diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c
index de5ea6b..ce13fa6 100644
--- a/ui/vnc-jobs-async.c
+++ b/ui/vnc-jobs-async.c
@@ -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);
diff --git a/ui/vnc.c b/ui/vnc.c
index 2ae9121..4e28e34 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -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;
diff --git a/usb-linux.c b/usb-linux.c
index 77c0252..dcd4149 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -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;
diff --git a/usb-redir.c b/usb-redir.c
index a764cc8..e7a9b44 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -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;
diff --git a/vl.c b/vl.c
index df96c11..e6a8498 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
diff --git a/xen-all.c b/xen-all.c
index d0988c9..415fde6 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -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) {
diff --git a/xen-mapcache.c b/xen-mapcache.c
index 8162b69..04a8196 100644
--- a/xen-mapcache.c
+++ b/xen-mapcache.c
@@ -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;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread