Use g_new() & friends where that makes obvious sense
Subsystems (2)
cover Use g_new() & friends where that makes obvious sense
PATCH 1/2 fixes a bug found by compiling the original PATCH 2/2. Evidence for my claim that PATCH 2/2 lets the compiler catch more type errors :)
Markus Armbruster (2):
qga: Fix memory allocation pasto
Use g_new() & friends where that makes obvious sense
aio-posix.c | 2 +- aio-win32.c | 2 +- async.c | 2 +- backends/baum.c | 4 ++-- backends/msmouse.c | 2 +- block-migration.c | 6 ++--- block.c | 8 +++---- block/gluster.c | 4 ++-- block/iscsi.c | 2 +- block/qcow.c | 4 ++-- block/qcow2-cluster.c | 2 +- block/qcow2-refcount.c | 8 +++---- block/qcow2-snapshot.c | 8 +++---- block/raw-posix.c | 2 +- block/rbd.c | 4 ++-- block/sheepdog.c | 4 ++-- block/vdi.c | 2 +- block/vhdx.c | 4 ++-- block/vmdk.c | 7 +++--- block/vvfat.c | 2 +- blockdev-nbd.c | 2 +- blockdev.c | 2 +- bsd-user/syscall.c | 2 +- bt-host.c | 2 +- bt-vhci.c | 2 +- cpus.c | 14 ++++++------ dump.c | 2 +- exec.c | 2 +- gdbstub.c | 4 ++-- hw/9pfs/virtio-9p-handle.c | 2 +- hw/9pfs/virtio-9p-proxy.c | 2 +- hw/9pfs/virtio-9p-synth.c | 4 ++-- hw/9pfs/virtio-9p.c | 6 ++--- hw/arm/integratorcp.c | 2 +- hw/arm/omap1.c | 30 +++++++++---------------- hw/arm/omap2.c | 15 +++++-------- hw/arm/pxa2xx.c | 14 +++++------- hw/arm/stellaris.c | 2 +- hw/arm/strongarm.c | 2 +- hw/audio/intel-hda.c | 2 +- hw/bt/core.c | 4 ++-- hw/bt/hci-csr.c | 3 +-- hw/bt/hci.c | 4 ++-- hw/bt/l2cap.c | 4 ++-- hw/char/mcf_uart.c | 2 +- hw/char/omap_uart.c | 3 +-- hw/char/parallel.c | 2 +- hw/char/serial.c | 4 ++-- hw/char/sh_serial.c | 2 +- hw/char/virtio-serial-bus.c | 6 ++--- hw/core/irq.c | 2 +- hw/core/ptimer.c | 2 +- hw/display/blizzard.c | 2 +- hw/display/omap_dss.c | 3 +-- hw/display/omap_lcdc.c | 3 +-- hw/display/pxa2xx_lcd.c | 2 +- hw/display/qxl.c | 2 +- hw/display/sm501.c | 2 +- hw/display/tc6393xb.c | 2 +- hw/display/xenfb.c | 4 ++-- hw/dma/omap_dma.c | 6 ++--- hw/dma/pxa2xx_dma.c | 2 +- hw/dma/rc4030.c | 6 ++--- hw/gpio/omap_gpio.c | 4 ++-- hw/i2c/bitbang_i2c.c | 2 +- hw/i386/pc.c | 3 +-- hw/ide/ahci.c | 2 +- hw/input/pckbd.c | 2 +- hw/input/ps2.c | 4 ++-- hw/input/pxa2xx_keypad.c | 2 +- hw/input/stellaris_input.c | 4 ++-- hw/input/tsc2005.c | 3 +-- hw/input/tsc210x.c | 6 ++--- hw/intc/heathrow_pic.c | 2 +- hw/intc/i8259.c | 2 +- hw/intc/xics.c | 6 ++--- hw/intc/xics_kvm.c | 4 ++-- hw/lm32/lm32_boards.c | 4 ++-- hw/lm32/lm32_hwsetup.h | 2 +- hw/lm32/milkymist.c | 2 +- hw/m68k/mcf5206.c | 4 ++-- hw/m68k/mcf5208.c | 2 +- hw/m68k/mcf_intc.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- hw/misc/applesmc.c | 2 +- hw/misc/ivshmem.c | 8 +++---- hw/misc/macio/mac_dbdma.c | 2 +- hw/misc/omap_clk.c | 2 +- hw/misc/omap_gpmc.c | 3 +-- hw/misc/omap_sdrc.c | 3 +-- hw/misc/vfio.c | 4 ++-- hw/net/dp8393x.c | 2 +- hw/net/mcf_fec.c | 2 +- hw/net/virtio-net.c | 2 +- hw/ppc/e500.c | 4 ++-- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/ppc.c | 8 +++---- hw/ppc/ppc405_boards.c | 4 ++-- hw/ppc/ppc405_uc.c | 28 +++++++++++------------ hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/ppc4xx_devs.c | 4 ++-- hw/ppc/ppc_booke.c | 4 ++-- hw/ppc/prep.c | 2 +- hw/ppc/virtex_ml507.c | 2 +- hw/s390x/css.c | 4 ++-- hw/s390x/event-facility.c | 2 +- hw/s390x/s390-virtio.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/lsi53c895a.c | 2 +- hw/scsi/virtio-scsi.c | 2 +- hw/sd/omap_mmc.c | 6 ++--- hw/sd/pxa2xx_mmci.c | 2 +- hw/sd/sd.c | 2 +- hw/sh4/r2d.c | 4 ++-- hw/sh4/sh7750.c | 2 +- hw/sparc/leon3.c | 2 +- hw/sparc64/sun4u.c | 4 ++-- hw/ssi/omap_spi.c | 3 +-- hw/timer/arm_timer.c | 2 +- hw/timer/omap_gptimer.c | 3 +-- hw/timer/sh_timer.c | 4 ++-- hw/timer/slavio_timer.c | 2 +- hw/usb/ccid-card-emulated.c | 4 ++-- hw/usb/hcd-xhci.c | 2 +- hw/usb/redirect.c | 6 ++--- hw/virtio/virtio.c | 2 +- hw/xtensa/xtensa_lx60.c | 2 +- include/qemu/timer.h | 2 +- iohandler.c | 4 ++-- kvm-all.c | 8 +++---- libcacard/cac.c | 2 +- libcacard/card_7816.c | 8 +++---- libcacard/event.c | 2 +- libcacard/vcard.c | 6 ++--- libcacard/vcard_emul_nss.c | 12 +++++----- libcacard/vreader.c | 7 +++--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- main-loop.c | 2 +- memory_mapping.c | 2 +- migration-rdma.c | 16 ++++++------- monitor.c | 4 ++-- nbd.c | 4 ++-- net/queue.c | 2 +- net/slirp.c | 2 +- qemu-char.c | 46 +++++++++++++++++++------------------- qemu-file.c | 10 ++++----- qemu-img.c | 2 +- qemu-io-cmds.c | 2 +- qemu-io.c | 2 +- qemu-timer.c | 2 +- qga/channel-posix.c | 2 +- qga/channel-win32.c | 2 +- qga/commands-posix.c | 10 ++++----- qga/commands-win32.c | 4 ++-- qga/commands.c | 6 ++--- qga/guest-agent-command-state.c | 4 ++-- qga/main.c | 2 +- qobject/json-parser.c | 4 ++-- savevm.c | 12 +++++----- slirp/slirp.c | 2 +- spice-qemu-char.c | 4 ++-- target-i386/kvm.c | 2 +- tcg/tcg.c | 4 ++-- tests/test-qmp-commands.c | 16 ++++++------- tests/test-qmp-output-visitor.c | 2 +- tests/test-visitor-serialization.c | 2 +- translate-all.c | 2 +- ui/console.c | 4 ++-- ui/curses.c | 2 +- ui/input.c | 8 +++---- ui/keymaps.c | 2 +- ui/sdl.c | 2 +- ui/vnc-jobs.c | 6 ++--- ui/vnc.c | 4 ++-- util/hbitmap.c | 4 ++-- util/iov.c | 4 ++-- util/qemu-option.c | 2 +- util/uri.c | 2 +- vl.c | 6 ++--- xen-all.c | 8 +++---- xen-mapcache.c | 14 ++++++------ 186 files changed, 376 insertions(+), 415 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/2 qga: Fix memory allocation pasto
qmp_guest_file_seek() allocates memory for a GuestFileRead object instead of the GuestFileSeek object it actually uses. Harmless, because the GuestFileRead is slightly larger.
--- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
@@ -525,7 +525,7 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,if (ret ==-1 ) {error_setg_errno (err, errno,"failed to seek file" ); }else { - seek_data =g_malloc0 (sizeof (GuestFileRead)); + seek_data =g_new0 (GuestFileSeek,1 ); seek_data->position =ftell (fh); seek_data->eof =feof (fh); }
Signature · 1 line
1.8.1.4
PATCH 2/2 Use g_new() & friends where that makes obvious sense
In reply to Markus Armbrusterg_new(T, n) is safer than g_malloc(sizeof(T) * n) for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors.
Patch created with the following Coccinelle patch, with two hunks dropped from the result:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression n;
@@
-(T *)g_new(T, n)
+g_new(T, n)
@@
type T;
expression n;
@@
-(T *)g_new0(T, n)
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)First dropped hunk:
diff --git a/hw/9pfs/virtio-9p-synth.c b/hw/9pfs/virtio-9p-synth.c
index fd888d6..96ef2b0 100644
--- a/hw/9pfs/virtio-9p-synth.c
+++ b/hw/9pfs/virtio-9p-synth.c
@@ -497,7 +497,7 @@ static int v9fs_synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
}
out:
/* Copy the node pointer to fid */
- target->data = g_new(void *, 1);
+ target->data = g_malloc(sizeof(void *));
memcpy(target->data, &node, sizeof(void *));
target->size = sizeof(void *);
return 0;Here, the value of g_malloc() is assigned to a variable of type char *. The value of g_new() would need a type cast, which in my opinion makes the change pointless.
Second dropped hunk:
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index c030a20..6c6591e 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -7573,7 +7573,7 @@ static int create_new_table (opc_handler_t **table, unsigned char idx)
{
opc_handler_t **tmp;
- tmp = g_malloc(0x20 * sizeof(opc_handler_t));
+ tmp = g_new(opc_handler_t *, 0x20);
fill_new_table(tmp, 0x20);
table[idx] = (opc_handler_t *)((uintptr_t)tmp | PPC_INDIRECT);Here, I suspect a bug, namely allocating opc_handler_t[0x20] instead of opc_handler_t *[0x20]. But there's so much dirty hackery going on around this array that I refuse to touch it.
--- aio-posix.c | 2 +- aio-win32.c | 2 +- async.c | 2 +- backends/baum.c | 4 ++-- backends/msmouse.c | 2 +- block-migration.c | 6 ++--- block.c | 8 +++---- block/gluster.c | 4 ++-- block/iscsi.c | 2 +- block/qcow.c | 4 ++-- block/qcow2-cluster.c | 2 +- block/qcow2-refcount.c | 8 +++---- block/qcow2-snapshot.c | 8 +++---- block/raw-posix.c | 2 +- block/rbd.c | 4 ++-- block/sheepdog.c | 4 ++-- block/vdi.c | 2 +- block/vhdx.c | 4 ++-- block/vmdk.c | 7 +++--- block/vvfat.c | 2 +- blockdev-nbd.c | 2 +- blockdev.c | 2 +- bsd-user/syscall.c | 2 +- bt-host.c | 2 +- bt-vhci.c | 2 +- cpus.c | 14 ++++++------ dump.c | 2 +- exec.c | 2 +- gdbstub.c | 4 ++-- hw/9pfs/virtio-9p-handle.c | 2 +- hw/9pfs/virtio-9p-proxy.c | 2 +- hw/9pfs/virtio-9p-synth.c | 4 ++-- hw/9pfs/virtio-9p.c | 6 ++--- hw/arm/integratorcp.c | 2 +- hw/arm/omap1.c | 30 +++++++++---------------- hw/arm/omap2.c | 15 +++++-------- hw/arm/pxa2xx.c | 14 +++++------- hw/arm/stellaris.c | 2 +- hw/arm/strongarm.c | 2 +- hw/audio/intel-hda.c | 2 +- hw/bt/core.c | 4 ++-- hw/bt/hci-csr.c | 3 +-- hw/bt/hci.c | 4 ++-- hw/bt/l2cap.c | 4 ++-- hw/char/mcf_uart.c | 2 +- hw/char/omap_uart.c | 3 +-- hw/char/parallel.c | 2 +- hw/char/serial.c | 4 ++-- hw/char/sh_serial.c | 2 +- hw/char/virtio-serial-bus.c | 6 ++--- hw/core/irq.c | 2 +- hw/core/ptimer.c | 2 +- hw/display/blizzard.c | 2 +- hw/display/omap_dss.c | 3 +-- hw/display/omap_lcdc.c | 3 +-- hw/display/pxa2xx_lcd.c | 2 +- hw/display/qxl.c | 2 +- hw/display/sm501.c | 2 +- hw/display/tc6393xb.c | 2 +- hw/display/xenfb.c | 4 ++-- hw/dma/omap_dma.c | 6 ++--- hw/dma/pxa2xx_dma.c | 2 +- hw/dma/rc4030.c | 6 ++--- hw/gpio/omap_gpio.c | 4 ++-- hw/i2c/bitbang_i2c.c | 2 +- hw/i386/pc.c | 3 +-- hw/ide/ahci.c | 2 +- hw/input/pckbd.c | 2 +- hw/input/ps2.c | 4 ++-- hw/input/pxa2xx_keypad.c | 2 +- hw/input/stellaris_input.c | 4 ++-- hw/input/tsc2005.c | 3 +-- hw/input/tsc210x.c | 6 ++--- hw/intc/heathrow_pic.c | 2 +- hw/intc/i8259.c | 2 +- hw/intc/xics.c | 6 ++--- hw/intc/xics_kvm.c | 4 ++-- hw/lm32/lm32_boards.c | 4 ++-- hw/lm32/lm32_hwsetup.h | 2 +- hw/lm32/milkymist.c | 2 +- hw/m68k/mcf5206.c | 4 ++-- hw/m68k/mcf5208.c | 2 +- hw/m68k/mcf_intc.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/mips/mips_mipssim.c | 2 +- hw/mips/mips_r4k.c | 2 +- hw/misc/applesmc.c | 2 +- hw/misc/ivshmem.c | 8 +++---- hw/misc/macio/mac_dbdma.c | 2 +- hw/misc/omap_clk.c | 2 +- hw/misc/omap_gpmc.c | 3 +-- hw/misc/omap_sdrc.c | 3 +-- hw/misc/vfio.c | 4 ++-- hw/net/dp8393x.c | 2 +- hw/net/mcf_fec.c | 2 +- hw/net/virtio-net.c | 2 +- hw/ppc/e500.c | 4 ++-- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/ppc.c | 8 +++---- hw/ppc/ppc405_boards.c | 4 ++-- hw/ppc/ppc405_uc.c | 28 +++++++++++------------ hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/ppc4xx_devs.c | 4 ++-- hw/ppc/ppc_booke.c | 4 ++-- hw/ppc/prep.c | 2 +- hw/ppc/virtex_ml507.c | 2 +- hw/s390x/css.c | 4 ++-- hw/s390x/event-facility.c | 2 +- hw/s390x/s390-virtio.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/lsi53c895a.c | 2 +- hw/scsi/virtio-scsi.c | 2 +- hw/sd/omap_mmc.c | 6 ++--- hw/sd/pxa2xx_mmci.c | 2 +- hw/sd/sd.c | 2 +- hw/sh4/r2d.c | 4 ++-- hw/sh4/sh7750.c | 2 +- hw/sparc/leon3.c | 2 +- hw/sparc64/sun4u.c | 4 ++-- hw/ssi/omap_spi.c | 3 +-- hw/timer/arm_timer.c | 2 +- hw/timer/omap_gptimer.c | 3 +-- hw/timer/sh_timer.c | 4 ++-- hw/timer/slavio_timer.c | 2 +- hw/usb/ccid-card-emulated.c | 4 ++-- hw/usb/hcd-xhci.c | 2 +- hw/usb/redirect.c | 6 ++--- hw/virtio/virtio.c | 2 +- hw/xtensa/xtensa_lx60.c | 2 +- include/qemu/timer.h | 2 +- iohandler.c | 4 ++-- kvm-all.c | 8 +++---- libcacard/cac.c | 2 +- libcacard/card_7816.c | 8 +++---- libcacard/event.c | 2 +- libcacard/vcard.c | 6 ++--- libcacard/vcard_emul_nss.c | 12 +++++----- libcacard/vreader.c | 7 +++--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- main-loop.c | 2 +- memory_mapping.c | 2 +- migration-rdma.c | 16 ++++++------- monitor.c | 4 ++-- nbd.c | 4 ++-- net/queue.c | 2 +- net/slirp.c | 2 +- qemu-char.c | 46 +++++++++++++++++++------------------- qemu-file.c | 10 ++++----- qemu-img.c | 2 +- qemu-io-cmds.c | 2 +- qemu-io.c | 2 +- qemu-timer.c | 2 +- qga/channel-posix.c | 2 +- qga/channel-win32.c | 2 +- qga/commands-posix.c | 8 +++---- qga/commands-win32.c | 4 ++-- qga/commands.c | 6 ++--- qga/guest-agent-command-state.c | 4 ++-- qga/main.c | 2 +- qobject/json-parser.c | 4 ++-- savevm.c | 12 +++++----- slirp/slirp.c | 2 +- spice-qemu-char.c | 4 ++-- target-i386/kvm.c | 2 +- tcg/tcg.c | 4 ++-- tests/test-qmp-commands.c | 16 ++++++------- tests/test-qmp-output-visitor.c | 2 +- tests/test-visitor-serialization.c | 2 +- translate-all.c | 2 +- ui/console.c | 4 ++-- ui/curses.c | 2 +- ui/input.c | 8 +++---- ui/keymaps.c | 2 +- ui/sdl.c | 2 +- ui/vnc-jobs.c | 6 ++--- ui/vnc.c | 4 ++-- util/hbitmap.c | 4 ++-- util/iov.c | 4 ++-- util/qemu-option.c | 2 +- util/uri.c | 2 +- vl.c | 6 ++--- xen-all.c | 8 +++---- xen-mapcache.c | 14 ++++++------ 186 files changed, 375 insertions(+), 414 deletions(-)
aio-posix.c +1 -1
@@ -73,7 +73,7 @@ void aio_set_fd_handler(AioContext *ctx, }else {if (node ==NULL ) {/* Alloc and insert if it's not already there */ - node =g_malloc0 (sizeof (AioHandler)); + node =g_new0 (AioHandler,1 ); node->pfd.fd = fd;QLIST_INSERT_HEAD (&ctx->aio_handlers, node, node);
aio-win32.c +1 -1
@@ -61,7 +61,7 @@ void aio_set_event_notifier(AioContext *ctx, }else {if (node ==NULL ) {/* Alloc and insert if it's not already there */ - node =g_malloc0 (sizeof (AioHandler)); + node =g_new0 (AioHandler,1 ); node->e = e; node->pfd.fd = (uintptr_t )event_notifier_get_handle (e); node->pfd.events =G_IO_IN ;
async.c +1 -1
@@ -43,7 +43,7 @@ struct QEMUBH {QEMUBH *aio_bh_new (AioContext *ctx,QEMUBHFunc *cb,void *opaque) {QEMUBH *bh; - bh =g_malloc0 (sizeof (QEMUBH )); + bh =g_new0 (QEMUBH ,1 ); bh->ctx = ctx; bh->cb = cb; bh->opaque = opaque;
backends/baum.c +2 -2
@@ -571,8 +571,8 @@ CharDriverState *chr_baum_init(void)#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;
backends/msmouse.c +1 -1
@@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void) {CharDriverState *chr; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 ); chr->chr_write = msmouse_chr_write; chr->chr_close = msmouse_chr_close; chr->explicit_be_open = true;
block-migration.c +3 -3
@@ -283,7 +283,7 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) 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;
@@ -339,7 +339,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;
@@ -449,7 +449,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds, }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;
block.c +4 -4
@@ -336,7 +336,7 @@ BlockDriverState *bdrv_new(const char *device_name) {BlockDriverState *bs; - bs =g_malloc0 (sizeof (BlockDriverState)); + bs =g_new0 (BlockDriverState,1 );QLIST_INIT (&bs->dirty_bitmaps);pstrcpy (bs->device_name,sizeof (bs->device_name), device_name);if (device_name[0 ] !='\0' ) {
@@ -5026,7 +5026,7 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, int granularity) granularity >>=BDRV_SECTOR_BITS ;assert (granularity); bitmap_size = (bdrv_getlength (bs) >>BDRV_SECTOR_BITS ); - bitmap =g_malloc0 (sizeof (BdrvDirtyBitmap)); + bitmap =g_new0 (BdrvDirtyBitmap,1 ); bitmap->bitmap =hbitmap_alloc (bitmap_size,ffs (granularity) -1 );QLIST_INSERT_HEAD (&bs->dirty_bitmaps, bitmap, list);return bitmap;
@@ -5052,8 +5052,8 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)BlockDirtyInfoList **plist = &list; QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { -BlockDirtyInfo *info =g_malloc0 (sizeof (BlockDirtyInfo)); -BlockDirtyInfoList *entry =g_malloc0 (sizeof (BlockDirtyInfoList)); +BlockDirtyInfo *info =g_new0 (BlockDirtyInfo,1 ); +BlockDirtyInfoList *entry =g_new0 (BlockDirtyInfoList,1 ); info->count =bdrv_get_dirty_count (bs, bm); info->granularity = ((int64_t )BDRV_SECTOR_SIZE <<hbitmap_granularity (bm->bitmap));
block/gluster.c +2 -2
@@ -275,7 +275,7 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,BDRVGlusterState *s = bs->opaque;int open_flags =O_BINARY ;int ret =0 ; -GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf)); +GlusterConf *gconf =g_new0 (GlusterConf,1 );QemuOpts *opts;Error *local_err =NULL ;const char *filename;
@@ -387,7 +387,7 @@ static int qemu_gluster_create(const char *filename,int ret =0 ;int prealloc =0 ;int64_t total_size =0 ; -GlusterConf *gconf =g_malloc0 (sizeof (GlusterConf)); +GlusterConf *gconf =g_new0 (GlusterConf,1 ); glfs =qemu_gluster_init (gconf, filename);if (!glfs) {
block/iscsi.c +1 -1
@@ -1384,7 +1384,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options, options++; } - bs->opaque =g_malloc0 (sizeof (struct IscsiLun )); + bs->opaque = g_new0(struct IscsiLun, 1); iscsilun = bs->opaque; bs_options =qdict_new ();
block/qcow.c +2 -2
@@ -150,7 +150,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, 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); ret =bdrv_pread (bs->file, s->l1_table_offset, s->l1_table, s->l1_size *sizeof (uint64_t ));
@@ -162,7 +162,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, 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 ); s->cluster_cache =g_malloc (s->cluster_size); s->cluster_data =g_malloc (s->cluster_size); s->cluster_cache_offset =-1 ;
block/qcow2-cluster.c +1 -1
@@ -698,7 +698,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)trace_qcow2_cluster_link_l2 (qemu_coroutine_self (), m->nb_clusters);assert (m->nb_clusters >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 */ ret =perform_cow (bs, m, &m->cow_start);
block/qcow2-refcount.c +4 -4
@@ -334,7 +334,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));
@@ -1468,7 +1468,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); res->bfi.total_clusters =size_to_clusters (s, bs->total_sectors *BDRV_SECTOR_SIZE );
@@ -1545,8 +1545,8 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,/* increase refcount_table size if necessary */ int old_nb_clusters = nb_clusters; nb_clusters = (new_offset >> s->cluster_bits) +1 ; - refcount_table =g_realloc (refcount_table, - nb_clusters *sizeof (uint16_t )); + refcount_table =g_renew (uint16_t, refcount_table, + nb_clusters);memset (&refcount_table[old_nb_clusters],0 , (nb_clusters - old_nb_clusters) *sizeof (uint16_t )); }
block/qcow2-snapshot.c +4 -4
@@ -83,7 +83,7 @@ int qcow2_read_snapshots(BlockDriverState *bs) } offset = s->snapshots_offset; - s->snapshots =g_malloc0 (s->nb_snapshots *sizeof (QCowSnapshot)); + s->snapshots =g_new0 (QCowSnapshot, s->nb_snapshots);for (i =0 ; i < s->nb_snapshots; i++) {/* Read statically sized part of the snapshot header */
@@ -389,7 +389,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->l1_table_offset = l1_table_offset; sn->l1_size = s->l1_size; - l1_table =g_malloc (s->l1_size *sizeof (uint64_t )); + l1_table =g_new (uint64_t, s->l1_size);for (i =0 ; i < s->l1_size; i++) { l1_table[i] =cpu_to_be64 (s->l1_table[i]); }
@@ -420,7 +420,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) }/* Append the new snapshot to the snapshot list */ - new_snapshot_list =g_malloc ((s->nb_snapshots +1 ) *sizeof (QCowSnapshot)); + new_snapshot_list =g_new (QCowSnapshot, s->nb_snapshots +1 );if (s->snapshots) {memcpy (new_snapshot_list, s->snapshots, s->nb_snapshots *sizeof (QCowSnapshot));
@@ -658,7 +658,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;
block/raw-posix.c +1 -1
@@ -466,7 +466,7 @@ static int raw_reopen_prepare(BDRVReopenState *state, s = state->bs->opaque; - state->opaque =g_malloc0 (sizeof (BDRVRawReopenState)); + state->opaque =g_new0 (BDRVRawReopenState,1 ); raw_s = state->opaque;#ifdef CONFIG_LINUX_AIO
block/rbd.c +2 -2
@@ -648,7 +648,7 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs, off = sector_num *BDRV_SECTOR_SIZE ; size = nb_sectors *BDRV_SECTOR_SIZE ; - rcb =g_malloc (sizeof (RADOSCB )); + rcb =g_new (RADOSCB ,1 ); rcb->done =0 ; rcb->acb = acb; rcb->buf = buf;
@@ -866,7 +866,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, goto done; } - 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;
block/sheepdog.c +2 -2
@@ -1637,7 +1637,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,bool prealloc = false;Error *local_err =NULL ; - s =g_malloc0 (sizeof (BDRVSheepdogState)); + s =g_new0 (BDRVSheepdogState,1 );memset (tag,0 ,sizeof (tag));if (strstr (filename,"://" )) {
@@ -2201,7 +2201,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)uint32_t snapid =0 ;int ret =0 ; - old_s =g_malloc (sizeof (BDRVSheepdogState)); + old_s =g_new (BDRVSheepdogState,1 );memcpy (old_s, s,sizeof (BDRVSheepdogState));
block/vdi.c +1 -1
@@ -288,7 +288,7 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res,return -ENOTSUP ; } - 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. */
block/vhdx.c +2 -2
@@ -1357,7 +1357,7 @@ static int vhdx_create_new_headers(BlockDriverState *bs, uint64_t image_size,int ret =0 ;VHDXHeader *hdr =NULL ; - hdr =g_malloc0 (sizeof (VHDXHeader)); + hdr =g_new0 (VHDXHeader,1 ); hdr->signature =VHDX_HEADER_SIGNATURE ; hdr->sequence_number =g_random_int ();
@@ -1623,7 +1623,7 @@ static int vhdx_create_new_region_table(BlockDriverState *bs,/* Populate enough of the BDRVVHDXState to be able to use the * pre-existing BAT calculation, translation, and update functions */ - s =g_malloc0 (sizeof (BDRVVHDXState)); + s =g_new0 (BDRVVHDXState,1 ); s->chunk_ratio = (VHDX_MAX_SECTORS_PER_BLOCK ) * (uint64_t ) sector_size / (uint64_t ) block_size;
block/vmdk.c +3 -4
@@ -233,7 +233,7 @@ static void vmdk_free_last_extent(BlockDriverState *bs)return ; } s->num_extents--; - s->extents =g_realloc (s->extents, s->num_extents *sizeof (VmdkExtent)); + s->extents =g_renew (VmdkExtent, s->extents, s->num_extents); }static uint32_t vmdk_read_cid (BlockDriverState *bs,int parent)
@@ -412,8 +412,7 @@ static int vmdk_add_extent(BlockDriverState *bs,return -EFBIG ; } - s->extents =g_realloc (s->extents, - (s->num_extents +1 ) *sizeof (VmdkExtent)); + s->extents =g_renew (VmdkExtent, s->extents, s->num_extents +1 ); extent = &s->extents[s->num_extents]; s->num_extents++;
@@ -481,7 +480,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, } extent->l2_cache = -g_malloc (extent->l2_size *L2_CACHE_SIZE *sizeof (uint32_t )); +g_new (uint32_t, extent->l2_size *L2_CACHE_SIZE );return 0 ; fail_l1b:g_free (extent->l1_backup_table);
block/vvfat.c +1 -1
@@ -2954,7 +2954,7 @@ static int enable_write_target(BDRVVVFATState *s) s->bs->backing_hd =bdrv_new ("" ); s->bs->backing_hd->drv = &vvfat_write_target; - s->bs->backing_hd->opaque =g_malloc (sizeof (void *)); + s->bs->backing_hd->opaque = g_new(void *, 1); *(void **)s->bs->backing_hd->opaque = s;return 0 ;
blockdev-nbd.c +1 -1
@@ -103,7 +103,7 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,nbd_export_set_name (exp, device); - n =g_malloc0 (sizeof (NBDCloseNotifier)); + n =g_new0 (NBDCloseNotifier,1 ); n->n.notify = nbd_close_notifier; n->exp = exp;bdrv_add_close_notifier (bs, &n->n);
blockdev.c +1 -1
@@ -1035,7 +1035,7 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device,return NULL ; } - info =g_malloc0 (sizeof (SnapshotInfo)); + info =g_new0 (SnapshotInfo,1 ); info->id =g_strdup (sn.id_str); info->name =g_strdup (sn.name); info->date_nsec = sn.date_nsec;
bsd-user/syscall.c +1 -1
@@ -236,7 +236,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong olvoid *hnamep, *holdp, *hnewp =NULL ;size_t holdlen;abi_ulong oldlen =0 ; -int32_t *snamep =g_malloc (sizeof (int32_t ) * namelen), *p, *q, i; +int32_t *snamep =g_new (int32_t, namelen), *p, *q, i;uint32_t kind =0 ;if (oldlenp)
bt-host.c +1 -1
@@ -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;
bt-vhci.c +1 -1
@@ -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;
cpus.c +7 -7
@@ -770,7 +770,7 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)return ; } - wi =g_malloc0 (sizeof (struct qemu_work_item )); + wi = g_new0(struct qemu_work_item, 1); wi->func = func; wi->data = data; wi->free = true;
@@ -1121,8 +1121,8 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) {/* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { - cpu->thread =g_malloc0 (sizeof (QemuThread)); - cpu->halt_cond =g_malloc0 (sizeof (QemuCond)); + cpu->thread =g_new0 (QemuThread,1 ); + cpu->halt_cond =g_new0 (QemuCond,1 );qemu_cond_init (cpu->halt_cond); tcg_halt_cond = cpu->halt_cond; qemu_thread_create(cpu->thread, qemu_tcg_cpu_thread_fn, cpu,
@@ -1142,8 +1142,8 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)static void qemu_kvm_start_vcpu (CPUState *cpu) { - cpu->thread =g_malloc0 (sizeof (QemuThread)); - cpu->halt_cond =g_malloc0 (sizeof (QemuCond)); + cpu->thread =g_new0 (QemuThread,1 ); + cpu->halt_cond =g_new0 (QemuCond,1 );qemu_cond_init (cpu->halt_cond);qemu_thread_create (cpu->thread, qemu_kvm_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE );
@@ -1154,8 +1154,8 @@ static void qemu_kvm_start_vcpu(CPUState *cpu)static void qemu_dummy_start_vcpu (CPUState *cpu) { - cpu->thread =g_malloc0 (sizeof (QemuThread)); - cpu->halt_cond =g_malloc0 (sizeof (QemuCond)); + cpu->thread =g_new0 (QemuThread,1 ); + cpu->halt_cond =g_new0 (QemuCond,1 );qemu_cond_init (cpu->halt_cond);qemu_thread_create (cpu->thread, qemu_dummy_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE );
dump.c +1 -1
@@ -880,7 +880,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,return ; } - s =g_malloc0 (sizeof (DumpState)); + s =g_new0 (DumpState,1 ); ret =dump_init (s, fd, paging, has_begin, begin, length, errp);if (ret <0 ) {
exec.c +1 -1
@@ -1700,7 +1700,7 @@ static subpage_t *subpage_init(AddressSpace *as, hwaddr base) {subpage_t *mmio; - mmio =g_malloc0 (sizeof (subpage_t)); + mmio =g_new0 (subpage_t,1 ); mmio->as = as; mmio->base = base;
gdbstub.c +2 -2
@@ -1536,7 +1536,7 @@ static void gdb_accept(void)/* set short latency */ socket_set_nodelay (fd); - s =g_malloc0 (sizeof (GDBState)); + s =g_new0 (GDBState,1 ); s->c_cpu = first_cpu; s->g_cpu = first_cpu; s->fd = fd;
@@ -1705,7 +1705,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 );
hw/9pfs/virtio-9p-handle.c +1 -1
@@ -606,7 +606,7 @@ static int handle_init(FsContext *ctx)int ret, mnt_id;struct statfs stbuf;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 ) {
hw/9pfs/virtio-9p-proxy.c +1 -1
@@ -1144,7 +1144,7 @@ static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs)static int proxy_init (FsContext *ctx) { -V9fsProxy *proxy =g_malloc (sizeof (V9fsProxy)); +V9fsProxy *proxy =g_new (V9fsProxy,1 );int sock_id;if (ctx->export_flags &V9FS_PROXY_SOCK_NAME ) {
hw/9pfs/virtio-9p-synth.c +2 -2
@@ -43,7 +43,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,/* Add directory type and remove write bits */ mode = ((mode &0777 ) |S_IFDIR ) & ~(S_IWUSR |S_IWGRP |S_IWOTH ); - node =g_malloc0 (sizeof (V9fsSynthNode)); + node =g_new0 (V9fsSynthNode,1 );if (attr) {/* We are adding .. or . entries */ node->attr = attr;
@@ -124,7 +124,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode, }/* Add file type and remove write bits */ mode = ((mode &0777 ) |S_IFREG ); - node =g_malloc0 (sizeof (V9fsSynthNode)); + node =g_new0 (V9fsSynthNode,1 ); node->attr = &node->actual_attr; node->attr->inode = v9fs_synth_node_count++; node->attr->nlink =1 ;
hw/9pfs/virtio-9p.c +3 -3
@@ -256,7 +256,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 ;
@@ -1595,7 +1595,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);
@@ -1781,7 +1781,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);
hw/arm/integratorcp.c +1 -1
@@ -446,7 +446,7 @@ static void icp_control_init(hwaddr base) {MemoryRegion *io; - io = (MemoryRegion *)g_malloc0 (sizeof (MemoryRegion)); + io =g_new0 (MemoryRegion,1 );memory_region_init_io (io,NULL , &icp_control_ops,NULL ,"control" ,0x00800000 );memory_region_add_subregion (get_system_memory (), base, io);
hw/arm/omap1.c +10 -20
@@ -254,8 +254,7 @@ static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,hwaddr base, qemu_irq irq, omap_clk clk) { - struct omap_mpu_timer_s *s = (struct omap_mpu_timer_s *) -g_malloc0 (sizeof (struct omap_mpu_timer_s )); + struct omap_mpu_timer_s *s = g_new0(struct omap_mpu_timer_s, 1); s->irq = irq; s->clk = clk;
@@ -383,8 +382,7 @@ static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,hwaddr base, qemu_irq irq, omap_clk clk) { - struct omap_watchdog_timer_s *s = (struct omap_watchdog_timer_s *) -g_malloc0 (sizeof (struct omap_watchdog_timer_s )); + struct omap_watchdog_timer_s *s = g_new0(struct omap_watchdog_timer_s, 1); s->timer.irq = irq; s->timer.clk = clk;
@@ -489,8 +487,7 @@ static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,hwaddr base, qemu_irq irq, omap_clk clk) { - struct omap_32khz_timer_s *s = (struct omap_32khz_timer_s *) -g_malloc0 (sizeof (struct omap_32khz_timer_s )); + struct omap_32khz_timer_s *s = g_new0(struct omap_32khz_timer_s, 1); s->timer.irq = irq; s->timer.clk = clk;
@@ -1221,8 +1218,7 @@ static struct omap_tipb_bridge_s *omap_tipb_bridge_init( MemoryRegion *memory, hwaddr base, qemu_irq abort_irq, omap_clk clk) { - struct omap_tipb_bridge_s *s = (struct omap_tipb_bridge_s *) -g_malloc0 (sizeof (struct omap_tipb_bridge_s )); + struct omap_tipb_bridge_s *s = g_new0(struct omap_tipb_bridge_s, 1); s->abort = abort_irq;omap_tipb_bridge_reset (s);
@@ -2081,8 +2077,7 @@ static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory, qemu_irq kbd_int, qemu_irq gpio_int, qemu_irq wakeup, omap_clk clk) { - struct omap_mpuio_s *s = (struct omap_mpuio_s *) -g_malloc0 (sizeof (struct omap_mpuio_s )); + struct omap_mpuio_s *s = g_new0(struct omap_mpuio_s, 1); s->irq = gpio_int; s->kbd_irq = kbd_int;
@@ -2273,8 +2268,7 @@ static struct omap_uwire_s *omap_uwire_init(MemoryRegion *system_memory, qemu_irq dma, omap_clk clk) { -struct omap_uwire_s *s = (struct omap_uwire_s *) -g_malloc0 (sizeof (struct omap_uwire_s )); + struct omap_uwire_s *s = g_new0(struct omap_uwire_s, 1); s->txirq = txirq; s->rxirq = rxirq;
@@ -2910,8 +2904,7 @@ static struct omap_rtc_s *omap_rtc_init(MemoryRegion *system_memory, qemu_irq timerirq, qemu_irq alarmirq, omap_clk clk) { - struct omap_rtc_s *s = (struct omap_rtc_s *) -g_malloc0 (sizeof (struct omap_rtc_s )); + struct omap_rtc_s *s = g_new0(struct omap_rtc_s, 1); s->irq = timerirq; s->alarm = alarmirq;
@@ -3441,8 +3434,7 @@ static struct omap_mcbsp_s *omap_mcbsp_init(MemoryRegion *system_memory, qemu_irq txirq, qemu_irq rxirq, qemu_irq *dma, omap_clk clk) { - struct omap_mcbsp_s *s = (struct omap_mcbsp_s *) -g_malloc0 (sizeof (struct omap_mcbsp_s )); + struct omap_mcbsp_s *s = g_new0(struct omap_mcbsp_s, 1); s->txirq = txirq; s->rxirq = rxirq;
@@ -3620,8 +3612,7 @@ static void omap_lpg_clk_update(void *opaque, int line, int on)static struct omap_lpg_s *omap_lpg_init (MemoryRegion *system_memory,hwaddr base,omap_clk clk) { -struct omap_lpg_s *s = (struct omap_lpg_s *) -g_malloc0 (sizeof (struct omap_lpg_s )); + struct omap_lpg_s *s = g_new0(struct omap_lpg_s, 1); s->tm =timer_new_ms (QEMU_CLOCK_VIRTUAL , omap_lpg_tick, s);
@@ -3825,8 +3816,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory, const char *core) {int i; -struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) -g_malloc0 (sizeof (struct omap_mpu_state_s )); + struct omap_mpu_state_s *s = g_new0(struct omap_mpu_state_s, 1);qemu_irq dma_irqs[6 ];DriveInfo *dinfo;SysBusDevice *busdev;
hw/arm/omap2.c +5 -10
@@ -593,8 +593,7 @@ static const MemoryRegionOps omap_eac_ops = {static struct omap_eac_s *omap_eac_init (struct omap_target_agent_s *ta,qemu_irq irq,qemu_irq *drq,omap_clk fclk,omap_clk iclk) { -struct omap_eac_s *s = (struct omap_eac_s *) -g_malloc0 (sizeof (struct omap_eac_s )); + struct omap_eac_s *s = g_new0(struct omap_eac_s, 1); s->irq = irq; s->codec.rxdrq = *drq ++;
@@ -783,8 +782,7 @@ static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta, hwaddr channel_base, qemu_irq irq, omap_clk clk, CharDriverState *chr) { - struct omap_sti_s *s = (struct omap_sti_s *) -g_malloc0 (sizeof (struct omap_sti_s )); + struct omap_sti_s *s = g_new0(struct omap_sti_s, 1); s->irq = irq;omap_sti_reset (s);
@@ -1800,8 +1798,7 @@ static struct omap_prcm_s *omap_prcm_init(struct omap_target_agent_s *ta, qemu_irq mpu_int, qemu_irq dsp_int, qemu_irq iva_int, struct omap_mpu_state_s *mpu) { - struct omap_prcm_s *s = (struct omap_prcm_s *) -g_malloc0 (sizeof (struct omap_prcm_s )); + struct omap_prcm_s *s = g_new0(struct omap_prcm_s, 1); s->irq[0 ] = mpu_int; s->irq[1 ] = dsp_int;
@@ -2179,8 +2176,7 @@ static void omap_sysctl_reset(struct omap_sysctl_s *s)static struct omap_sysctl_s *omap_sysctl_init (struct omap_target_agent_s *ta,omap_clk iclk,struct omap_mpu_state_s *mpu) { -struct omap_sysctl_s *s = (struct omap_sysctl_s *) -g_malloc0 (sizeof (struct omap_sysctl_s )); + struct omap_sysctl_s *s = g_new0(struct omap_sysctl_s, 1); s->mpu = mpu;omap_sysctl_reset (s);
@@ -2242,8 +2238,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,unsigned long sdram_size, const char *core) { - struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) -g_malloc0 (sizeof (struct omap_mpu_state_s )); + struct omap_mpu_state_s *s = g_new0(struct omap_mpu_state_s, 1);qemu_irq dma_irqs[4 ];DriveInfo *dinfo;int i;
hw/arm/pxa2xx.c +6 -8
@@ -1739,8 +1739,7 @@ static PXA2xxI2SState *pxa2xx_i2s_init(MemoryRegion *sysmem,hwaddr base, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma) { - PXA2xxI2SState *s = (PXA2xxI2SState *) -g_malloc0 (sizeof (PXA2xxI2SState)); + PXA2xxI2SState *s = g_new0(PXA2xxI2SState, 1); s->irq = irq; s->rx_dma = rx_dma;
@@ -1997,8 +1996,7 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma, CharDriverState *chr) { - PXA2xxFIrState *s = (PXA2xxFIrState *) -g_malloc0 (sizeof (PXA2xxFIrState)); + PXA2xxFIrState *s = g_new0(PXA2xxFIrState, 1); s->irq = irq; s->rx_dma = rx_dma;
@@ -2039,7 +2037,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,PXA2xxState *s;int i;DriveInfo *dinfo; - s = (PXA2xxState *)g_malloc0 (sizeof (PXA2xxState)); + s =g_new0 (PXA2xxState,1 );if (revision &&strncmp (revision,"pxa27" ,5 )) {fprintf (stderr,"Machine requires a PXA27x processor.\n" );
@@ -2132,7 +2130,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,vmstate_register (NULL ,0 , &vmstate_pxa2xx_pm, s);for (i =0 ; pxa27x_ssp[i].io_base; i ++); - s->ssp = (SSIBus **)g_malloc0 (sizeof (SSIBus *) * i); + s->ssp = g_new0(SSIBus *, i);for (i =0 ; pxa27x_ssp[i].io_base; i ++) {DeviceState *dev; dev = sysbus_create_simple(TYPE_PXA2XX_SSP, pxa27x_ssp[i].io_base,
@@ -2177,7 +2175,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)int i;DriveInfo *dinfo; - s = (PXA2xxState *)g_malloc0 (sizeof (PXA2xxState)); + s =g_new0 (PXA2xxState,1 ); s->cpu =cpu_arm_init ("pxa255" );if (s->cpu ==NULL ) {
@@ -2263,7 +2261,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)vmstate_register (NULL ,0 , &vmstate_pxa2xx_pm, s);for (i =0 ; pxa255_ssp[i].io_base; i ++); - s->ssp = (SSIBus **)g_malloc0 (sizeof (SSIBus *) * i); + s->ssp = g_new0(SSIBus *, i);for (i =0 ; pxa255_ssp[i].io_base; i ++) {DeviceState *dev; dev = sysbus_create_simple(TYPE_PXA2XX_SSP, pxa255_ssp[i].io_base,
hw/arm/stellaris.c +1 -1
@@ -668,7 +668,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq, {ssys_state *s; - s = (ssys_state *)g_malloc0 (sizeof (ssys_state)); + s =g_new0 (ssys_state,1 ); s->irq = irq; s->board = board;/* Most devices come preprogrammed with a MAC address in the user data. */
hw/arm/strongarm.c +1 -1
@@ -1590,7 +1590,7 @@ StrongARMState *sa1110_init(MemoryRegion *sysmem,StrongARMState *s;int i; - s =g_malloc0 (sizeof (StrongARMState)); + s =g_new0 (StrongARMState,1 );if (!rev) { rev ="sa1110-b5" ;
hw/audio/intel-hda.c +1 -1
@@ -466,7 +466,7 @@ static void intel_hda_parse_bdl(IntelHDAState *d, IntelHDAStream *st) addr =intel_hda_addr (st->bdlp_lbase, st->bdlp_ubase); st->bentries = st->lvi +1 ;g_free (st->bpl); - st->bpl =g_malloc (sizeof (bpl) * st->bentries); + st->bpl =g_new (bpl, st->bentries);for (i =0 ; i < st->bentries; i++, addr +=16 ) {pci_dma_read (&d->pci, addr, buf,16 ); st->bpl[i].addr =le64_to_cpu (*(uint64_t *)buf);
hw/bt/core.c +2 -2
@@ -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;
@@ -134,7 +134,7 @@ 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 )
hw/bt/hci-csr.c +1 -2
@@ -433,8 +433,7 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (qemu_irq wakeup) { -struct csrhci_s *s = (struct csrhci_s *) -g_malloc0 (sizeof (struct csrhci_s )); + struct csrhci_s *s = g_new0(struct csrhci_s, 1); s->chr.opaque = s; s->chr.chr_write = csrhci_write;
hw/bt/hci.c +2 -2
@@ -739,7 +739,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 ;
@@ -2157,7 +2157,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 =timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_inquiry_done, s); s->lm.inquiry_next =timer_new_ns (QEMU_CLOCK_VIRTUAL , bt_hci_inquiry_next, s);
hw/bt/l2cap.c +2 -2
@@ -1239,7 +1239,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 );
@@ -1260,7 +1260,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;
hw/char/mcf_uart.c +1 -1
@@ -276,7 +276,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) {
hw/char/omap_uart.c +1 -2
@@ -55,8 +55,7 @@ struct omap_uart_s *omap_uart_init(hwaddr base, qemu_irq txdma, qemu_irq rxdma, const char *label, CharDriverState *chr) { - struct omap_uart_s *s = (struct omap_uart_s *) -g_malloc0 (sizeof (struct omap_uart_s )); + struct omap_uart_s *s = g_new0(struct omap_uart_s, 1); s->base = base; s->fclk = fclk;
hw/char/parallel.c +1 -1
@@ -581,7 +581,7 @@ bool parallel_mm_init(MemoryRegion *address_space, {ParallelState *s; - s =g_malloc0 (sizeof (ParallelState)); + s =g_new0 (ParallelState,1 ); s->irq = irq; s->chr = chr; s->it_shift = it_shift;
hw/char/serial.c +2 -2
@@ -690,7 +690,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,SerialState *s;Error *err =NULL ; - s =g_malloc0 (sizeof (SerialState)); + s =g_new0 (SerialState,1 ); s->irq = irq; s->baudbase = baudbase;
@@ -752,7 +752,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,SerialState *s;Error *err =NULL ; - s =g_malloc0 (sizeof (SerialState)); + s =g_new0 (SerialState,1 ); s->it_shift = it_shift; s->irq = irq;
hw/char/sh_serial.c +1 -1
@@ -361,7 +361,7 @@ void sh_serial_init(MemoryRegion *sysmem, {sh_serial_state *s; - 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 ;
hw/char/virtio-serial-bus.c +2 -4
@@ -921,10 +921,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)QTAILQ_INIT (&vser->ports); vser->bus.max_nr_ports = vser->serial.max_virtserial_ports; - vser->ivqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); - vser->ovqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); + vser->ivqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports); + vser->ovqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);/* Add a queue for host to guest transfers for port 0 (backward compat) */ vser->ivqs[0 ] =virtio_add_queue (vdev,128 , handle_input);
hw/core/irq.c +1 -1
@@ -114,7 +114,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 ];
hw/core/ptimer.c +1 -1
@@ -224,7 +224,7 @@ ptimer_state *ptimer_init(QEMUBH *bh) {ptimer_state *s; - s = (ptimer_state *)g_malloc0 (sizeof (ptimer_state)); + s =g_new0 (ptimer_state,1 ); s->bh = bh; s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , ptimer_tick, s);return s;
hw/display/blizzard.c +1 -1
@@ -962,7 +962,7 @@ void *s1d13745_init(qemu_irq gpio_int)switch (surface_bits_per_pixel (surface)) {case 0 : s->line_fn_tab[0 ] = s->line_fn_tab[1 ] = -g_malloc0 (sizeof (blizzard_fn_t) *0x10 ); +g_new0 (blizzard_fn_t,0x10 );break ;case 8 : s->line_fn_tab[0 ] = blizzard_draw_fn_8;
hw/display/omap_dss.c +1 -2
@@ -1046,8 +1046,7 @@ struct omap_dss_s *omap_dss_init(struct omap_target_agent_s *ta, omap_clk fck1, omap_clk fck2, omap_clk ck54m, omap_clk ick1, omap_clk ick2) { - struct omap_dss_s *s = (struct omap_dss_s *) -g_malloc0 (sizeof (struct omap_dss_s )); + struct omap_dss_s *s = g_new0(struct omap_dss_s, 1); s->irq = irq; s->drq = drq;
hw/display/omap_lcdc.c +1 -2
@@ -395,8 +395,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem, struct omap_dma_lcd_channel_s *dma, omap_clk clk) { -struct omap_lcd_panel_s *s = (struct omap_lcd_panel_s *) -g_malloc0 (sizeof (struct omap_lcd_panel_s )); + struct omap_lcd_panel_s *s = g_new0(struct omap_lcd_panel_s, 1); s->irq = irq; s->dma = dma;
hw/display/pxa2xx_lcd.c +1 -1
@@ -1002,7 +1002,7 @@ PXA2xxLCDState *pxa2xx_lcdc_init(MemoryRegion *sysmem,PXA2xxLCDState *s;DisplaySurface *surface; - s = (PXA2xxLCDState *)g_malloc0 (sizeof (PXA2xxLCDState)); + s =g_new0 (PXA2xxLCDState,1 ); s->invalidated =1 ; s->irq = irq; s->sysmem = sysmem;
hw/display/qxl.c +1 -1
@@ -2158,7 +2158,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) * (d->ssd.num_surfaces +1 )); + cmds =g_new0 (QXLCommandExt, d->ssd.num_surfaces +1 );for (in =0 , out =0 ; in < d->ssd.num_surfaces; in++) {if (d->guest_surfaces.cmds[in] ==0 ) {continue ;
hw/display/sm501.c +1 -1
@@ -1396,7 +1396,7 @@ void sm501_init(MemoryRegion *address_space_mem, uint32_t base,MemoryRegion *sm501_2d_engine =g_new (MemoryRegion,1 );/* allocate management data region */ - s = (SM501State *)g_malloc0 (sizeof (SM501State)); + s =g_new0 (SM501State,1 ); s->base = base; s->local_mem_size_index =get_local_mem_size_index (local_mem_bytes);
hw/display/tc6393xb.c +1 -1
@@ -566,7 +566,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq) }, }; - s = (TC6393xbState *)g_malloc0 (sizeof (TC6393xbState)); + s =g_new0 (TC6393xbState,1 ); s->irq = irq; s->gpio_in =qemu_allocate_irqs (tc6393xb_gpio_set, s,TC6393XB_GPIOS );
hw/display/xenfb.c +2 -2
@@ -483,8 +483,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,
hw/dma/omap_dma.c +2 -4
@@ -1625,8 +1625,7 @@ struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs, enum omap_dma_model model) {int num_irqs, memsize, i; -struct omap_dma_s *s = (struct omap_dma_s *) -g_malloc0 (sizeof (struct omap_dma_s )); + struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);if (model <= omap_dma_3_1) { num_irqs =6 ;
@@ -2059,8 +2058,7 @@ struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs, int chans, omap_clk iclk, omap_clk fclk) { int i; -struct omap_dma_s *s = (struct omap_dma_s *) -g_malloc0 (sizeof (struct omap_dma_s )); + struct omap_dma_s *s = g_new0(struct omap_dma_s, 1); s->model = omap_dma_4; s->chans = chans;
hw/dma/pxa2xx_dma.c +1 -1
@@ -459,7 +459,7 @@ static int pxa2xx_dma_init(SysBusDevice *sbd)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 ++)
hw/dma/rc4030.c +3 -3
@@ -784,8 +784,8 @@ static rc4030_dma *rc4030_allocate_dmas(void *opaque, int n)struct rc4030DMAState *p;int i; - s = (rc4030_dma *)g_malloc0 (sizeof (rc4030_dma) * n); - p = (struct rc4030DMAState *)g_malloc0 (sizeof (struct rc4030DMAState ) * n); + s =g_new0 (rc4030_dma, n); + p = g_new0(struct rc4030DMAState, n);for (i =0 ; i < n; i++) { p->opaque = opaque; p->n = i;
@@ -801,7 +801,7 @@ void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus, {rc4030State *s; - 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 );
hw/gpio/omap_gpio.c +2 -2
@@ -712,8 +712,8 @@ static int omap2_gpio_init(SysBusDevice *sbd) }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, omap2_gpio_set, s->modulecount *32 );qdev_init_gpio_out (dev, s->handler, s->modulecount *32 );for (i =0 ; i < s->modulecount; i++) {
hw/i2c/bitbang_i2c.c +1 -1
@@ -174,7 +174,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 ;
hw/i386/pc.c +1 -2
@@ -601,8 +601,7 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) }/* new "etc/e820" file -- include ram too */ - e820_table =g_realloc (e820_table, -sizeof (struct e820_entry ) * (e820_entries+1 )); + e820_table = g_renew(struct e820_entry, e820_table, e820_entries + 1); e820_table[e820_entries].address =cpu_to_le64 (address); e820_table[e820_entries].length =cpu_to_le64 (length); e820_table[e820_entries].type =cpu_to_le32 (type);
hw/ide/ahci.c +1 -1
@@ -1163,7 +1163,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports) s->as = as; s->ports = ports; - s->dev =g_malloc0 (sizeof (AHCIDevice) * ports); + s->dev =g_new0 (AHCIDevice, ports);ahci_reg_init (s);/* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ memory_region_init_io(&s->mem, OBJECT(qdev), &ahci_mem_ops, s,
hw/input/pckbd.c +1 -1
@@ -416,7 +416,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, MemoryRegion *region, ram_addr_t size, hwaddr mask) { - KBDState *s = g_malloc0(sizeof(KBDState)); + KBDState *s = g_new0(KBDState, 1); s->irq_kbd = kbd_irq; s->irq_mouse = mouse_irq;
hw/input/ps2.c +2 -2
@@ -652,7 +652,7 @@ static const VMStateDescription vmstate_ps2_mouse = {void *ps2_kbd_init (void (*update_irq)(void *,int ),void *update_arg) { -PS2KbdState *s = (PS2KbdState *)g_malloc0 (sizeof (PS2KbdState)); +PS2KbdState *s =g_new0 (PS2KbdState,1 ); s->common.update_irq = update_irq; s->common.update_arg = update_arg;
@@ -665,7 +665,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg)void *ps2_mouse_init (void (*update_irq)(void *,int ),void *update_arg) { -PS2MouseState *s = (PS2MouseState *)g_malloc0 (sizeof (PS2MouseState)); +PS2MouseState *s =g_new0 (PS2MouseState,1 ); s->common.update_irq = update_irq; s->common.update_arg = update_arg;
hw/input/pxa2xx_keypad.c +1 -1
@@ -310,7 +310,7 @@ PXA2xxKeyPadState *pxa27x_keypad_init(MemoryRegion *sysmem, {PXA2xxKeyPadState *s; - s = (PXA2xxKeyPadState *)g_malloc0 (sizeof (PXA2xxKeyPadState)); + s =g_new0 (PXA2xxKeyPadState,1 ); s->irq = irq; memory_region_init_io(&s->iomem, NULL, &pxa2xx_keypad_ops, s,
hw/input/stellaris_input.c +2 -2
@@ -77,8 +77,8 @@ void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)gamepad_state *s;int i; - s = (gamepad_state *)g_malloc0 (sizeof (gamepad_state)); - s->buttons = (gamepad_button *)g_malloc0 (n *sizeof (gamepad_button)); + s =g_new0 (gamepad_state,1 ); + s->buttons =g_new0 (gamepad_button, n);for (i =0 ; i < n; i++) { s->buttons[i].irq = irq[i]; s->buttons[i].keycode = keycode[i];
hw/input/tsc2005.c +1 -2
@@ -523,8 +523,7 @@ void *tsc2005_init(qemu_irq pintdav) {TSC2005State *s; - s = (TSC2005State *) -g_malloc0 (sizeof (TSC2005State)); + s =g_new0 (TSC2005State,1 ); s->x =400 ; s->y =240 ; s->pressure =0 ;
hw/input/tsc210x.c +2 -4
@@ -1104,8 +1104,7 @@ uWireSlave *tsc2102_init(qemu_irq pint) {TSC210xState *s; - s = (TSC210xState *) -g_malloc0 (sizeof (TSC210xState)); + s =g_new0 (TSC210xState,1 );memset (s,0 ,sizeof (TSC210xState)); s->x =160 ; s->y =160 ;
@@ -1153,8 +1152,7 @@ uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav) {TSC210xState *s; - s = (TSC210xState *) -g_malloc0 (sizeof (TSC210xState)); + s =g_new0 (TSC210xState,1 );memset (s,0 ,sizeof (TSC210xState)); s->x =400 ; s->y =240 ;
hw/intc/heathrow_pic.c +1 -1
@@ -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, NULL, &heathrow_pic_ops, s,
hw/intc/i8259.c +1 -1
@@ -471,7 +471,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)ISADevice *isadev;int i; - irq_set =g_malloc (ISA_NUM_IRQS *sizeof (qemu_irq)); + irq_set =g_new (qemu_irq,ISA_NUM_IRQS ); isadev =i8259_init_chip (TYPE_I8259 , bus, true); dev =DEVICE (isadev);
hw/intc/xics.c +3 -3
@@ -597,8 +597,8 @@ static void ics_realize(DeviceState *dev, Error **errp)error_setg (errp,"Number of interrupts needs to be greater 0" );return ; } - ics->irqs =g_malloc0 (ics->nr_irqs *sizeof (ICSIRQState)); - ics->islsi =g_malloc0 (ics->nr_irqs *sizeof (bool )); + ics->irqs =g_new0 (ICSIRQState, ics->nr_irqs); + ics->islsi =g_new0 (bool, ics->nr_irqs); ics->qirqs =qemu_allocate_irqs (ics_set_irq, ics, ics->nr_irqs); }
@@ -836,7 +836,7 @@ static void xics_set_nr_servers(XICSState *icp, uint32_t nr_servers, icp->nr_servers = nr_servers; - icp->ss =g_malloc0 (icp->nr_servers*sizeof (ICPState)); + icp->ss =g_new0 (ICPState, icp->nr_servers);for (i =0 ; i < icp->nr_servers; i++) {char buffer[32 ];object_initialize (&icp->ss[i],sizeof (icp->ss[i]),TYPE_ICP );
hw/intc/xics_kvm.c +2 -2
@@ -280,7 +280,7 @@ static void ics_kvm_realize(DeviceState *dev, Error **errp)error_setg (errp,"Number of interrupts needs to be greater 0" );return ; } - ics->irqs =g_malloc0 (ics->nr_irqs *sizeof (ICSIRQState)); + ics->irqs =g_new0 (ICSIRQState, ics->nr_irqs); ics->islsi =g_malloc0 (ics->nr_irqs *sizeof (bool )); ics->qirqs =qemu_allocate_irqs (ics_kvm_set_irq, ics, ics->nr_irqs); }
@@ -351,7 +351,7 @@ static void xics_kvm_set_nr_servers(XICSState *icp, uint32_t nr_servers, icp->nr_servers = nr_servers; - icp->ss =g_malloc0 (icp->nr_servers*sizeof (ICPState)); + icp->ss =g_new0 (ICPState, icp->nr_servers);for (i =0 ; i < icp->nr_servers; i++) {char buffer[32 ];object_initialize (&icp->ss[i],sizeof (icp->ss[i]),TYPE_KVM_ICP );
hw/lm32/lm32_boards.c +2 -2
@@ -95,7 +95,7 @@ static void lm32_evr_init(QEMUMachineInitArgs *args)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" ;
@@ -192,7 +192,7 @@ static void lm32_uclinux_init(QEMUMachineInitArgs *args)hwaddr 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" ;
hw/lm32/lm32_hwsetup.h +1 -1
@@ -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;
hw/lm32/milkymist.c +1 -1
@@ -102,7 +102,7 @@ milkymist_init(QEMUMachineInitArgs *args)hwaddr 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" ;
hw/m68k/mcf5206.c +2 -2
@@ -134,7 +134,7 @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)m5206_timer_state *s;QEMUBH *bh; - s = (m5206_timer_state *)g_malloc0 (sizeof (m5206_timer_state)); + s =g_new0 (m5206_timer_state,1 ); bh =qemu_bh_new (m5206_timer_trigger, s); s->timer =ptimer_init (bh); s->irq = irq;
@@ -530,7 +530,7 @@ qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)m5206_mbar_state *s;qemu_irq *pic; - s = (m5206_mbar_state *)g_malloc0 (sizeof (m5206_mbar_state)); + s =g_new0 (m5206_mbar_state,1 );memory_region_init_io (&s->iomem,NULL , &m5206_mbar_ops, s,"mbar" ,0x00001000 );
hw/m68k/mcf5208.c +1 -1
@@ -177,7 +177,7 @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)memory_region_add_subregion (address_space,0xfc0a8000 , iomem);/* Timers. */ for (i =0 ; i <2 ; i++) { - s = (m5208_timer_state *)g_malloc0 (sizeof (m5208_timer_state)); + s =g_new0 (m5208_timer_state,1 ); bh =qemu_bh_new (m5208_timer_trigger, s); s->timer =ptimer_init (bh); memory_region_init_io(&s->iomem, NULL, &m5208_timer_ops, s,
hw/m68k/mcf_intc.c +1 -1
@@ -143,7 +143,7 @@ qemu_irq *mcf_intc_init(MemoryRegion *sysmem, {mcf_intc_state *s; - s =g_malloc0 (sizeof (mcf_intc_state)); + s =g_new0 (mcf_intc_state,1 ); s->cpu = cpu;mcf_intc_reset (s);
hw/mips/mips_malta.c +1 -1
@@ -540,7 +540,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space, {MaltaFPGAState *s; - s = (MaltaFPGAState *)g_malloc0 (sizeof (MaltaFPGAState)); + s =g_new0 (MaltaFPGAState,1 );memory_region_init_io (&s->iomem,NULL , &malta_fpga_ops, s,"malta-fpga" ,0x100000 );
hw/mips/mips_mipssim.c +1 -1
@@ -165,7 +165,7 @@ mips_mipssim_init(QEMUMachineInitArgs *args) } env = &cpu->env; - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->cpu = cpu; reset_info->vector = env->active_tc.PC;qemu_register_reset (main_cpu_reset, reset_info);
hw/mips/mips_r4k.c +1 -1
@@ -192,7 +192,7 @@ void mips_r4k_init(QEMUMachineInitArgs *args) } env = &cpu->env; - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->cpu = cpu; reset_info->vector = env->active_tc.PC;qemu_register_reset (main_cpu_reset, reset_info);
hw/misc/applesmc.c +1 -1
@@ -180,7 +180,7 @@ static void applesmc_add_key(AppleSMCState *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;
hw/misc/ivshmem.c +4 -4
@@ -411,7 +411,7 @@ static void increase_dynamic_storage(IVShmemState *s, int new_min_size) { s->nb_peers = s->nb_peers *2 ;IVSHMEM_DPRINTF ("bumping storage to %d guests\n" , s->nb_peers); - s->peers =g_realloc (s->peers, s->nb_peers *sizeof (Peer)); + s->peers =g_renew (Peer, s->peers, s->nb_peers);/* zero out new pointers */ for (j = old_nb_alloc; j < s->nb_peers; j++) {
@@ -586,7 +586,7 @@ static void ivshmem_setup_msi(IVShmemState * s)IVSHMEM_DPRINTF ("msix initialized (%d vectors)\n" , s->vectors);/* allocate QEMU char devices for receiving interrupts */ - s->eventfd_table =g_malloc0 (s->vectors *sizeof (EventfdEntry)); + s->eventfd_table =g_new0 (EventfdEntry, s->vectors);ivshmem_use_msix (s); }
@@ -732,11 +732,11 @@ 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 (dev,2 , s->ivshmem_attr, &s->bar); - 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);
hw/misc/macio/mac_dbdma.c +1 -1
@@ -751,7 +751,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,NULL , &dbdma_ops, s,"dbdma" ,0x1000 ); *dbdma_mem = &s->mem;
hw/misc/omap_clk.c +1 -1
@@ -1239,7 +1239,7 @@ void omap_clk_init(struct omap_mpu_state_s *mpu)for (i = onchip_clks, count =0 ; *i; i ++)if ((*i)->flags & flag) count ++; - mpu->clks = (struct clk *)g_malloc0 (sizeof (struct clk ) * (count +1 )); + mpu->clks = g_new0(struct clk, count + 1);for (i = onchip_clks, j = mpu->clks; *i; i ++)if ((*i)->flags & flag) {memcpy (j, *i,sizeof (struct clk ));
hw/misc/omap_gpmc.c +1 -2
@@ -823,8 +823,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu, qemu_irq irq, qemu_irq drq) { int cs; -struct omap_gpmc_s *s = (struct omap_gpmc_s *) -g_malloc0 (sizeof (struct omap_gpmc_s )); + struct omap_gpmc_s *s = g_new0(struct omap_gpmc_s, 1);memory_region_init_io (&s->iomem,NULL , &omap_gpmc_ops, s,"omap-gpmc" ,0x1000 );memory_region_add_subregion (get_system_memory (), base, &s->iomem);
hw/misc/omap_sdrc.c +1 -2
@@ -156,8 +156,7 @@ static const MemoryRegionOps omap_sdrc_ops = {struct omap_sdrc_s *omap_sdrc_init (MemoryRegion *sysmem,hwaddr base) { -struct omap_sdrc_s *s = (struct omap_sdrc_s *) -g_malloc0 (sizeof (struct omap_sdrc_s )); + struct omap_sdrc_s *s = g_new0(struct omap_sdrc_s, 1);omap_sdrc_reset (s);
hw/misc/vfio.c +2 -2
@@ -787,7 +787,7 @@ static void vfio_enable_msix(VFIODevice *vdev) {vfio_disable_interrupts (vdev); - vdev->msi_vectors =g_malloc0 (vdev->msix->entries *sizeof (VFIOMSIVector)); + vdev->msi_vectors =g_new0 (VFIOMSIVector, vdev->msix->entries); vdev->interrupt =VFIO_INT_MSIX ;
@@ -824,7 +824,7 @@ static void vfio_enable_msi(VFIODevice *vdev) vdev->nr_vectors =msi_nr_vectors_allocated (&vdev->pdev); retry: - vdev->msi_vectors =g_malloc0 (vdev->nr_vectors *sizeof (VFIOMSIVector)); + vdev->msi_vectors =g_new0 (VFIOMSIVector, vdev->nr_vectors);for (i =0 ; i < vdev->nr_vectors; i++) {VFIOMSIVector *vector = &vdev->msi_vectors[i];
hw/net/dp8393x.c +1 -1
@@ -889,7 +889,7 @@ void dp83932_init(NICInfo *nd, hwaddr base, int it_shift,qemu_check_nic_model (nd,"dp83932" ); - s =g_malloc0 (sizeof (dp8393xState)); + s =g_new0 (dp8393xState,1 ); s->address_space = address_space; s->mem_opaque = mem_opaque;
hw/net/mcf_fec.c +1 -1
@@ -464,7 +464,7 @@ void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd,qemu_check_nic_model (nd,"mcf_fec" ); - s = (mcf_fec_state *)g_malloc0 (sizeof (mcf_fec_state)); + s =g_new0 (mcf_fec_state,1 ); s->sysmem = sysmem; s->irq = irq;
hw/net/virtio-net.c +1 -1
@@ -1501,7 +1501,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); n->max_queues =MAX (n->nic_conf.queues,1 ); - n->vqs =g_malloc0 (sizeof (VirtIONetQueue) * n->max_queues); + n->vqs =g_new0 (VirtIONetQueue, n->max_queues); n->vqs[0 ].rx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_rx); n->curr_queues =1 ; n->vqs[0 ].n = n;
hw/ppc/e500.c +2 -2
@@ -624,7 +624,7 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params) args->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++) {PowerPCCPU *cpu;
@@ -657,7 +657,7 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)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 (ppce500_cpu_reset, cpu); env->load_info = boot_info; }else {
hw/ppc/mac_newworld.c +1 -1
@@ -300,7 +300,7 @@ static void ppc_core99_init(QEMUMachineInitArgs *args)memory_region_init_io (unin2_memory,NULL , &unin_ops, token,"unin" ,0x1000 );memory_region_add_subregion (get_system_memory (),0xf3000000 , unin2_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++) {
hw/ppc/mac_oldworld.c +1 -1
@@ -231,7 +231,7 @@ static void ppc_heathrow_init(QEMUMachineInitArgs *args)memory_region_add_subregion (sysmem,0xfe000000 , isa);/* 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 */
hw/ppc/ppc.c +4 -4
@@ -802,7 +802,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)PowerPCCPU *cpu =ppc_env_get_cpu (env);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 */
@@ -1066,10 +1066,10 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *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;
@@ -1174,7 +1174,7 @@ int ppc_dcr_init (CPUPPCState *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;
hw/ppc/ppc405_boards.c +2 -2
@@ -165,7 +165,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,NULL , &ref405ep_fpga_ops, fpga,"fpga" ,0x00000100 );memory_region_add_subregion (sysmem, base, fpga_memory);
@@ -493,7 +493,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,NULL , &taihu_cpld_ops, cpld,"cpld" ,0x100 );memory_region_add_subregion (sysmem, base, cpld_memory);qemu_register_reset (&taihu_cpld_reset, cpld);
hw/ppc/ppc405_uc.c +14 -14
@@ -173,7 +173,7 @@ static void ppc4xx_plb_init(CPUPPCState *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);
@@ -255,7 +255,7 @@ static void ppc4xx_pob_init(CPUPPCState *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);
@@ -386,7 +386,7 @@ static void ppc4xx_opba_init(hwaddr 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
@@ -584,7 +584,7 @@ static void ppc405_ebc_init(CPUPPCState *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);
@@ -667,7 +667,7 @@ static void ppc405_dma_init(CPUPPCState *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,
@@ -808,7 +808,7 @@ static void ppc405_gpio_init(hwaddr 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
@@ -970,7 +970,7 @@ static void ppc405_ocm_init(CPUPPCState *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 );vmstate_register_ram_global (&ocm->isarc_ram);
@@ -1217,7 +1217,7 @@ static void ppc405_i2c_init(hwaddr 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);
@@ -1493,7 +1493,7 @@ static void ppc4xx_gpt_init(hwaddr 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]; }
@@ -1724,7 +1724,7 @@ static void ppc405_mal_init(CPUPPCState *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);
@@ -2081,7 +2081,7 @@ static void ppc405cr_cpc_init (CPUPPCState *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;
@@ -2131,7 +2131,7 @@ CPUPPCState *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] =
@@ -2425,7 +2425,7 @@ static void ppc405ep_cpc_init (CPUPPCState *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 ;
@@ -2488,7 +2488,7 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,/* Initialize timers */ ppc_booke_timers_init (cpu, sysclk,0 );/* 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] =
hw/ppc/ppc440_bamboo.c +1 -1
@@ -199,7 +199,7 @@ static void bamboo_init(QEMUMachineInitArgs *args)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 );
hw/ppc/ppc4xx_devs.c +2 -2
@@ -304,7 +304,7 @@ qemu_irq *ppcuic_init (CPUPPCState *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)
@@ -652,7 +652,7 @@ void ppc4xx_sdram_init (CPUPPCState *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;
hw/ppc/ppc_booke.c +2 -2
@@ -333,8 +333,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags)booke_timer_t *booke_timer;int ret =0 ; - 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 ); cpu->env.tb_env = tb_env; tb_env->flags = flags |PPC_TIMER_BOOKE |PPC_DECR_ZERO_TRIGGERED ;
hw/ppc/prep.c +1 -1
@@ -479,7 +479,7 @@ static void ppc_prep_init(QEMUMachineInitArgs *args)int ppc_boot_device;DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ]; - sysctrl =g_malloc0 (sizeof (sysctrl_t)); + sysctrl =g_new0 (sysctrl_t,1 ); linux_boot = (kernel_filename !=NULL );
hw/ppc/virtex_ml507.c +1 -1
@@ -98,7 +98,7 @@ static PowerPCCPU *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 );
hw/s390x/css.c +2 -2
@@ -61,7 +61,7 @@ int css_create_css_image(uint8_t cssid, bool default_image)if (channel_subsys->css[cssid]) {return -EBUSY ; } - channel_subsys->css[cssid] =g_malloc0 (sizeof (CssImage)); + channel_subsys->css[cssid] =g_new0 (CssImage,1 );if (default_image) { channel_subsys->default_cssid = cssid; }
@@ -1120,7 +1120,7 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, css = channel_subsys->css[cssid];if (!css->sch_set[ssid]) { - css->sch_set[ssid] =g_malloc0 (sizeof (SubchSet)); + css->sch_set[ssid] =g_new0 (SubchSet,1 ); } s_set = css->sch_set[ssid];
hw/s390x/event-facility.c +1 -1
@@ -318,7 +318,7 @@ static int init_event_facility(S390SCLPDevice *sdev)SCLPEventFacility *event_facility;DeviceState *quiesce; - event_facility =g_malloc0 (sizeof (SCLPEventFacility)); + event_facility =g_new0 (SCLPEventFacility,1 ); sdev->ef = event_facility; sdev->sclp_command_handler = command_handler; sdev->event_pending = event_pending;
hw/s390x/s390-virtio.c +1 -1
@@ -184,7 +184,7 @@ void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys) cpu_model ="host" ; } - ipi_states =g_malloc (sizeof (S390CPU *) * smp_cpus); + ipi_states = g_new(S390CPU *, smp_cpus);for (i =0 ; i < smp_cpus; i++) {S390CPU *cpu;
hw/s390x/virtio-ccw.c +1 -1
@@ -494,7 +494,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)int num;DeviceState *parent =DEVICE (dev); - sch =g_malloc0 (sizeof (SubchDev)); + sch =g_new0 (SubchDev,1 ); sch->driver_data = dev; dev->sch = sch;
hw/scsi/lsi53c895a.c +1 -1
@@ -780,7 +780,7 @@ static void lsi_do_command(LSIState *s) }assert (s->current ==NULL ); - s->current =g_malloc0 (sizeof (lsi_request)); + s->current =g_new0 (lsi_request,1 ); s->current->tag = s->select_tag; s->current->req =scsi_req_new (dev, s->current->tag, s->current_lun, buf, s->current);
hw/scsi/virtio-scsi.c +1 -1
@@ -602,7 +602,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp)virtio_init (vdev,"virtio-scsi" ,VIRTIO_ID_SCSI ,sizeof (VirtIOSCSIConfig)); - s->cmd_vqs =g_malloc0 (s->conf.num_queues *sizeof (VirtQueue *)); + s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues); s->sense_size =VIRTIO_SCSI_SENSE_SIZE ; s->cdb_size =VIRTIO_SCSI_CDB_SIZE ;
hw/sd/omap_mmc.c +2 -4
@@ -577,8 +577,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,BlockDriverState *bd, qemu_irq irq, qemu_irq dma[], omap_clk clk) { - struct omap_mmc_s *s = (struct omap_mmc_s *) -g_malloc0 (sizeof (struct omap_mmc_s )); + struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1); s->irq = irq; s->dma = dma;
@@ -604,8 +603,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, BlockDriverState *bd, qemu_irq irq, qemu_irq dma[], omap_clk fclk, omap_clk iclk) { - struct omap_mmc_s *s = (struct omap_mmc_s *) -g_malloc0 (sizeof (struct omap_mmc_s )); + struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1); s->irq = irq; s->dma = dma;
hw/sd/pxa2xx_mmci.c +1 -1
@@ -528,7 +528,7 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, {PXA2xxMMCIState *s; - s = (PXA2xxMMCIState *)g_malloc0 (sizeof (PXA2xxMMCIState)); + s =g_new0 (PXA2xxMMCIState,1 ); s->irq = irq; s->rx_dma = rx_dma; s->tx_dma = tx_dma;
hw/sd/sd.c +1 -1
@@ -499,7 +499,7 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi)return NULL ; } - sd = (SDState *)g_malloc0 (sizeof (SDState)); + sd =g_new0 (SDState,1 ); sd->buf =qemu_blockalign (bs,512 ); sd->spi = is_spi; sd->enable = true;
hw/sh4/r2d.c +2 -2
@@ -182,7 +182,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem, {r2d_fpga_t *s; - s =g_malloc0 (sizeof (r2d_fpga_t)); + s =g_new0 (r2d_fpga_t,1 ); s->irl = irl;
@@ -249,7 +249,7 @@ static void r2d_init(QEMUMachineInitArgs *args) } env = &cpu->env; - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->cpu = cpu; reset_info->vector = env->pc;qemu_register_reset (main_cpu_reset, reset_info);
hw/sh4/sh7750.c +1 -1
@@ -727,7 +727,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem) {SH7750State *s; - s =g_malloc0 (sizeof (SH7750State)); + s =g_new0 (SH7750State,1 ); s->cpu = cpu; s->periph_freq =60000000 ;/* 60MHz */ memory_region_init_io(&s->iomem, NULL, &sh7750_mem_ops, s,
hw/sparc/leon3.c +1 -1
@@ -131,7 +131,7 @@ static void leon3_generic_hw_init(QEMUMachineInitArgs *args)cpu_sparc_set_id (env,0 );/* Reset data */ - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->cpu = cpu;qemu_register_reset (main_cpu_reset, reset_info);
hw/sparc64/sun4u.c +2 -2
@@ -380,7 +380,7 @@ static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu, 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;
@@ -802,7 +802,7 @@ static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef) env->hstick =cpu_timer_create ("hstick" , cpu, hstick_irq, hstick_frequency,TICK_INT_DIS ); - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->cpu = cpu; reset_info->prom_addr = hwdef->prom_addr;qemu_register_reset (main_cpu_reset, reset_info);
hw/ssi/omap_spi.c +1 -2
@@ -341,8 +341,7 @@ static const MemoryRegionOps omap_mcspi_ops = {struct omap_mcspi_s *omap_mcspi_init (struct omap_target_agent_s *ta,int chnum,qemu_irq irq,qemu_irq *drq,omap_clk fclk,omap_clk iclk) { -struct omap_mcspi_s *s = (struct omap_mcspi_s *) -g_malloc0 (sizeof (struct omap_mcspi_s )); + struct omap_mcspi_s *s = g_new0(struct omap_mcspi_s, 1);struct omap_mcspi_ch_s *ch = s->ch; s->irq = irq;
hw/timer/arm_timer.c +1 -1
@@ -165,7 +165,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)arm_timer_state *s;QEMUBH *bh; - s = (arm_timer_state *)g_malloc0 (sizeof (arm_timer_state)); + s =g_new0 (arm_timer_state,1 ); s->freq = freq; s->control =TIMER_CTRL_IE ;
hw/timer/omap_gptimer.c +1 -2
@@ -468,8 +468,7 @@ static const MemoryRegionOps omap_gp_timer_ops = {struct omap_gp_timer_s *omap_gp_timer_init (struct omap_target_agent_s *ta,qemu_irq irq,omap_clk fclk,omap_clk iclk) { -struct omap_gp_timer_s *s = (struct omap_gp_timer_s *) -g_malloc0 (sizeof (struct omap_gp_timer_s )); + struct omap_gp_timer_s *s = g_new0(struct omap_gp_timer_s, 1); s->ta = ta; s->irq = irq;
hw/timer/sh_timer.c +2 -2
@@ -191,7 +191,7 @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq)sh_timer_state *s;QEMUBH *bh; - s = (sh_timer_state *)g_malloc0 (sizeof (sh_timer_state)); + s =g_new0 (sh_timer_state,1 ); s->freq = freq; s->feat = feat; s->tcor =0xffffffff ;
@@ -312,7 +312,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base,tmu012_state *s;int timer_feat = (feat &TMU012_FEAT_EXTCLK ) ?TIMER_FEAT_EXTCLK :0 ; - s = (tmu012_state *)g_malloc0 (sizeof (tmu012_state)); + s =g_new0 (tmu012_state,1 ); s->feat = feat; s->timer[0 ] =sh_timer_init (freq, timer_feat, ch0_irq); s->timer[1 ] =sh_timer_init (freq, timer_feat, ch1_irq);
hw/timer/slavio_timer.c +1 -1
@@ -390,7 +390,7 @@ static int slavio_timer_init1(SysBusDevice *dev)uint64_t size;char timer_name[20 ]; - tc =g_malloc0 (sizeof (TimerContext)); + tc =g_new0 (TimerContext,1 ); tc->s = s; tc->timer_index = i;
hw/usb/ccid-card-emulated.c +2 -2
@@ -169,7 +169,7 @@ static void emulated_push_event(EmulatedState *card, EmulEvent *event)static void emulated_push_type (EmulatedState *card,uint32_t type) { -EmulEvent *event = (EmulEvent *)g_malloc (sizeof (EmulEvent)); +EmulEvent *event =g_new (EmulEvent,1 );assert (event); event->p.gen.type = type;
@@ -178,7 +178,7 @@ static void emulated_push_type(EmulatedState *card, uint32_t type)static void emulated_push_error (EmulatedState *card,uint64_t code) { -EmulEvent *event = (EmulEvent *)g_malloc (sizeof (EmulEvent)); +EmulEvent *event =g_new (EmulEvent,1 );assert (event); event->p.error.type =EMUL_ERROR ;
hw/usb/hcd-xhci.c +1 -1
@@ -2173,7 +2173,7 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, xfer->trbs =NULL ; }if (!xfer->trbs) { - xfer->trbs =g_malloc (sizeof (XHCITRB ) * length); + xfer->trbs =g_new (XHCITRB , length); xfer->trb_alloced = length; } xfer->trb_count = length;
hw/usb/redirect.c +3 -3
@@ -314,7 +314,7 @@ static void packet_id_queue_add(struct PacketIdQueue *q, uint64_t id)DPRINTF ("adding packet id %" PRIu64" to %s queue\n" , id, q->name); - e =g_malloc0 (sizeof (struct PacketIdQueueEntry )); + e = g_new0(struct PacketIdQueueEntry, 1); e->id = id;QTAILQ_INSERT_TAIL (&q->head, e, next); q->size++;
@@ -460,7 +460,7 @@ static void bufp_alloc(USBRedirDevice *dev, uint8_t *data, uint16_t len, dev->endpoint[EP2I (ep)].bufpq_dropping_packets =0 ; } - bufp =g_malloc (sizeof (struct buf_packet )); + bufp = g_new(struct buf_packet, 1); bufp->data = data; bufp->len = len; bufp->offset =0 ;
@@ -2126,7 +2126,7 @@ static int usbredir_get_bufpq(QEMUFile *f, void *priv, size_t unused) endp->bufpq_size =qemu_get_be32 (f);for (i =0 ; i < endp->bufpq_size; i++) { - bufp =g_malloc (sizeof (struct buf_packet )); + bufp = g_new(struct buf_packet, 1); bufp->len =qemu_get_be32 (f); bufp->status =qemu_get_be32 (f); bufp->offset =0 ;
hw/virtio/virtio.c +1 -1
@@ -993,7 +993,7 @@ void virtio_init(VirtIODevice *vdev, const char *name, vdev->isr =0 ; vdev->queue_sel =0 ; vdev->config_vector =VIRTIO_NO_VECTOR ; - vdev->vq =g_malloc0 (sizeof (VirtQueue) *VIRTIO_PCI_QUEUE_MAX ); + vdev->vq =g_new0 (VirtQueue,VIRTIO_PCI_QUEUE_MAX ); vdev->vm_running =runstate_is_running ();for (i =0 ; i <VIRTIO_PCI_QUEUE_MAX ; i++) { vdev->vq[i].vector =VIRTIO_NO_VECTOR ;
hw/xtensa/xtensa_lx60.c +1 -1
@@ -107,7 +107,7 @@ static const MemoryRegionOps lx60_fpga_ops = {static Lx60FpgaState *lx60_fpga_init (MemoryRegion *address_space,hwaddr base) { -Lx60FpgaState *s =g_malloc (sizeof (Lx60FpgaState)); +Lx60FpgaState *s =g_new (Lx60FpgaState,1 );memory_region_init_io (&s->iomem,NULL , &lx60_fpga_ops, s,"lx60.fpga" ,0x10000 );
include/qemu/timer.h +1 -1
@@ -439,7 +439,7 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, QEMUTimerCB *cb, void *opaque) { -QEMUTimer *ts =g_malloc0 (sizeof (QEMUTimer)); +QEMUTimer *ts =g_new0 (QEMUTimer,1 );timer_init (ts, timer_list, scale, cb, opaque);return ts; }
iohandler.c +2 -2
@@ -71,7 +71,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;
@@ -209,7 +209,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 ;
kvm-all.c +4 -4
@@ -1151,7 +1151,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)return virq; } - route =g_malloc0 (sizeof (KVMMSIRoute)); + route =g_new0 (KVMMSIRoute,1 ); route->kroute.gsi = virq; route->kroute.type =KVM_IRQ_ROUTING_MSI ; route->kroute.flags =0 ;
@@ -1351,7 +1351,7 @@ int kvm_init(void)int ret;int i; - s =g_malloc0 (sizeof (KVMState)); + s =g_new0 (KVMState,1 );/* * On systems where the kernel can support different base page
@@ -1394,7 +1394,7 @@ int kvm_init(void) s->nr_slots =32 ; } - s->slots =g_malloc0 (s->nr_slots *sizeof (KVMSlot)); + s->slots =g_new0 (KVMSlot, s->nr_slots);for (i =0 ; i < s->nr_slots; i++) { s->slots[i].slot = i;
@@ -1913,7 +1913,7 @@ int kvm_insert_breakpoint(CPUState *cpu, 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 ; }
libcacard/cac.c +1 -1
@@ -312,7 +312,7 @@ cac_new_pki_applet_private(const unsigned char *cert, {CACPKIAppletData *pki_applet_data =NULL ;VCardAppletPrivate *applet_private =NULL ; - applet_private = (VCardAppletPrivate *)g_malloc (sizeof (VCardAppletPrivate)); + applet_private =g_new (VCardAppletPrivate,1 ); pki_applet_data = &(applet_private->u.pki_data); pki_applet_data->cert_buffer =NULL ;
libcacard/card_7816.c +4 -4
@@ -51,7 +51,7 @@ vcard_response_new_data(unsigned char *buf, int len) {VCardResponse *new_response; - new_response = (VCardResponse *)g_malloc (sizeof (VCardResponse)); + new_response =g_new (VCardResponse,1 ); new_response->b_data =g_malloc (len +2 );memcpy (new_response->b_data, buf, len); new_response->b_total_len = len+2 ;
@@ -132,7 +132,7 @@ vcard_response_new_status(vcard_7816_status_t status) {VCardResponse *new_response; - new_response = (VCardResponse *)g_malloc (sizeof (VCardResponse)); + new_response =g_new (VCardResponse,1 ); new_response->b_data = &new_response->b_sw1; new_response->b_len =0 ; new_response->b_total_len =2 ;
@@ -149,7 +149,7 @@ vcard_response_new_status_bytes(unsigned char sw1, unsigned char sw2) {VCardResponse *new_response; - new_response = (VCardResponse *)g_malloc (sizeof (VCardResponse)); + new_response =g_new (VCardResponse,1 ); new_response->b_data = &new_response->b_sw1; new_response->b_len =0 ; new_response->b_total_len =2 ;
@@ -336,7 +336,7 @@ vcard_apdu_new(unsigned char *raw_apdu, int len, vcard_7816_status_t *status)return NULL ; } - new_apdu = (VCardAPDU *)g_malloc (sizeof (VCardAPDU)); + new_apdu =g_new (VCardAPDU,1 ); new_apdu->a_data =g_malloc (len);memcpy (new_apdu->a_data, raw_apdu, len); new_apdu->a_len = len;
libcacard/event.c +1 -1
@@ -17,7 +17,7 @@ vevent_new(VEventType type, VReader *reader, VCard *card) {VEvent *new_vevent; - new_vevent = (VEvent *)g_malloc (sizeof (VEvent)); + new_vevent =g_new (VEvent,1 ); new_vevent->next =NULL ; new_vevent->type = type; new_vevent->reader =vreader_reference (reader);
libcacard/vcard.c +3 -3
@@ -37,7 +37,7 @@ vcard_buffer_response_new(unsigned char *buffer, int size) {VCardBufferResponse *new_buffer; - new_buffer = (VCardBufferResponse *)g_malloc (sizeof (VCardBufferResponse)); + new_buffer =g_new (VCardBufferResponse,1 ); new_buffer->buffer = (unsigned char *)g_malloc (size);memcpy (new_buffer->buffer, buffer, size); new_buffer->buffer_len = size;
@@ -102,7 +102,7 @@ vcard_new_applet(VCardProcessAPDU applet_process_function, {VCardApplet *applet; - applet = (VCardApplet *)g_malloc (sizeof (VCardApplet)); + applet =g_new (VCardApplet,1 ); applet->next =NULL ; applet->applet_private =NULL ; applet->applet_private_free =NULL ;
@@ -151,7 +151,7 @@ vcard_new(VCardEmul *private, VCardEmulFree private_free)VCard *new_card;int i; - new_card = (VCard *)g_malloc (sizeof (VCard)); + new_card =g_new (VCard,1 ); new_card->applet_list =NULL ;for (i =0 ; i <MAX_CHANNEL ; i++) { new_card->current_applet[i] =NULL ;
libcacard/vcard_emul_nss.c +6 -6
@@ -94,9 +94,9 @@ static void vcard_emul_alloc_arrays(unsigned char ***certsp, int **cert_lenp, VCardKey ***keysp, int cert_count) { - *certsp = (unsigned char **)g_malloc (sizeof (unsigned char *)*cert_count); - *cert_lenp = (int *)g_malloc (sizeof (int )*cert_count); - *keysp = (VCardKey **)g_malloc (sizeof (VCardKey *)*cert_count); + *certsp = g_new(unsigned char *, cert_count); + *cert_lenp =g_new (int, cert_count); + *keysp = g_new(VCardKey *, cert_count); }/*
@@ -139,7 +139,7 @@ vcard_emul_make_key(PK11SlotInfo *slot, CERTCertificate *cert) {VCardKey *key; - key = (VCardKey *)g_malloc (sizeof (VCardKey)); + key =g_new (VCardKey,1 ); key->slot =PK11_ReferenceSlot (slot); key->cert =CERT_DupCertificate (cert);/* NOTE: if we aren't logged into the token, this could return NULL */
@@ -449,7 +449,7 @@ vreader_emul_new(PK11SlotInfo *slot, VCardEmulType type, const char *params) {VReaderEmul *new_reader_emul; - new_reader_emul = (VReaderEmul *)g_malloc (sizeof (VReaderEmul)); + new_reader_emul =g_new (VReaderEmul,1 ); new_reader_emul->slot =PK11_ReferenceSlot (slot); new_reader_emul->default_type = type;
@@ -1188,7 +1188,7 @@ vcard_emul_options(const char *args)g_strndup (type_params, type_params_length); count =count_tokens (args,',' ,')' ) +1 ; vreaderOpt->cert_count = count; - vreaderOpt->cert_name = (char **)g_malloc (count*sizeof (char *)); + vreaderOpt->cert_name = g_new(char *, count);for (i =0 ; i < count; i++) {const char *cert = args; args =strpbrk (args,",)" );
libcacard/vreader.c +3 -4
@@ -115,7 +115,7 @@ vreader_new(const char *name, VReaderEmul *private, {VReader *reader; - reader = (VReader *)g_malloc (sizeof (VReader)); + reader =g_new (VReader,1 );qemu_mutex_init (&reader->lock); reader->reference_count =1 ; reader->name =g_strdup (name);
@@ -312,8 +312,7 @@ vreader_list_entry_new(VReader *reader) {VReaderListEntry *new_reader_list_entry; - new_reader_list_entry = (VReaderListEntry *) -g_malloc (sizeof (VReaderListEntry)); + new_reader_list_entry =g_new (VReaderListEntry,1 ); new_reader_list_entry->next =NULL ; new_reader_list_entry->prev =NULL ; new_reader_list_entry->reader =vreader_reference (reader);
@@ -336,7 +335,7 @@ vreader_list_new(void) {VReaderList *new_reader_list; - new_reader_list = (VReaderList *)g_malloc (sizeof (VReaderList)); + new_reader_list =g_new (VReaderList,1 ); new_reader_list->head =NULL ; new_reader_list->tail =NULL ;return new_reader_list;
linux-user/elfload.c +1 -1
@@ -2648,7 +2648,7 @@ static int fill_note_info(struct elf_note_info *info,QTAILQ_INIT (&info->thread_list); - info->notes =g_malloc0 (NUMNOTES *sizeof (struct memelfnote )); + info->notes = g_new0(struct memelfnote, NUMNOTES);if (info->notes ==NULL )return (-ENOMEM ); info->prstatus =g_malloc0 (sizeof (*info->prstatus));
linux-user/main.c +1 -1
@@ -3974,7 +3974,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;
linux-user/syscall.c +1 -1
@@ -4410,7 +4410,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,new_thread_info info;pthread_attr_t attr; - 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);
main-loop.c +1 -1
@@ -249,7 +249,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);
memory_mapping.c +1 -1
@@ -42,7 +42,7 @@ static void create_new_memory_mapping(MemoryMappingList *list, {MemoryMapping *memory_mapping; - memory_mapping =g_malloc (sizeof (MemoryMapping)); + memory_mapping =g_new (MemoryMapping,1 ); memory_mapping->phys_addr = phys_addr; memory_mapping->virt_addr = virt_addr; memory_mapping->length = length;
migration-rdma.c +7 -9
@@ -547,7 +547,7 @@ static int __qemu_rdma_add_block(RDMAContext *rdma, void *host_addr,assert (block ==NULL ); - local->block =g_malloc0 (sizeof (RDMALocalBlock) * (local->nb_blocks +1 )); + local->block =g_new0 (RDMALocalBlock, local->nb_blocks +1 );if (local->nb_blocks) {int x;
@@ -572,7 +572,7 @@ static int __qemu_rdma_add_block(RDMAContext *rdma, void *host_addr,bitmap_clear (block->transit_bitmap,0 , block->nb_chunks); block->unregister_bitmap =bitmap_new (block->nb_chunks);bitmap_clear (block->unregister_bitmap,0 , block->nb_chunks); - block->remote_keys =g_malloc0 (block->nb_chunks *sizeof (uint32_t )); + block->remote_keys =g_new0 (uint32_t, block->nb_chunks); block->is_ram_block = local->init ? false : true;
@@ -615,8 +615,7 @@ static int qemu_rdma_init_ram_blocks(RDMAContext *rdma)memset (local,0 ,sizeof *local);qemu_ram_foreach_block (qemu_rdma_init_one_block, rdma);DPRINTF ("Allocated %d local ram block structures\n" , local->nb_blocks); - rdma->block = (RDMARemoteBlock *)g_malloc0 (sizeof (RDMARemoteBlock) * - rdma->local_ram_blocks.nb_blocks); + rdma->block =g_new0 (RDMARemoteBlock, rdma->local_ram_blocks.nb_blocks); local->init = true;return 0 ; }
@@ -666,8 +665,7 @@ static int __qemu_rdma_delete_block(RDMAContext *rdma, ram_addr_t block_offset)if (local->nb_blocks >1 ) { - local->block =g_malloc0 (sizeof (RDMALocalBlock) * - (local->nb_blocks -1 )); + local->block =g_new0 (RDMALocalBlock, local->nb_blocks -1 );if (block->index) {memcpy (local->block, old,sizeof (RDMALocalBlock) * block->index);
@@ -1145,7 +1143,7 @@ static int qemu_rdma_register_and_get_keys(RDMAContext *rdma,/* allocate memory to store chunk MRs */ if (!block->pmr) { - block->pmr =g_malloc0 (block->nb_chunks *sizeof (struct ibv_mr *)); + block->pmr = g_new0(struct ibv_mr *, block->nb_chunks);if (!block->pmr) {return -1 ; }
@@ -2500,7 +2498,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)InetSocketAddress *addr;if (host_port) { - rdma =g_malloc0 (sizeof (RDMAContext)); + rdma =g_new0 (RDMAContext,1 );memset (rdma,0 ,sizeof (RDMAContext)); rdma->current_index =-1 ; rdma->current_chunk =-1 ;
@@ -3314,7 +3312,7 @@ const QEMUFileOps rdma_write_ops = {static void *qemu_fopen_rdma (RDMAContext *rdma,const char *mode) { -QEMUFileRDMA *r =g_malloc0 (sizeof (QEMUFileRDMA)); +QEMUFileRDMA *r =g_new0 (QEMUFileRDMA,1 );if (qemu_file_mode_is_not_valid (mode)) {return NULL ;
monitor.c +2 -2
@@ -2246,7 +2246,7 @@ void qmp_getfd(const char *fdname, Error **errp)return ; } - monfd =g_malloc0 (sizeof (mon_fd_t)); + monfd =g_new0 (mon_fd_t,1 ); monfd->name =g_strdup (fdname); monfd->fd = fd;
@@ -4926,7 +4926,7 @@ void monitor_init(CharDriverState *chr, int flags) }if (monitor_ctrl_mode (mon)) { - mon->mc =g_malloc0 (sizeof (MonitorControl)); + mon->mc =g_new0 (MonitorControl,1 );/* Control mode requires special handlers */ qemu_chr_add_handlers (chr, monitor_can_read, monitor_control_read, monitor_control_event, mon);
nbd.c +2 -2
@@ -872,7 +872,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size, uint32_t nbdflags, void (*close)(NBDExport *)) { - NBDExport *exp = g_malloc0(sizeof(NBDExport)); + NBDExport *exp = g_new0(NBDExport, 1); exp->refcount =1 ;QTAILQ_INIT (&exp->clients); exp->bs = bs;
@@ -1235,7 +1235,7 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock, void (*close)(NBDClient *)) {NBDClient *client; - client =g_malloc0 (sizeof (NBDClient)); + client =g_new0 (NBDClient,1 ); client->refcount =1 ; client->exp = exp; client->sock = csock;
net/queue.c +1 -1
@@ -62,7 +62,7 @@ NetQueue *qemu_new_net_queue(void *opaque) {NetQueue *queue; - queue =g_malloc0 (sizeof (NetQueue)); + queue =g_new0 (NetQueue,1 ); queue->opaque = opaque; queue->nq_maxlen =10000 ;
net/slirp.c +1 -1
@@ -632,7 +632,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);if ((strlen (p) >4 ) && !strncmp (p,"cmd:" ,4 )) {
qemu-char.c +23 -23
133 lines not on this page · raw message
qemu-file.c +5 -5
@@ -195,7 +195,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileStdio)); + s =g_new0 (QEMUFileStdio,1 ); s->stdio_file = stdio_file;
@@ -315,7 +315,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileSocket)); + s =g_new0 (QEMUFileSocket,1 ); s->fd = fd;if (mode[0 ] =='r' ) {
@@ -358,7 +358,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileSocket)); + s =g_new0 (QEMUFileSocket,1 ); s->fd = fd;if (mode[0 ] =='w' ) {qemu_set_block (s->fd);
@@ -377,7 +377,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) {
@@ -399,7 +399,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) {QEMUFile *f; - f =g_malloc0 (sizeof (QEMUFile)); + f =g_new0 (QEMUFile,1 ); f->opaque = opaque; f->ops = ops;
qemu-img.c +1 -1
@@ -1260,7 +1260,7 @@ static int img_convert(int argc, char **argv)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++) {
qemu-io-cmds.c +1 -1
@@ -114,7 +114,7 @@ static char **breakline(char *input, int *count) {int c =0 ;char *p; -char **rval =g_malloc0 (sizeof (char *)); + char **rval = g_new0(char *, 1);char **tmp;while (rval && (p =qemu_strsep (&input," " )) !=NULL ) {
qemu-io.c +1 -1
@@ -341,7 +341,7 @@ static void command_loop(void)static void add_user_command (char *optarg) { - cmdline =g_realloc (cmdline, ++ncmdline *sizeof (char *)); + cmdline = g_renew(char *, cmdline, ++ncmdline); cmdline[ncmdline-1 ] = optarg; }
qemu-timer.c +1 -1
@@ -102,7 +102,7 @@ QEMUTimerList *timerlist_new(QEMUClockType type,QEMUTimerList *timer_list;QEMUClock *clock =qemu_clock_ptr (type); - timer_list =g_malloc0 (sizeof (QEMUTimerList)); + timer_list =g_new0 (QEMUTimerList,1 );qemu_event_init (&timer_list->timers_done_ev, false); timer_list->clock = clock; timer_list->notify_cb = cb;
qga/channel-posix.c +1 -1
@@ -249,7 +249,7 @@ GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *count)GAChannel *ga_channel_new (GAChannelMethod method,const gchar *path,GAChannelCallback cb,gpointer opaque) { -GAChannel *c =g_malloc0 (sizeof (GAChannel)); +GAChannel *c =g_new0 (GAChannel,1 ); c->event_cb = cb; c->user_data = opaque;
qga/channel-win32.c +1 -1
@@ -306,7 +306,7 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,GAChannel *ga_channel_new (GAChannelMethod method,const gchar *path,GAChannelCallback cb,gpointer opaque) { -GAChannel *c =g_malloc0 (sizeof (GAChannel)); +GAChannel *c =g_new0 (GAChannel,1 );SECURITY_ATTRIBUTES sec_attrs;if (!ga_channel_open (c, method, path)) {
qga/commands-posix.c +4 -4
@@ -217,7 +217,7 @@ static int64_t guest_file_handle_add(FILE *fh, Error **errp)return 0 ; } - gfh =g_malloc0 (sizeof (GuestFileHandle)); + gfh =g_new0 (GuestFileHandle,1 ); gfh->id = handle; gfh->fh = fh;QTAILQ_INSERT_TAIL (&guest_file_state.filehandles, gfh, next);
@@ -454,7 +454,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,slog ("guest-file-read failed, handle: %" PRId64, handle); }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) {
@@ -498,7 +498,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,error_setg_errno (err, errno,"failed to write to file" );slog ("guest-file-write failed, handle: %" PRId64, handle); }else { - write_data =g_malloc0 (sizeof (GuestFileWrite)); + write_data =g_new0 (GuestFileWrite,1 ); write_data->count = write_count; write_data->eof =feof (fh); }
@@ -613,7 +613,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **err)continue ; } - mount =g_malloc0 (sizeof (FsMount)); + mount =g_new0 (FsMount,1 ); mount->dirname =g_strdup (ment->mnt_dir); mount->devtype =g_strdup (ment->mnt_type);
qga/commands-win32.c +2 -2
@@ -310,7 +310,7 @@ static DWORD WINAPI do_suspend(LPVOID opaque)void qmp_guest_suspend_disk (Error **err) { -GuestSuspendMode *mode =g_malloc (sizeof (GuestSuspendMode)); +GuestSuspendMode *mode =g_new (GuestSuspendMode,1 ); *mode =GUEST_SUSPEND_MODE_DISK ;check_suspend_mode (*mode, err);
@@ -324,7 +324,7 @@ void qmp_guest_suspend_disk(Error **err)void qmp_guest_suspend_ram (Error **err) { -GuestSuspendMode *mode =g_malloc (sizeof (GuestSuspendMode)); +GuestSuspendMode *mode =g_new (GuestSuspendMode,1 ); *mode =GUEST_SUSPEND_MODE_RAM ;check_suspend_mode (*mode, err);
qga/commands.c +3 -3
@@ -51,12 +51,12 @@ static void qmp_command_info(QmpCommand *cmd, void *opaque)GuestAgentCommandInfo *cmd_info;GuestAgentCommandInfoList *cmd_info_list; - cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); + cmd_info =g_new0 (GuestAgentCommandInfo,1 ); cmd_info->name =g_strdup (qmp_command_name (cmd)); cmd_info->enabled =qmp_command_is_enabled (cmd); cmd_info->success_response =qmp_has_success_response (cmd); - cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); + cmd_info_list =g_new0 (GuestAgentCommandInfoList,1 ); cmd_info_list->value = cmd_info; cmd_info_list->next = info->supported_commands; info->supported_commands = cmd_info_list;
@@ -64,7 +64,7 @@ static void qmp_command_info(QmpCommand *cmd, void *opaque)struct GuestAgentInfo *qmp_guest_info (Error **err) { -GuestAgentInfo *info =g_malloc0 (sizeof (GuestAgentInfo)); +GuestAgentInfo *info =g_new0 (GuestAgentInfo,1 ); info->version =g_strdup (QEMU_VERSION );qmp_for_each_command (qmp_command_info, info);
qga/guest-agent-command-state.c +2 -2
@@ -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; }
qga/main.c +1 -1
@@ -1057,7 +1057,7 @@ int main(int argc, char **argv) }#endif - s =g_malloc0 (sizeof (GAState)); + s =g_new0 (GAState,1 ); s->log_level = log_level; s->log_file = stderr;#ifdef CONFIG_FSFREEZE
qobject/json-parser.c +2 -2
@@ -336,10 +336,10 @@ static JSONParserContext *parser_context_new(QList *tokens)return NULL ; } - ctxt =g_malloc0 (sizeof (JSONParserContext)); + ctxt =g_new0 (JSONParserContext,1 ); ctxt->tokens.pos =0 ; ctxt->tokens.count = count; - ctxt->tokens.buf =g_malloc (count *sizeof (QObject *)); + ctxt->tokens.buf = g_new(QObject *, count);qlist_iter (tokens, tokens_append_from_iter, ctxt); ctxt->tokens.pos =0 ;
savevm.c +6 -6
@@ -285,7 +285,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->ops = ops;
@@ -304,7 +304,7 @@ int register_savevm_live(DeviceState *dev,pstrcat (se->idstr,sizeof (se->idstr),"/" );g_free (id); - se->compat =g_malloc0 (sizeof (CompatEntry)); + se->compat =g_new0 (CompatEntry,1 );pstrcpy (se->compat->idstr,sizeof (se->compat->idstr), idstr); se->compat->instance_id = instance_id ==-1 ?calculate_compat_instance_id (idstr) : instance_id;
@@ -332,7 +332,7 @@ int register_savevm(DeviceState *dev, LoadStateHandler *load_state, void *opaque) { -SaveVMHandlers *ops =g_malloc0 (sizeof (SaveVMHandlers)); +SaveVMHandlers *ops =g_new0 (SaveVMHandlers,1 ); ops->save_state = save_state; ops->load_state = load_state; return register_savevm_live(dev, idstr, instance_id, version_id,
@@ -376,7 +376,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->opaque = opaque;
@@ -391,7 +391,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,pstrcat (se->idstr,sizeof (se->idstr),"/" );g_free (id); - se->compat =g_malloc0 (sizeof (CompatEntry)); + se->compat =g_new0 (CompatEntry,1 );pstrcpy (se->compat->idstr,sizeof (se->compat->idstr), vmsd->name); se->compat->instance_id = instance_id ==-1 ?calculate_compat_instance_id (vmsd->name) : instance_id;
@@ -1152,7 +1152,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)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];
slirp/slirp.c +1 -1
@@ -206,7 +206,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, struct in_addr vnameserver, const char **vdnssearch, void *opaque) { - Slirp *slirp = g_malloc0(sizeof(Slirp)); + Slirp *slirp = g_new0(Slirp, 1);slirp_init_once ();
spice-qemu-char.c +2 -2
@@ -253,8 +253,8 @@ static CharDriverState *chr_open(const char *subtype)CharDriverState *chr;SpiceCharDriver *s; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (SpiceCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (SpiceCharDriver,1 ); s->chr = chr; s->active = false; s->sin.subtype =g_strdup (subtype);
target-i386/kvm.c +1 -1
@@ -270,7 +270,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); }
tcg/tcg.c +2 -2
@@ -305,8 +305,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];
tests/test-qmp-commands.c +8 -8
@@ -19,15 +19,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;
@@ -105,23 +105,23 @@ 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 =g_new0 (UserDefOneList,1 ); ud1list->next->value = ud1b;qapi_free_UserDefOneList (ud1list);
tests/test-qmp-output-visitor.c +1 -1
@@ -389,7 +389,7 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, p->value->string0 =g_strdup (string); p->value->dict1.string1 =g_strdup (string); - p->value->dict1.dict2.userdef1 =g_malloc0 (sizeof (UserDefOne)); + p->value->dict1.dict2.userdef1 =g_new0 (UserDefOne,1 ); p->value->dict1.dict2.userdef1->string =g_strdup (string); p->value->dict1.dict2.userdef1->integer =42 ; p->value->dict1.dict2.string2 =g_strdup (string);
tests/test-visitor-serialization.c +1 -1
@@ -725,7 +725,7 @@ static void test_nested_struct_list(gconstpointer opaque)int i =0 ;for (i =0 ; i <8 ; i++) { - tmp =g_malloc0 (sizeof (UserDefNestedList)); + tmp =g_new0 (UserDefNestedList,1 ); tmp->value =nested_struct_create (); tmp->next = listp; listp = tmp;
translate-all.c +1 -1
@@ -585,7 +585,7 @@ static inline void code_gen_alloc(size_t tb_size) tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size /CODE_GEN_AVG_BLOCK_SIZE ; tcg_ctx.tb_ctx.tbs = -g_malloc (tcg_ctx.code_gen_max_blocks *sizeof (TranslationBlock)); +g_new (TranslationBlock, tcg_ctx.code_gen_max_blocks); }/* Must be called before using the QEMU cpus. 'tb_size' is the size
ui/console.c +2 -2
@@ -444,7 +444,7 @@ static void text_console_resize(QemuConsole *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 ) {
@@ -1731,7 +1731,7 @@ static CharDriverState *text_console_init(ChardevVC *vc)unsigned width =0 ;unsigned height =0 ; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 );if (vc->has_width) { width = vc->width;
ui/curses.c +1 -1
@@ -369,7 +369,7 @@ void curses_display_init(DisplayState *ds, int full_screen)curses_winch_init (); - dcl = (DisplayChangeListener *)g_malloc0 (sizeof (DisplayChangeListener)); + dcl =g_new0 (DisplayChangeListener,1 ); dcl->ops = &dcl_ops;register_displaychangelistener (dcl);
ui/input.c +4 -4
@@ -303,7 +303,7 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, }kbd_put_keycode (keycode &SCANCODE_KEYCODEMASK ); - keycodes =g_realloc (keycodes,sizeof (int ) * (keycodes_size +1 )); + keycodes =g_renew (int, keycodes, keycodes_size +1 ); keycodes[keycodes_size++] = keycode; }
@@ -316,7 +316,7 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) {QEMUPutKbdEntry *entry; - entry =g_malloc0 (sizeof (QEMUPutKbdEntry)); + entry =g_new0 (QEMUPutKbdEntry,1 ); entry->put_kbd = func; entry->opaque = opaque;QTAILQ_INSERT_HEAD (&kbd_handlers, entry, next);
@@ -353,7 +353,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;
@@ -391,7 +391,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;
ui/keymaps.c +1 -1
@@ -107,7 +107,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, }if (!k) - k =g_malloc0 (sizeof (kbd_layout_t)); + k =g_new0 (kbd_layout_t,1 );for (;;) {if (fgets (line,1024 , f) ==NULL )
ui/sdl.c +1 -1
@@ -950,7 +950,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->ops = &dcl_ops;register_displaychangelistener (dcl);
ui/vnc-jobs.c +3 -3
@@ -78,7 +78,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);
@@ -89,7 +89,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;
@@ -292,7 +292,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);
ui/vnc.c +2 -2
@@ -2774,7 +2774,7 @@ static void vnc_refresh(DisplayChangeListener *dcl)static void vnc_connect (VncDisplay *vd,int csock,bool skipauth,bool websocket) { -VncState *vs =g_malloc0 (sizeof (VncState)); +VncState *vs =g_new0 (VncState,1 );int i; vs->csock = csock;
@@ -2793,7 +2793,7 @@ static void vnc_connect(VncDisplay *vd, int csock, vs->lossy_rect =g_malloc0 (VNC_STAT_ROWS *sizeof (*vs->lossy_rect));for (i =0 ; i <VNC_STAT_ROWS ; ++i) { - vs->lossy_rect[i] =g_malloc0 (VNC_STAT_COLS *sizeof (uint8_t )); + vs->lossy_rect[i] =g_new0 (uint8_t,VNC_STAT_COLS ); }VNC_DEBUG ("New client on socket %d\n" , csock);
util/hbitmap.c +2 -2
@@ -378,7 +378,7 @@ void hbitmap_free(HBitmap *hb)HBitmap *hbitmap_alloc (uint64_t size,int granularity) { -HBitmap *hb =g_malloc0 (sizeof (struct HBitmap )); + HBitmap *hb = g_new0(struct HBitmap, 1);unsigned i;assert (granularity >=0 && granularity <64 );
@@ -389,7 +389,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) hb->granularity = granularity;for (i =HBITMAP_LEVELS ; i-- >0 ; ) { size =MAX ((size +BITS_PER_LONG -1 ) >>BITS_PER_LEVEL ,1 ); - hb->levels[i] =g_malloc0 (size *sizeof (unsigned long )); + hb->levels[i] = g_new0(unsigned long, size); }/* We necessarily have free bits in level 0 due to the definition
util/iov.c +2 -2
@@ -260,7 +260,7 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,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 ;
@@ -284,7 +284,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)if (qiov->niov == qiov->nalloc) { qiov->nalloc =2 * qiov->nalloc +1 ; - qiov->iov =g_realloc (qiov->iov, qiov->nalloc *sizeof (struct iovec )); + qiov->iov = g_renew(struct iovec, qiov->iov, qiov->nalloc); } qiov->iov[qiov->niov].iov_base = base; qiov->iov[qiov->niov].iov_len = len;
util/qemu-option.c +1 -1
@@ -362,7 +362,7 @@ QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, num_options +=count_option_parameters (list); - dest =g_realloc (dest, (num_options +1 ) *sizeof (QEMUOptionParameter)); + dest =g_renew (QEMUOptionParameter, dest, num_options +1 ); dest[num_dest_options].name =NULL ;while (list && list->name) {
util/uri.c +1 -1
@@ -1006,7 +1006,7 @@ URI *uri_new (void) {URI *ret; - ret = (URI *)g_malloc (sizeof (URI )); + ret =g_new (URI ,1 );memset (ret,0 ,sizeof (URI ));return (ret); }
vl.c +3 -3
@@ -1171,7 +1171,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 =g_strdup (suffix); node->dev = dev;
@@ -1547,7 +1547,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;
@@ -1810,7 +1810,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;
xen-all.c +4 -4
@@ -312,7 +312,7 @@ go_physmap: } } - physmap =g_malloc (sizeof (XenPhysmap)); + physmap =g_new (XenPhysmap,1 ); physmap->start_addr = start_addr; physmap->size = size;
@@ -1027,7 +1027,7 @@ static void xen_read_physmap(XenIOState *state)return ;for (i =0 ; i < num; i++) { - physmap =g_malloc (sizeof (XenPhysmap)); + physmap =g_new (XenPhysmap,1 ); physmap->phys_offset =strtoull (entries[i],NULL ,16 ); snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap/%s/start_addr",
@@ -1073,7 +1073,7 @@ int xen_hvm_init(MemoryRegion **ram_memory)unsigned long bufioreq_evtchn;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 ) {
@@ -1115,7 +1115,7 @@ int xen_hvm_init(MemoryRegion **ram_memory)hw_error ("map buffered IO page returned error %d" , errno); } - state->ioreq_local_port =g_malloc0 (max_cpus *sizeof (evtchn_port_t)); + state->ioreq_local_port =g_new0 (evtchn_port_t, max_cpus);/* FIXME: how about if we overflow the page here? */ for (i =0 ; i < max_cpus; i++) {
xen-mapcache.c +7 -7
@@ -98,7 +98,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)unsigned long size;struct rlimit rlimit_as; - mapcache =g_malloc0 (sizeof (MapCache)); + mapcache =g_new0 (MapCache,1 ); mapcache->phys_offset_to_gaddr = f; mapcache->opaque = opaque;
@@ -151,8 +151,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 ) {
@@ -179,8 +179,8 @@ static void xen_remap_bucket(MapCacheEntry *entry, entry->vaddr_base = vaddr_base; entry->paddr_index = address_index; entry->size = size; - entry->valid_mapping = (unsigned long *)g_malloc0 (sizeof (unsigned long ) * -BITS_TO_LONGS (size >>XC_PAGE_SHIFT )); + entry->valid_mapping = g_new0(unsigned long, +BITS_TO_LONGS (size >>XC_PAGE_SHIFT ));bitmap_zero (entry->valid_mapping, nb_pfn);for (i =0 ; i < nb_pfn; i++) {
@@ -251,7 +251,7 @@ tryagain: 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) {
@@ -279,7 +279,7 @@ tryagain: mapcache->last_entry = entry;if (lock) { -MapCacheRev *reventry =g_malloc0 (sizeof (MapCacheRev)); +MapCacheRev *reventry =g_new0 (MapCacheRev,1 ); entry->lock++; reventry->vaddr_req = mapcache->last_entry->vaddr_base + address_offset; reventry->paddr_index = mapcache->last_entry->paddr_index;
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 1/2] qga: Fix memory allocation pasto
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
qmp_guest_file_seek()allocates memory for a GuestFileRead object instead of the GuestFileSeek object it actually uses. Harmless, because the GuestFileRead is slightly larger.Signed-off-by Markus Armbruster <[email protected]>--- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
qga/commands-posix.c +1
-1@@ -525,7 +525,7 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,if (ret ==-1 ) {error_setg_errno (err, errno,"failed to seek file" ); }else { - seek_data =g_malloc0 (sizeof (GuestFileRead)); + seek_data =g_new0 (GuestFileSeek,1 ); seek_data->position =ftell (fh); seek_data->eof =feof (fh); }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 9 lines · Markus Armbruster
PATCH 1/2 fixes a bug found by compiling the original PATCH 2/2. Evidence for my claim that PATCH 2/2 lets the compiler catch more type errors :)
Markus Armbruster (2):
qga: Fix memory allocation pasto
Useg_new()& friends where that makes obvious sense186 files changed, 376 insertions(+), 415 deletions(-)
No objection in principle, but I think this is going to be hideous merge pain since it touches a huge range of files. Could you split it up into separate patches that could reasonably go in via the appropriate submaintainer trees?
thanks
-- PMM
Quoted 8 lines · Markus Armbruster
g_new(T, n)is safer thang_malloc(sizeof(T) * n)for two reasons. One, it catches multiplication overflowingsize_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors.Patch created with the following Coccinelle patch, with two hunks dropped from the result:
Looks like a reasonable formula for replacement.
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>---
186 files changed, 375 insertions(+), 414 deletions(-)
Is there any easy way to enforce that this style does not creep back into the code base? In other words, can you do a followup patch to checkpatch.pl that flags use of g_malloc[0]?
block/qcow2-snapshot.c int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) · line 662
Quoted 7 lines
block/qcow2-snapshot.c +1
-1@@ -658,7 +658,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++) {
Should checkpatch.pl care about the spacing after 'for'? Then again, it's unrelated to your conversion, so omitting a whitespace cleanup from this patch doesn't hurt.
hw/char/virtio-serial-bus.c static void virtio_serial_device_realize(DeviceState *dev, Error **errp) · line 925
Quoted 11 lines
hw/char/virtio-serial-bus.c +3
-4+++ b/hw/char/virtio-serial-bus.c@@ -921,10 +921,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)QTAILQ_INIT (&vser->ports); vser->bus.max_nr_ports = vser->serial.max_virtserial_ports; - vser->ivqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); - vser->ovqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); + vser->ivqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports); + vser->ovqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);
I'm impressed at what Coccinelle can rewrite!
ui/keymaps.c static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, · line 112
Quoted 9 lines
ui/keymaps.c +2
-1+++ b/ui/keymaps.c@@ -107,7 +107,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, }if (!k) - k =g_malloc0 (sizeof (kbd_layout_t)); + k =g_new0 (kbd_layout_t,1 );for (;;) {
Fixing tab damage while you are at it - nice. And just noticed this is another instance of no space after 'for', but not worth fixing in this patch if checkpatch.pl is happy.
I'm trusting coccinelle, and only glanced through random spots of the patch; but where I looked, I didn't find any problems in the conversion.
I don't know if that means we should add:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 5 lines · Eric Blake
Quoted 5 lines
Quoted 5 lines
block/qcow2-snapshot.c +0
-0@@ -658,7 +658,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)return s->nb_snapshots; }
Quoted 7 lines
Quoted 3 lines
block/qcow2-snapshot.c int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) · line 662
Quoted 3 lines
block/qcow2-snapshot.c +1
-1- 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++) {Should checkpatch.pl care about the spacing after 'for'? Then again, it's unrelated to your conversion, so omitting a whitespace cleanup from this patch doesn't hurt.
checkpatch.pl won't check lines that aren't touched, as you see here.
r~
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Markus Armbruster
PATCH 1/2 fixes a bug found by compiling the original PATCH 2/2. Evidence for my claim that PATCH 2/2 lets the compiler catch more type errors :)
Markus Armbruster (2):
qga: Fix memory allocation pasto
Useg_new()& friends where that makes obvious sense
Quoted 6 lines
Quoted 1 line
186 files changed, 376 insertions(+), 415 deletions(-)No objection in principle, but I think this is going to be hideous merge pain since it touches a huge range of files. Could you split it up into separate patches that could reasonably go in via the appropriate submaintainer trees?
No merge pain at all if you simply rerun the included Coccinelle patch!
Splitting the patch may shift some pain from the choke point (you) to submaintainers and me. I don't mind the splitting pain. I do mind the "chase the nominal maintainer of obscure corner" pain.
If you really want it split: what about splitting off just the busy and/or well-maintained subsystems?
Quoted 13 lines · Eric Blake
Quoted 8 lines · Markus Armbruster
g_new(T, n)is safer thang_malloc(sizeof(T) * n)for two reasons. One, it catches multiplication overflowingsize_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors.Patch created with the following Coccinelle patch, with two hunks dropped from the result:
Looks like a reasonable formula for replacement.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Signed-off-by Markus Armbruster <[email protected]>---
186 files changed, 375 insertions(+), 414 deletions(-)Is there any easy way to enforce that this style does not creep back into the code base? In other words, can you do a followup patch to checkpatch.pl that flags use of g_malloc[0]?
There are many, many uses of g_malloc(), g_malloc0() and g_realloc() left. The ones with a size argument of the form sizeof(E) * N could be rewritten, too. But there are plenty of others.
For the sizeof(E) * N cases, rewriting may not be an improvement. The pattern "p = malloc(sizeof(*p))" is pretty idiomatic.
Having checkpatch.pl match the unwanted patterns sizeof(T), sizeof(T)*N, and their variations seems infeasible to me, because deciding whether T is a type is beyond its capabilities.
Ideas?
Quoted 11 lines
block/qcow2-snapshot.c int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) · line 662
Quoted 7 lines
block/qcow2-snapshot.c +1
-1@@ -658,7 +658,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++) {Should checkpatch.pl care about the spacing after 'for'? Then again, it's unrelated to your conversion, so omitting a whitespace cleanup from this patch doesn't hurt.
It already does as far as I can tell, but as Richard said, it only complains about style violations in changed lines.
Quoted 5 lines
Quoted 5 lines
hw/char/virtio-serial-bus.c +1
-0+++ b/hw/char/virtio-serial-bus.c@@ -921,10 +921,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)QTAILQ_INIT (&vser->ports);
Quoted 9 lines
hw/char/virtio-serial-bus.c static void virtio_serial_device_realize(DeviceState *dev, Error **errp) · line 925
Quoted 7 lines
hw/char/virtio-serial-bus.c +2
-4vser->bus.max_nr_ports = vser->serial.max_virtserial_ports; - vser->ivqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); - vser->ovqs =g_malloc (vser->serial.max_virtserial_ports - *sizeof (VirtQueue *)); + vser->ivqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports); + vser->ovqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);I'm impressed at what Coccinelle can rewrite!
Yup. It's quite capable, but its language is weird, and its error messages can compete with C++ is mysteriousness (thankfully not in length).
Quoted 15 lines
ui/keymaps.c static kbd_layout_t *parse_keyboard_layout(const · line 113
Quoted 10 lines
ui/keymaps.c +2
-1+++ b/ui/keymaps.c@@ -107,7 +107,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, }if (!k) - k =g_malloc0 (sizeof (kbd_layout_t)); + k =g_new0 (kbd_layout_t,1 );for (;;) {Fixing tab damage while you are at it - nice. And just noticed this is another instance of no space after 'for', but not worth fixing in this patch if checkpatch.pl is happy.
Quoted 5 lines
I'm trusting coccinelle, and only glanced through random spots of the patch; but where I looked, I didn't find any problems in the conversion.
I don't know if that means we should add:
Reviewed-by Eric Blake <[email protected]>
Thank you!
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
Quoted 1 line · Markus Armbruster
186 files changed, 376 insertions(+), 415 deletions(-)No objection in principle, but I think this is going to be hideous merge pain since it touches a huge range of files. Could you split it up into separate patches that could reasonably go in via the appropriate submaintainer trees?
No merge pain at all if you simply rerun the included Coccinelle patch!
Yes, but that requires me to find, install, learn about and use Coccinelle.
Quoted 6 lines
Splitting the patch may shift some pain from the choke point (you) to submaintainers and me. I don't mind the splitting pain. I do mind the "chase the nominal maintainer of obscure corner" pain.
If you really want it split: what about splitting off just the busy and/or well-maintained subsystems?
Yes, that's fine. You can put the "miscellaneous leftovers" parts through trivial if you like. I just dislike single touches-entire-world patches if they're not absolutely necessary.
thanks
-- PMM
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
Quoted 1 line · Markus Armbruster
186 files changed, 376 insertions(+), 415 deletions(-)No objection in principle, but I think this is going to be hideous merge pain since it touches a huge range of files. Could you split it up into separate patches that could reasonably go in via the appropriate submaintainer trees?
No merge pain at all if you simply rerun the included Coccinelle patch!
Yes, but that requires me to find, install, learn about and use Coccinelle.
Quoted 4 lines
Splitting the patch may shift some pain from the choke point (you) to submaintainers and me. I don't mind the splitting pain. I do mind the "chase the nominal maintainer of obscure corner" pain.
Quoted 6 lines
Quoted 2 lines
If you really want it split: what about splitting off just the busy and/or well-maintained subsystems?
Yes, that's fine. You can put the "miscellaneous leftovers" parts through trivial if you like. I just dislike single touches-entire-world patches if they're not absolutely necessary.
Unfortunately, our use of macros confuses coccinelle sufficiently to miss quite a few instances of the patterns. Do we want this change anyway?
Il 04/02/2014 17:52, Markus Armbruster ha scritto:
Quoted 3 lines
Unfortunately, our use of macros confuses coccinelle sufficiently to miss quite a few instances of the patterns. Do we want this change anyway?
Yes, we already use g_new anyway.
Paolo
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
Quoted 1 line · Markus Armbruster
186 files changed, 376 insertions(+), 415 deletions(-)No objection in principle, but I think this is going to be hideous merge pain since it touches a huge range of files. Could you split it up into separate patches that could reasonably go in via the appropriate submaintainer trees?
No merge pain at all if you simply rerun the included Coccinelle patch!
Yes, but that requires me to find, install, learn about and use Coccinelle.
Quoted 4 lines
Splitting the patch may shift some pain from the choke point (you) to submaintainers and me. I don't mind the splitting pain. I do mind the "chase the nominal maintainer of obscure corner" pain.
Quoted 6 lines
Quoted 2 lines
If you really want it split: what about splitting off just the busy and/or well-maintained subsystems?
Yes, that's fine. You can put the "miscellaneous leftovers" parts through trivial if you like. I just dislike single touches-entire-world patches if they're not absolutely necessary.
I started splitting the patch, and it bores me to tears.
Peter, any chance for applying as is, with all conflicting hunks summarily dropped?
Quoted 4 lines · Markus Armbruster
I started splitting the patch, and it bores me to tears.
Peter, any chance for applying as is, with all conflicting hunks summarily dropped?
I'm afraid that sounds like too much manual effort on my part.
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Markus Armbruster
I started splitting the patch, and it bores me to tears.
Peter, any chance for applying as is, with all conflicting hunks summarily dropped?
I'm afraid that sounds like too much manual effort on my part.
git-pull -s recursive -X ours ?
Quick experiment to gauge the likelihood of conflicts: I reran coccinelle on v1.7.0, then attempted to merge the result into master. I got *two* conflicts. I backed out with "git-merge --abort", then merged with "git-merge -s recursive -X ours g_new.old" to drop both conflicting hunks, and the result is just fine.
Peter, would you be willing to honor a pull request?
Quoted 7 lines · Markus Armbruster
Quick experiment to gauge the likelihood of conflicts: I reran coccinelle on v1.7.0, then attempted to merge the result into master. I got *two* conflicts. I backed out with "git-merge --abort", then merged with "git-merge -s recursive -X ours g_new.old" to drop both conflicting hunks, and the result is just fine.
Peter, would you be willing to honor a pull request?
I've thought about this for a few days and (especially given Kevin's recent complaint about another cleanup that didn't go through the right subtrees) I think the answer is no. Split it up into manageable pieces and submit them separately via the appropriate submaintainers, please.
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Markus Armbruster
Quick experiment to gauge the likelihood of conflicts: I reran coccinelle on v1.7.0, then attempted to merge the result into master. I got *two* conflicts. I backed out with "git-merge --abort", then merged with "git-merge -s recursive -X ours g_new.old" to drop both conflicting hunks, and the result is just fine.
Quoted 7 lines
Quoted 1 line
Peter, would you be willing to honor a pull request?
I've thought about this for a few days and (especially given Kevin's recent complaint about another cleanup that didn't go through the right subtrees) I think the answer is no. Split it up into manageable pieces and submit them separately via the appropriate submaintainers, please.
PATCH 1/2 is a bug fix, please apply it directly, or tell me to resubmit via -trivial.
I'll stick splitting up 2/2 in my queue, but given its work / benefit ratio, it's unlikely to happen, to be honest.
Quoted 2 lines · Markus Armbruster
PATCH 1/2 is a bug fix, please apply it directly, or tell me to resubmit via -trivial.
Yes, please send that via trivial.
thanks
-- PMM
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Markus Armbruster
PATCH 1/2 is a bug fix, please apply it directly, or tell me to resubmit via -trivial.
Yes, please send that via trivial.
Done & thanks