Convert calls to g_malloc() using casts to g_new()
Subsystems (3)
PATCH 1/5 Convert calls to g_malloc() using casts to g_new()
Convert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the return value is casted to the same type as specified using sizeof() in the parameter to g_malloc() and assigned to a variable of that type.
This was achieved using Coccinelle with the following semantic patch:
@@ type T; T *E; @@
-E = (T *)g_malloc(sizeof(T))
+E = g_new(T, 1)
@@ type T; T *E; @@
-E = (T *)g_malloc0(sizeof(T))
+E = g_new0(T, 1)
@@ type T; T *E; expression N; @@
-E = (T *)g_malloc(sizeof(T) * N)
+E = g_new(T, N)
@@ type T; T *E; expression N; @@
-E = (T *)g_malloc0(sizeof(T) * N)
+E = g_new0(T, N)
--- console.c | 6 +++--- gdbstub.c | 2 +- hw/arm_timer.c | 2 +- hw/bt-hci-csr.c | 3 +-- hw/ccid-card-emulated.c | 4 ++-- hw/ide/microdrive.c | 2 +- hw/irq.c | 4 ++-- hw/ivshmem.c | 3 +-- hw/mcf5206.c | 4 ++-- hw/mcf5208.c | 2 +- hw/mcf_fec.c | 2 +- hw/mips_malta.c | 2 +- hw/omap1.c | 30 ++++++++++-------------------- hw/omap2.c | 15 +++++---------- hw/omap_clk.c | 2 +- hw/omap_dma.c | 6 ++---- hw/omap_dss.c | 3 +-- hw/omap_gpmc.c | 3 +-- hw/omap_gptimer.c | 3 +-- hw/omap_i2c.c | 6 ++---- hw/omap_lcdc.c | 3 +-- hw/omap_mmc.c | 6 ++---- hw/omap_sdrc.c | 3 +-- hw/omap_spi.c | 3 +-- hw/omap_uart.c | 3 +-- hw/ps2.c | 4 ++-- hw/ptimer.c | 2 +- hw/pxa2xx.c | 14 ++++++-------- hw/pxa2xx_keypad.c | 2 +- hw/pxa2xx_lcd.c | 2 +- hw/pxa2xx_mmci.c | 2 +- hw/pxa2xx_pcmcia.c | 3 +-- hw/rc4030.c | 4 ++-- hw/sd.c | 2 +- hw/sh_timer.c | 4 ++-- hw/sm501.c | 2 +- hw/stellaris.c | 2 +- hw/stellaris_input.c | 4 ++-- hw/tc6393xb.c | 2 +- hw/tsc2005.c | 3 +-- hw/tsc210x.c | 6 ++---- libcacard/cac.c | 2 +- libcacard/card_7816.c | 8 ++++---- libcacard/event.c | 2 +- libcacard/vcard.c | 6 +++--- libcacard/vcard_emul_nss.c | 10 +++++----- libcacard/vreader.c | 7 +++---- ui/curses.c | 2 +- ui/sdl.c | 2 +- usb-redir.c | 2 +- xen-mapcache.c | 4 ++-- 51 files changed, 94 insertions(+), 131 deletions(-)
console.c +3 -3
@@ -1270,7 +1270,7 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)static DisplaySurface *defaultallocator_create_displaysurface (int width,int height) { -DisplaySurface *surface = (DisplaySurface *)g_malloc0 (sizeof (DisplaySurface)); +DisplaySurface *surface =g_new0 (DisplaySurface,1 );int linesize = width *4 ; qemu_alloc_display(surface, width, height, linesize,
@@ -1311,7 +1311,7 @@ void qemu_alloc_display(DisplaySurface *surface, int width, int height,DisplaySurface *qemu_create_displaysurface_from (int width,int height,int bpp,int linesize,uint8_t *data) { -DisplaySurface *surface = (DisplaySurface *)g_malloc0 (sizeof (DisplaySurface)); +DisplaySurface *surface =g_new0 (DisplaySurface,1 ); surface->width = width; surface->height = height;
@@ -1397,7 +1397,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,TextConsole *s;DisplayState *ds; - ds = (DisplayState *)g_malloc0 (sizeof (DisplayState)); + ds =g_new0 (DisplayState,1 ); ds->allocator = &default_allocator; ds->surface =qemu_create_displaysurface (ds,640 ,480 );
gdbstub.c +1 -1
@@ -1768,7 +1768,7 @@ void gdb_register_coprocessor(CPUState * env,GDBRegisterState **p;static int last_reg =NUM_CORE_REGS ; - s = (GDBRegisterState *)g_malloc0 (sizeof (GDBRegisterState)); + s =g_new0 (GDBRegisterState,1 ); s->base_reg = last_reg; s->num_regs = num_regs; s->get_reg = get_reg;
hw/arm_timer.c +1 -1
@@ -159,7 +159,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/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/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/ide/microdrive.c +1 -1
@@ -530,7 +530,7 @@ static int dscm1xxxx_detach(void *opaque)PCMCIACardState *dscm1xxxx_init (DriveInfo *bdrv) { -MicroDriveState *md = (MicroDriveState *)g_malloc0 (sizeof (MicroDriveState)); +MicroDriveState *md =g_new0 (MicroDriveState,1 ); md->card.state = md; md->card.attach = dscm1xxxx_attach; md->card.detach = dscm1xxxx_detach;
hw/irq.c +2 -2
@@ -44,8 +44,8 @@ qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)struct IRQState *p;int i; - s = (qemu_irq *)g_malloc0 (sizeof (qemu_irq) * n); - p = (struct IRQState *)g_malloc0 (sizeof (struct IRQState ) * n); + s =g_new0 (qemu_irq, n); + p = g_new0(struct IRQState, n);for (i =0 ; i < n; i++) { p->handler = handler; p->opaque = opaque;
hw/ivshmem.c +1 -2
@@ -467,8 +467,7 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)if (guest_max_eventfd ==0 ) {/* one eventfd per MSI vector */ - s->peers[incoming_posn].eventfds = (int *)g_malloc (s->vectors * -sizeof (int )); + s->peers[incoming_posn].eventfds =g_new (int, s->vectors); }/* this is an eventfd for a particular guest VM */
hw/mcf5206.c +2 -2
@@ -132,7 +132,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;
@@ -523,7 +523,7 @@ qemu_irq *mcf5206_init(uint32_t base, CPUState *env)qemu_irq *pic;int iomemtype; - s = (m5206_mbar_state *)g_malloc0 (sizeof (m5206_mbar_state)); + s =g_new0 (m5206_mbar_state,1 ); iomemtype =cpu_register_io_memory (m5206_mbar_readfn, m5206_mbar_writefn, s,DEVICE_NATIVE_ENDIAN );
hw/mcf5208.c +1 -1
@@ -175,7 +175,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, &m5208_timer_ops, s,
hw/mcf_fec.c +1 -1
@@ -464,7 +464,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)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->irq = irq; s->mmio_index = cpu_register_io_memory(mcf_fec_readfn, mcf_fec_writefn, s,
hw/mips_malta.c +1 -1
@@ -432,7 +432,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, &malta_fpga_ops, s,"malta-fpga" ,0x100000 );
hw/omap1.c +10 -20
@@ -258,8 +258,7 @@ static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,target_phys_addr_t 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;
@@ -387,8 +386,7 @@ static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,target_phys_addr_t 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;
@@ -493,8 +491,7 @@ static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,target_phys_addr_t 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;
@@ -1222,8 +1219,7 @@ static struct omap_tipb_bridge_s *omap_tipb_bridge_init( MemoryRegion *memory, target_phys_addr_t 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);
@@ -2071,8 +2067,7 @@ 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;
@@ -2263,8 +2258,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;
@@ -2879,8 +2873,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;
@@ -3410,8 +3403,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;
@@ -3589,8 +3581,7 @@ static void omap_lpg_clk_update(void *opaque, int line, int on)static struct omap_lpg_s *omap_lpg_init (MemoryRegion *system_memory,target_phys_addr_t 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 =qemu_new_timer_ms (rt_clock, omap_lpg_tick, s);
@@ -3793,8 +3784,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 *cpu_irq;qemu_irq dma_irqs[6 ];DriveInfo *dinfo;
hw/omap2.c +5 -10
@@ -590,8 +590,7 @@ 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) { int iomemtype; -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 ++;
@@ -776,8 +775,7 @@ static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta, CharDriverState *chr) {int iomemtype; -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);
@@ -1789,8 +1787,7 @@ static struct omap_prcm_s *omap_prcm_init(struct omap_target_agent_s *ta, struct omap_mpu_state_s *mpu) {int iomemtype; -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;
@@ -2162,8 +2159,7 @@ static struct omap_sysctl_s *omap_sysctl_init(struct omap_target_agent_s *ta, omap_clk iclk, struct omap_mpu_state_s *mpu) { int iomemtype; -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);
@@ -2226,8 +2222,7 @@ static const struct dma_irq_map omap2_dma_irq_map[] = {struct omap_mpu_state_s *omap2420_mpu_init (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);ram_addr_t sram_base, q2_base;qemu_irq *cpu_irq;qemu_irq dma_irqs[4 ];
hw/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/omap_dma.c +2 -4
@@ -1619,8 +1619,7 @@ struct soc_dma_s *omap_dma_init(target_phys_addr_t base, qemu_irq *irqs, enum omap_dma_model model) {int iomemtype, 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 ;
@@ -2038,8 +2037,7 @@ struct soc_dma_s *omap_dma4_init(target_phys_addr_t base, qemu_irq *irqs, int chans, omap_clk iclk, omap_clk fclk) { int iomemtype, 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/omap_dss.c +1 -2
@@ -1029,8 +1029,7 @@ struct omap_dss_s *omap_dss_init(struct omap_target_agent_s *ta, omap_clk ick1, omap_clk ick2) { int iomemtype[5]; -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/omap_gpmc.c +1 -2
@@ -809,8 +809,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, &omap_gpmc_ops, s,"omap-gpmc" ,0x1000 );memory_region_add_subregion (get_system_memory (), base, &s->iomem);
hw/omap_gptimer.c +1 -2
@@ -464,8 +464,7 @@ struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta, qemu_irq irq, omap_clk fclk, omap_clk iclk) { int iomemtype; -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/omap_i2c.c +2 -4
@@ -425,8 +425,7 @@ struct omap_i2c_s *omap_i2c_init(target_phys_addr_t base, qemu_irq irq, qemu_irq *dma, omap_clk clk) { int iomemtype; -struct omap_i2c_s *s = (struct omap_i2c_s *) -g_malloc0 (sizeof (struct omap_i2c_s )); + struct omap_i2c_s *s = g_new0(struct omap_i2c_s, 1);/* TODO: set a value greater or equal to real hardware */ s->revision =0x11 ;
@@ -447,8 +446,7 @@ struct omap_i2c_s *omap2_i2c_init(struct omap_target_agent_s *ta, qemu_irq irq, qemu_irq *dma, omap_clk fclk, omap_clk iclk) { int iomemtype; -struct omap_i2c_s *s = (struct omap_i2c_s *) -g_malloc0 (sizeof (struct omap_i2c_s )); + struct omap_i2c_s *s = g_new0(struct omap_i2c_s, 1); s->revision =0x34 ; s->irq = irq;
hw/omap_lcdc.c +1 -2
@@ -437,8 +437,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(target_phys_addr_t base, qemu_irq irq, struct omap_dma_lcd_channel_s *dma, omap_clk clk) { int iomemtype; -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/omap_mmc.c +2 -4
@@ -575,8 +575,7 @@ struct omap_mmc_s *omap_mmc_init(target_phys_addr_t base, qemu_irq irq, qemu_irq dma[], omap_clk clk) { int iomemtype; -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;
@@ -601,8 +600,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta, omap_clk fclk, omap_clk iclk) { int iomemtype; -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/omap_sdrc.c +1 -2
@@ -152,8 +152,7 @@ static CPUWriteMemoryFunc * const omap_sdrc_writefn[] = {struct omap_sdrc_s *omap_sdrc_init (target_phys_addr_t base) {int iomemtype; -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/omap_spi.c +1 -2
@@ -314,8 +314,7 @@ 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) { int iomemtype; -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/omap_uart.c +1 -2
@@ -55,8 +55,7 @@ struct omap_uart_s *omap_uart_init(target_phys_addr_t 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/ps2.c +2 -2
@@ -604,7 +604,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;
@@ -617,7 +617,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/ptimer.c +1 -1
@@ -210,7 +210,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 =qemu_new_timer_ns (vm_clock, ptimer_tick, s);return s;
hw/pxa2xx.c +6 -8
@@ -1763,8 +1763,7 @@ static PXA2xxI2SState *pxa2xx_i2s_init(target_phys_addr_t base, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma) { int iomemtype; -PXA2xxI2SState *s = (PXA2xxI2SState *) -g_malloc0 (sizeof (PXA2xxI2SState)); +PXA2xxI2SState *s =g_new0 (PXA2xxI2SState,1 ); s->irq = irq; s->rx_dma = rx_dma;
@@ -2024,8 +2023,7 @@ static PXA2xxFIrState *pxa2xx_fir_init(target_phys_addr_t base, CharDriverState *chr) {int iomemtype; -PXA2xxFIrState *s = (PXA2xxFIrState *) -g_malloc0 (sizeof (PXA2xxFIrState)); +PXA2xxFIrState *s =g_new0 (PXA2xxFIrState,1 ); s->irq = irq; s->rx_dma = rx_dma;
@@ -2065,7 +2063,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,PXA2xxState *s;int iomemtype, 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" );
@@ -2160,7 +2158,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("pxa2xx-ssp", pxa27x_ssp[i].io_base,
@@ -2205,7 +2203,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)int iomemtype, i;DriveInfo *dinfo; - s = (PXA2xxState *)g_malloc0 (sizeof (PXA2xxState)); + s =g_new0 (PXA2xxState,1 ); s->env =cpu_init ("pxa255" );if (!s->env) {
@@ -2292,7 +2290,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("pxa2xx-ssp", pxa255_ssp[i].io_base,
hw/pxa2xx_keypad.c +1 -1
@@ -312,7 +312,7 @@ PXA2xxKeyPadState *pxa27x_keypad_init(target_phys_addr_t base,int iomemtype;PXA2xxKeyPadState *s; - s = (PXA2xxKeyPadState *)g_malloc0 (sizeof (PXA2xxKeyPadState)); + s =g_new0 (PXA2xxKeyPadState,1 ); s->irq = irq; iomemtype = cpu_register_io_memory(pxa2xx_keypad_readfn,
hw/pxa2xx_lcd.c +1 -1
@@ -986,7 +986,7 @@ PXA2xxLCDState *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq)int iomemtype;PXA2xxLCDState *s; - s = (PXA2xxLCDState *)g_malloc0 (sizeof (PXA2xxLCDState)); + s =g_new0 (PXA2xxLCDState,1 ); s->invalidated =1 ; s->irq = irq;
hw/pxa2xx_mmci.c +1 -1
@@ -524,7 +524,7 @@ PXA2xxMMCIState *pxa2xx_mmci_init(target_phys_addr_t base,int iomemtype;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/pxa2xx_pcmcia.c +1 -2
@@ -135,8 +135,7 @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(target_phys_addr_t base)int iomemtype;PXA2xxPCMCIAState *s; - s = (PXA2xxPCMCIAState *) -g_malloc0 (sizeof (PXA2xxPCMCIAState)); + s =g_new0 (PXA2xxPCMCIAState,1 );/* Socket I/O Memory Space */ iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_io_readfn,
hw/rc4030.c +2 -2
@@ -789,8 +789,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;
hw/sd.c +1 -1
@@ -442,7 +442,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi) {SDState *sd; - sd = (SDState *)g_malloc0 (sizeof (SDState)); + sd =g_new0 (SDState,1 ); sd->buf =qemu_blockalign (bs,512 ); sd->spi = is_spi; sd->enable =1 ;
hw/sh_timer.c +2 -2
@@ -188,7 +188,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 ;
@@ -311,7 +311,7 @@ void tmu012_init(target_phys_addr_t base, int feat, uint32_t freq,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/sm501.c +1 -1
@@ -1395,7 +1395,7 @@ void sm501_init(MemoryRegion *address_space_mem, uint32_t base,int sm501_2d_engine_index;/* 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/stellaris.c +1 -1
@@ -670,7 +670,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq,int iomemtype;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/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/tc6393xb.c +1 -1
@@ -579,7 +579,7 @@ TC6393xbState *tc6393xb_init(uint32_t base, qemu_irq irq) tc6393xb_writel, }; - 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/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/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 ;
libcacard/cac.c +1 -1
@@ -288,7 +288,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 +5 -5
@@ -94,9 +94,9 @@ vcard_emul_alloc_arrays(unsigned char ***certsp, int **cert_lenp, *certsp =NULL ; *cert_lenp =NULL ; *keysp =NULL ; - *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);return PR_TRUE ; }
@@ -140,7 +140,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 */
@@ -452,7 +452,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;
libcacard/vreader.c +3 -4
@@ -46,7 +46,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 = name ?strdup (name) :NULL ;
@@ -236,8 +236,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);
@@ -260,7 +259,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;
ui/curses.c +1 -1
@@ -354,7 +354,7 @@ void curses_display_init(DisplayState *ds, int full_screen)#endif #endif - dcl = (DisplayChangeListener *)g_malloc0 (sizeof (DisplayChangeListener)); + dcl =g_new0 (DisplayChangeListener,1 ); dcl->dpy_update = curses_update; dcl->dpy_resize = curses_resize; dcl->dpy_refresh = curses_refresh;
ui/sdl.c +1 -1
@@ -166,7 +166,7 @@ static PixelFormat sdl_to_qemu_pixelformat(SDL_PixelFormat *sdl_pf)static DisplaySurface *sdl_create_displaysurface (int width,int height) { -DisplaySurface *surface = (DisplaySurface *)g_malloc0 (sizeof (DisplaySurface)); +DisplaySurface *surface =g_new0 (DisplaySurface,1 );if (surface ==NULL ) {fprintf (stderr,"sdl_create_displaysurface: malloc failed\n" );exit (1 );
usb-redir.c +1 -1
@@ -234,7 +234,7 @@ static int usbredir_write(void *priv, uint8_t *data, int count)static AsyncURB *async_alloc (USBRedirDevice *dev,USBPacket *p) { -AsyncURB *aurb = (AsyncURB *)g_malloc0 (sizeof (AsyncURB)); +AsyncURB *aurb =g_new0 (AsyncURB,1 ); aurb->dev = dev; aurb->packet = p; aurb->packet_id = dev->packet_id;
xen-mapcache.c +2 -2
@@ -173,8 +173,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++) {
Signature · 1 line
1.7.4.1
PATCH 2/5 Convert use of ptr = g_malloc(sizeof(*ptr)) to g_new()
Convert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the size passed to g_malloc() is specified as that of the type referenced by the pointer to which the result is assigned.
This was achieved using Coccinelle with the following semantic patch:
@@ type T; T *E; @@
-E = g_malloc(sizeof(*E))
+E = g_new(T, 1)
@@ type T; T *E; @@
-E = g_malloc0(sizeof(*E))
+E = g_new0(T, 1)
@@ type T; T *E; expression N; @@
-E = g_malloc(sizeof(*E) * N)
+E = g_new(T, N)
@@ type T; T *E; expression N; @@
-E = g_malloc0(sizeof(*E) * N)
+E = g_new0(T, N)
--- acl.c | 6 +++--- arch_init.c | 2 +- audio/wavcapture.c | 2 +- block.c | 2 +- block/blkdebug.c | 2 +- block/qcow2-cache.c | 2 +- block/qed-cluster.c | 2 +- block/qed-l2-cache.c | 2 +- block/rbd.c | 2 +- block/sheepdog.c | 4 ++-- blockdev.c | 2 +- buffered_file.c | 2 +- coroutine-gthread.c | 4 ++-- coroutine-ucontext.c | 4 ++-- coroutine-win32.c | 2 +- error.c | 4 ++-- exec.c | 12 ++++++------ fsdev/qemu-fsdev.c | 2 +- gdbstub.c | 2 +- hw/9pfs/virtio-9p.c | 4 ++-- hw/bt-hid.c | 2 +- hw/bt-l2cap.c | 4 ++-- hw/bt-sdp.c | 12 +++++------- hw/cirrus_vga.c | 2 +- hw/etraxfs_dma.c | 2 +- hw/grlib_irqmp.c | 2 +- hw/isa_mmio.c | 2 +- hw/loader.c | 4 ++-- hw/msix.c | 3 +-- hw/omap_l4.c | 2 +- hw/omap_synctimer.c | 2 +- hw/pc.c | 12 ++++++------ hw/pc_piix.c | 2 +- hw/pci.c | 4 ++-- hw/pcie_port.c | 2 +- hw/ppc405_boards.c | 4 ++-- hw/ppc440.c | 3 +-- hw/qdev-properties.c | 2 +- hw/spapr.c | 2 +- hw/sysbus.c | 2 +- hw/usb-desc.c | 2 +- hw/usb-ehci.c | 2 +- hw/usb-musb.c | 2 +- hw/vga-isa-mm.c | 6 +++--- hw/vga.c | 4 ++-- hw/vhost.c | 2 +- hw/vhost_net.c | 2 +- hw/virtio-blk.c | 2 +- hw/xen_devconfig.c | 2 +- hw/xen_disk.c | 2 +- hw/xics.c | 4 ++-- hw/xtensa_lx60.c | 8 ++++---- hw/xtensa_sim.c | 4 ++-- linux-aio.c | 2 +- linux-user/elfload.c | 6 +++--- memory.c | 2 +- migration-exec.c | 2 +- migration-fd.c | 2 +- migration-tcp.c | 2 +- migration-unix.c | 2 +- module.c | 2 +- monitor.c | 10 +++++----- net/slirp.c | 6 +++--- qapi/qapi-dealloc-visitor.c | 4 ++-- qapi/qmp-input-visitor.c | 4 ++-- qapi/qmp-output-visitor.c | 4 ++-- qapi/qmp-registry.c | 2 +- qbool.c | 2 +- qdict.c | 4 ++-- qemu-char.c | 4 ++-- qemu-io.c | 6 +++--- qemu-option.c | 4 ++-- qemu-thread-win32.c | 2 +- qerror.c | 2 +- qfloat.c | 2 +- qint.c | 2 +- qlist.c | 4 ++-- qmp.c | 8 ++++---- qstring.c | 2 +- readline.c | 2 +- target-xtensa/helper.c | 2 +- ui/keymaps.c | 2 +- ui/spice-core.c | 6 +++--- ui/spice-display.c | 2 +- ui/spice-input.c | 4 ++-- ui/vnc-palette.c | 2 +- ui/vnc.c | 2 +- usb-linux.c | 2 +- vl.c | 4 ++-- xen-all.c | 4 ++-- 90 files changed, 148 insertions(+), 152 deletions(-)
acl.c +3 -3
@@ -55,7 +55,7 @@ qemu_acl *qemu_acl_init(const char *aclname)if (acl)return acl; - acl =g_malloc (sizeof (*acl)); + acl =g_new (qemu_acl,1 ); acl->aclname =g_strdup (aclname);/* Deny by default, so there is no window of "open * access" between QEMU starting, and the user setting
@@ -116,7 +116,7 @@ int qemu_acl_append(qemu_acl *acl, {qemu_acl_entry *entry; - entry =g_malloc (sizeof (*entry)); + entry =g_new (qemu_acl_entry,1 ); entry->match =g_strdup (match); entry->deny = deny;
@@ -142,7 +142,7 @@ int qemu_acl_insert(qemu_acl *acl,return qemu_acl_append (acl, deny, match); - entry =g_malloc (sizeof (*entry)); + entry =g_new (qemu_acl_entry,1 ); entry->match =g_strdup (match); entry->deny = deny;
arch_init.c +1 -1
@@ -237,7 +237,7 @@ static void sort_ram_list(void) QLIST_FOREACH(block, &ram_list.blocks, next) { ++n; } - blocks =g_malloc (n *sizeof *blocks); + blocks = g_new(RAMBlock *, n); n =0 ; QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { blocks[n++] = block;
audio/wavcapture.c +1 -1
@@ -143,7 +143,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, ops.capture = wav_capture; ops.destroy = wav_destroy; - wav =g_malloc0 (sizeof (*wav)); + wav =g_new0 (WAVState,1 ); shift = bits16 + stereo; hdr[34 ] = bits16 ?0x10 :0x08 ;
block.c +1 -1
@@ -2472,7 +2472,7 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs,if (merge) {size_t size; -QEMUIOVector *qiov =g_malloc0 (sizeof (*qiov)); +QEMUIOVector *qiov =g_new0 (QEMUIOVector,1 );qemu_iovec_init (qiov, reqs[outidx].qiov->niov + reqs[i].qiov->niov +1 );
block/blkdebug.c +1 -1
@@ -214,7 +214,7 @@ static int add_rule(QemuOpts *opts, void *opaque) }/* Set attributes common for all actions */ - rule =g_malloc0 (sizeof (*rule)); + rule = g_new0(struct BlkdebugRule, 1); *rule = (struct BlkdebugRule ) { .event = event, .action = d->action,
block/qcow2-cache.c +1 -1
@@ -49,7 +49,7 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,Qcow2Cache *c;int i; - c =g_malloc0 (sizeof (*c)); + c =g_new0 (Qcow2Cache,1 ); c->size = num_tables; c->entries =g_malloc0 (sizeof (*c->entries) * num_tables); c->writethrough = writethrough;
block/qed-cluster.c +1 -1
@@ -152,7 +152,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos,return ; } - find_cluster_cb =g_malloc (sizeof (*find_cluster_cb)); + find_cluster_cb =g_new (QEDFindClusterCB,1 ); find_cluster_cb->s = s; find_cluster_cb->pos = pos; find_cluster_cb->len = len;
block/qed-l2-cache.c +1 -1
@@ -89,7 +89,7 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache) {CachedL2Table *entry; - entry =g_malloc0 (sizeof (*entry)); + entry =g_new0 (CachedL2Table,1 ); entry->ref++;trace_qed_alloc_l2_cache_entry (l2_cache, entry);
block/rbd.c +1 -1
@@ -800,7 +800,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,int max_snaps =RBD_MAX_SNAPS ; do { - snaps = g_malloc(sizeof(*snaps) * max_snaps); + snaps = g_new(rbd_snap_info_t, max_snaps); snap_count = rbd_snap_list(s->image, snaps, &max_snaps); if (snap_count < 0) { g_free(snaps);
block/sheepdog.c +2 -2
@@ -369,7 +369,7 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, {AIOReq *aio_req; - aio_req =g_malloc (sizeof (*aio_req)); + aio_req =g_new (AIOReq,1 ); aio_req->aiocb = acb; aio_req->iov_offset = iov_offset; aio_req->oid = oid;
@@ -1956,7 +1956,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) goto out; } - sn_tab =g_malloc0 (nr *sizeof (*sn_tab)); + sn_tab =g_new0 (QEMUSnapshotInfo, nr);/* calculate a vdi id with hash function */ hval =fnv_64a_buf (s->name,strlen (s->name),FNV1A_64_INIT );
blockdev.c +1 -1
@@ -432,7 +432,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)/* init */ - dinfo =g_malloc0 (sizeof (*dinfo)); + dinfo =g_new0 (DriveInfo,1 );if ((buf =qemu_opts_id (opts)) !=NULL ) { dinfo->id =g_strdup (buf); }else {
buffered_file.c +1 -1
@@ -259,7 +259,7 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque, {QEMUFileBuffered *s; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (QEMUFileBuffered,1 ); s->opaque = opaque; s->xfer_limit = bytes_per_sec /10 ;
coroutine-gthread.c +2 -2
@@ -71,7 +71,7 @@ Coroutine *qemu_coroutine_new(void) {CoroutineGThread *co; - co =g_malloc0 (sizeof (*co)); + co =g_new0 (CoroutineGThread,1 ); co->thread =g_thread_create_full (coroutine_thread, co,0 , TRUE, TRUE,G_THREAD_PRIORITY_NORMAL ,NULL );if (!co->thread) {
@@ -115,7 +115,7 @@ Coroutine *qemu_coroutine_self(void)CoroutineGThread *co =g_static_private_get (&coroutine_key);if (!co) { - co =g_malloc0 (sizeof (*co)); + co =g_new0 (CoroutineGThread,1 ); co->runnable = true;g_static_private_set (&coroutine_key, co, (GDestroyNotify )g_free); }
coroutine-ucontext.c +2 -2
@@ -73,7 +73,7 @@ static CoroutineThreadState *coroutine_get_thread_state(void)CoroutineThreadState *s =pthread_getspecific (thread_state_key);if (!s) { - s =g_malloc0 (sizeof (*s)); + s =g_new0 (CoroutineThreadState,1 ); s->current = &s->leader.base;QLIST_INIT (&s->pool);pthread_setspecific (thread_state_key, s);
@@ -146,7 +146,7 @@ static Coroutine *coroutine_new(void)abort (); } - co =g_malloc0 (sizeof (*co)); + co =g_new0 (CoroutineUContext,1 ); co->stack =g_malloc (stack_size); co->base.entry_arg = &old_env;/* stash away our jmp_buf */
coroutine-win32.c +1 -1
@@ -64,7 +64,7 @@ Coroutine *qemu_coroutine_new(void)const size_t stack_size =1 <<20 ;CoroutineWin32 *co; - co =g_malloc0 (sizeof (*co)); + co =g_new0 (CoroutineWin32,1 ); co->fiber =CreateFiber (stack_size, coroutine_trampoline, &co->base);return &co->base; }
error.c +2 -2
@@ -32,7 +32,7 @@ void error_set(Error **errp, const char *fmt, ...)return ; } - err =g_malloc0 (sizeof (*err)); + err =g_new0 (Error,1 );va_start (ap, fmt); err->obj =qobject_to_qdict (qobject_from_jsonv (fmt, &ap));
@@ -137,7 +137,7 @@ void error_set_qobject(Error **errp, QObject *obj)if (errp ==NULL ) {return ; } - err =g_malloc0 (sizeof (*err)); + err =g_new0 (Error,1 ); err->obj =qobject_to_qdict (obj);qobject_incref (obj);
exec.c +6 -6
@@ -1444,7 +1444,7 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len, TARGET_FMT_lx ", len=" TARGET_FMT_lu "\n", addr, len);return -EINVAL ; } - wp =g_malloc (sizeof (*wp)); + wp =g_new (CPUWatchpoint,1 ); wp->vaddr = addr; wp->len_mask = len_mask;
@@ -1509,7 +1509,7 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,#if defined(TARGET_HAS_ICE )CPUBreakpoint *bp; - bp =g_malloc (sizeof (*bp)); + bp =g_new (CPUBreakpoint,1 ); bp->pc = pc; bp->flags = flags;
@@ -2917,7 +2917,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,RAMBlock *new_block, *block; size =TARGET_PAGE_ALIGN (size); - new_block =g_malloc0 (sizeof (*new_block)); + new_block =g_new0 (RAMBlock,1 );if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {char *id = dev->parent_bus->info->get_dev_path (dev);
@@ -3824,11 +3824,11 @@ static void io_mem_init(void)static void memory_map_init (void ) { - system_memory =g_malloc (sizeof (*system_memory)); + system_memory =g_new (MemoryRegion,1 );memory_region_init (system_memory,"system" ,INT64_MAX );set_system_memory_map (system_memory); - system_io =g_malloc (sizeof (*system_io)); + system_io =g_new (MemoryRegion,1 );memory_region_init (system_io,"io" ,65536 );set_system_io_map (system_io); }
@@ -4044,7 +4044,7 @@ static QLIST_HEAD(map_client_list, MapClient) map_client_listvoid *cpu_register_map_client (void *opaque,void (*callback)(void *opaque)) { -MapClient *client =g_malloc (sizeof (*client)); +MapClient *client =g_new (MapClient,1 ); client->opaque = opaque; client->callback = callback;
fsdev/qemu-fsdev.c +1 -1
@@ -66,7 +66,7 @@ int qemu_fsdev_add(QemuOpts *opts)return -1 ; } - fsle =g_malloc (sizeof (*fsle)); + fsle = g_new(struct FsTypeListEntry, 1); fsle->fse.fsdev_id =g_strdup (fsdev_id); fsle->fse.path =g_strdup (path);
gdbstub.c +1 -1
@@ -2886,7 +2886,7 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =g_malloc0 (sizeof (*mon_chr)); + mon_chr =g_new0 (CharDriverState,1 ); mon_chr->chr_write = gdb_monitor_write;monitor_init (mon_chr,0 ); }else {
hw/9pfs/virtio-9p.c +2 -2
@@ -2861,7 +2861,7 @@ static void v9fs_lock(void *opaque)V9fsPDU *pdu = opaque;V9fsState *s = pdu->s; - flock =g_malloc (sizeof (*flock)); + flock =g_new (V9fsFlock,1 );pdu_unmarshal (pdu, offset,"dbdqqds" , &fid, &flock->type, &flock->flags, &flock->start, &flock->length, &flock->proc_id, &flock->client_id);
@@ -2906,7 +2906,7 @@ static void v9fs_getlock(void *opaque)V9fsPDU *pdu = opaque;V9fsState *s = pdu->s; - glock =g_malloc (sizeof (*glock)); + glock =g_new (V9fsGetlock,1 );pdu_unmarshal (pdu, offset,"dbqqds" , &fid, &glock->type, &glock->start, &glock->length, &glock->proc_id, &glock->client_id);
hw/bt-hid.c +1 -1
@@ -517,7 +517,7 @@ enum peripheral_minor_class {static struct bt_device_s *bt_hid_init (struct bt_scatternet_s *net,enum peripheral_minor_class minor) { -struct bt_hid_device_s *s =g_malloc0 (sizeof (*s)); + struct bt_hid_device_s *s = g_new0(struct bt_hid_device_s, 1);uint32_t class =/* Format type */ (0 << 0) |
hw/bt-l2cap.c +2 -2
@@ -410,7 +410,7 @@ static struct l2cap_chan_s *l2cap_channel_open(struct l2cap_instance_s *l2cap,if (psm_info) {/* Device supports this use-case. */ - ch =g_malloc0 (sizeof (*ch)); + ch = g_new0(struct l2cap_chan_s, 1); ch->params.sdu_out = l2cap_bframe_out; ch->params.sdu_submit = l2cap_bframe_submit; ch->frame_in = l2cap_bframe_in;
@@ -1353,7 +1353,7 @@ void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm, int min_mtu,exit (-1 ); } - new_psm =g_malloc0 (sizeof (*new_psm)); + new_psm = g_new0(struct bt_l2cap_psm_s, 1); new_psm->psm = psm; new_psm->min_mtu = min_mtu; new_psm->new_channel = new_channel;
hw/bt-sdp.c +5 -7
@@ -708,10 +708,9 @@ static void sdp_service_record_build(struct sdp_service_record_s *record, &record->uuids); } record->uuids =1 <<ffs (record->uuids -1 ); - record->attribute_list = -g_malloc0 (record->attributes *sizeof (*record->attribute_list)); - record->uuid = -g_malloc0 (record->uuids *sizeof (*record->uuid)); + record->attribute_list = g_new0(struct sdp_service_attribute_s, + record->attributes); + record->uuid =g_new0 (int, record->uuids); data =g_malloc (len); record->attributes =0 ;
@@ -752,8 +751,7 @@ static void sdp_service_db_build(struct bt_l2cap_sdp_state_s *sdp, sdp->services =0 ;while (service[sdp->services]) sdp->services ++; - sdp->service_list = -g_malloc0 (sdp->services *sizeof (*sdp->service_list)); + sdp->service_list = g_new0(struct sdp_service_record_s, sdp->services); sdp->services =0 ;while (*service) {
@@ -942,7 +940,7 @@ SERVICE(pnp,static int bt_l2cap_sdp_new_ch (struct bt_l2cap_device_s *dev,struct bt_l2cap_conn_params_s *params) { -struct bt_l2cap_sdp_state_s *sdp =g_malloc0 (sizeof (*sdp)); + struct bt_l2cap_sdp_state_s *sdp = g_new0(struct bt_l2cap_sdp_state_s, 1);struct sdp_def_service_s *services[] = { &sdp_service_sdp_s, &sdp_service_hid_s,
hw/cirrus_vga.c +1 -1
@@ -2384,7 +2384,7 @@ static void map_linear_vram_bank(CirrusVGAState *s, unsigned bank) && !((s->vga.gr[0x0B] & 0x14) == 0x14) && !(s->vga.gr[0x0B] & 0x02)) { - mr =g_malloc (sizeof (*mr)); + mr =g_new (MemoryRegion,1 );memory_region_init_alias (mr, names[bank], &s->vga.vram, s->cirrus_bank_base[bank],0x8000 ); memory_region_add_subregion_overlap(
hw/etraxfs_dma.c +1 -1
@@ -750,7 +750,7 @@ void *etraxfs_dmac_init(target_phys_addr_t base, int nr_channels) {struct fs_dma_ctrl *ctrl =NULL ; - ctrl =g_malloc0 (sizeof *ctrl); + ctrl = g_new0(struct fs_dma_ctrl, 1); ctrl->bh =qemu_bh_new (DMA_run, ctrl);
hw/grlib_irqmp.c +1 -1
@@ -345,7 +345,7 @@ static int grlib_irqmp_init(SysBusDevice *dev) grlib_irqmp_write, irqmp, DEVICE_NATIVE_ENDIAN); - irqmp->state =g_malloc0 (sizeof *irqmp->state); + irqmp->state =g_new0 (IRQMPState,1 );if (irqmp_regs <0 ) {return -1 ;
hw/isa_mmio.c +1 -1
@@ -74,7 +74,7 @@ void isa_mmio_setup(MemoryRegion *mr, target_phys_addr_t size)void isa_mmio_init (target_phys_addr_t base,target_phys_addr_t size) { -MemoryRegion *mr =g_malloc (sizeof (*mr)); +MemoryRegion *mr =g_new (MemoryRegion,1 );isa_mmio_setup (mr, size);memory_region_add_subregion (get_system_memory (), base, mr);
hw/loader.c +2 -2
@@ -564,7 +564,7 @@ int rom_add_file(const char *file, const char *fw_dir,int rc, fd =-1 ;char devpath[100 ]; - rom =g_malloc0 (sizeof (*rom)); + rom =g_new0 (Rom,1 ); rom->name =g_strdup (file); rom->path =qemu_find_file (QEMU_FILE_TYPE_BIOS , rom->name);if (rom->path ==NULL ) {
@@ -630,7 +630,7 @@ int rom_add_blob(const char *name, const void *blob, size_t len, {Rom *rom; - rom =g_malloc0 (sizeof (*rom)); + rom =g_new0 (Rom,1 ); rom->name =g_strdup (name); rom->addr = addr; rom->romsize = len;
hw/msix.c +1 -2
@@ -219,8 +219,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,if (nentries >MSIX_MAX_ENTRIES )return -EINVAL ; - dev->msix_entry_used =g_malloc0 (MSIX_MAX_ENTRIES * -sizeof *dev->msix_entry_used); + dev->msix_entry_used =g_new0 (unsigned,MSIX_MAX_ENTRIES ); dev->msix_table_page =g_malloc0 (MSIX_PAGE_SIZE );msix_mask_all (dev, nentries);
hw/omap_l4.c +1 -1
@@ -128,7 +128,7 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)#ifdef L4_MUX_HACK omap_l4_io_entries =1 ; - omap_l4_io_entry =g_malloc0 (125 *sizeof (*omap_l4_io_entry)); + omap_l4_io_entry = g_new0(struct omap_l4_entry, 125); omap_cpu_io_entry = cpu_register_io_memory(omap_l4_io_readfn,
hw/omap_synctimer.c +1 -1
@@ -86,7 +86,7 @@ static CPUWriteMemoryFunc * const omap_synctimer_writefn[] = {struct omap_synctimer_s *omap_synctimer_init (struct omap_target_agent_s *ta,struct omap_mpu_state_s *mpu,omap_clk fclk,omap_clk iclk) { -struct omap_synctimer_s *s =g_malloc0 (sizeof (*s)); + struct omap_synctimer_s *s = g_new0(struct omap_synctimer_s, 1);omap_synctimer_reset (s); omap_l4_attach(ta, 0, l4_register_io_memory(
hw/pc.c +6 -6
@@ -987,16 +987,16 @@ void pc_memory_init(MemoryRegion *system_memory,* aliases to address portions of it, mostly for backwards compatiblity * with older qemus that used qemu_ram_alloc(). */ - ram =g_malloc (sizeof (*ram)); + ram =g_new (MemoryRegion,1 );memory_region_init_ram (ram,NULL ,"pc.ram" , below_4g_mem_size + above_4g_mem_size); *ram_memory = ram; - ram_below_4g =g_malloc (sizeof (*ram_below_4g)); + ram_below_4g =g_new (MemoryRegion,1 );memory_region_init_alias (ram_below_4g,"ram-below-4g" , ram,0 , below_4g_mem_size);memory_region_add_subregion (system_memory,0 , ram_below_4g);if (above_4g_mem_size >0 ) { - ram_above_4g =g_malloc (sizeof (*ram_above_4g)); + ram_above_4g =g_new (MemoryRegion,1 );memory_region_init_alias (ram_above_4g,"ram-above-4g" , ram, below_4g_mem_size, above_4g_mem_size); memory_region_add_subregion(system_memory, 0x100000000ULL,
@@ -1016,7 +1016,7 @@ void pc_memory_init(MemoryRegion *system_memory, (bios_size % 65536) != 0) { goto bios_error; } - bios =g_malloc (sizeof (*bios)); + bios =g_new (MemoryRegion,1 );memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size);memory_region_set_readonly (bios, true); ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 );
@@ -1032,7 +1032,7 @@ void pc_memory_init(MemoryRegion *system_memory, isa_bios_size = bios_size;if (isa_bios_size > (128 *1024 )) isa_bios_size =128 *1024 ; - isa_bios =g_malloc (sizeof (*isa_bios)); + isa_bios =g_new (MemoryRegion,1 );memory_region_init_alias (isa_bios,"isa-bios" , bios, bios_size - isa_bios_size, isa_bios_size); memory_region_add_subregion_overlap(rom_memory,
@@ -1041,7 +1041,7 @@ void pc_memory_init(MemoryRegion *system_memory, 1);memory_region_set_readonly (isa_bios, true); - option_rom_mr =g_malloc (sizeof (*option_rom_mr)); + option_rom_mr =g_new (MemoryRegion,1 );memory_region_init_ram (option_rom_mr,NULL ,"pc.rom" ,PC_ROM_SIZE ); memory_region_add_subregion_overlap(rom_memory, PC_ROM_MIN_VGA,
hw/pc_piix.c +1 -1
@@ -130,7 +130,7 @@ static void pc_init1(MemoryRegion *system_memory, pci_enabled ? rom_memory : system_memory, &ram_memory); } - gsi_state =g_malloc0 (sizeof (*gsi_state)); + gsi_state =g_new0 (GSIState,1 ); gsi =qemu_allocate_irqs (gsi_handler, gsi_state,GSI_NUM_PINS );if (pci_enabled) {
hw/pci.c +2 -2
@@ -223,7 +223,7 @@ static int pcibus_reset(BusState *qbus)static void pci_host_bus_register (int domain,PCIBus *bus) {struct PCIHostBus *host; - host =g_malloc0 (sizeof (*host)); + host = g_new0(struct PCIHostBus, 1); host->domain = domain; host->bus = bus;QLIST_INSERT_HEAD (&host_buses, host, next);
@@ -288,7 +288,7 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name, {PCIBus *bus; - bus =g_malloc0 (sizeof (*bus)); + bus =g_new0 (PCIBus,1 ); bus->qbus.qdev_allocated =1 ;pci_bus_new_inplace (bus, parent, name, address_space_mem, address_space_io, devfn_min);
hw/pcie_port.c +1 -1
@@ -76,7 +76,7 @@ void pcie_chassis_create(uint8_t chassis_number)if (c) {return ; } - c =g_malloc0 (sizeof (*c)); + c = g_new0(struct PCIEChassis, 1); c->number = chassis_number;QLIST_INIT (&c->slots);QLIST_INSERT_HEAD (&chassis, c, next);
hw/ppc405_boards.c +2 -2
@@ -184,7 +184,7 @@ static void ref405ep_init (ram_addr_t ram_size,MemoryRegion *bios;MemoryRegion *sram =g_new (MemoryRegion,1 );ram_addr_t bdloc; -MemoryRegion *ram_memories =g_malloc (2 *sizeof (*ram_memories)); +MemoryRegion *ram_memories =g_new (MemoryRegion,2 );target_phys_addr_t ram_bases[2 ], ram_sizes[2 ];target_ulong sram_size;long bios_size;
@@ -503,7 +503,7 @@ static void taihu_405ep_init(ram_addr_t ram_size,qemu_irq *pic;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *bios; -MemoryRegion *ram_memories =g_malloc (2 *sizeof (*ram_memories)); +MemoryRegion *ram_memories =g_new (MemoryRegion,2 );target_phys_addr_t ram_bases[2 ], ram_sizes[2 ];long bios_size;target_ulong kernel_base, initrd_base;
hw/ppc440.c +1 -2
@@ -38,8 +38,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size, PCIBus **pcip, const unsigned int pci_irq_nrs[4], int do_init, const char *cpu_model) { - MemoryRegion *ram_memories - =g_malloc (PPC440EP_SDRAM_NR_BANKS *sizeof (*ram_memories)); + MemoryRegion *ram_memories = g_new(MemoryRegion, PPC440EP_SDRAM_NR_BANKS);target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS ];target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS ];CPUState *env;
hw/qdev-properties.c +1 -1
@@ -799,7 +799,7 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque) {GlobalProperty *g; - g =g_malloc0 (sizeof (*g)); + g =g_new0 (GlobalProperty,1 ); g->driver =qemu_opt_get (opts,"driver" ); g->property =qemu_opt_get (opts,"property" ); g->value =qemu_opt_get (opts,"value" );
hw/spapr.c +1 -1
@@ -330,7 +330,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,long pteg_shift =17 ;char *filename; - spapr =g_malloc (sizeof (*spapr)); + spapr =g_new (sPAPREnvironment,1 ); cpu_ppc_hypercall = emulate_spapr_hypercall;/* We place the device tree just below either the top of RAM, or
hw/sysbus.c +1 -1
@@ -166,7 +166,7 @@ void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init) {SysBusDeviceInfo *info; - info =g_malloc0 (sizeof (*info)); + info =g_new0 (SysBusDeviceInfo,1 ); info->qdev.name =g_strdup (name); info->qdev.size = size; info->init = init;
hw/usb-desc.c +1 -1
@@ -283,7 +283,7 @@ void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str) } }if (s ==NULL ) { - s =g_malloc0 (sizeof (*s)); + s =g_new0 (USBDescString,1 ); s->index = index;QLIST_INSERT_HEAD (&dev->strings, s, next); }
hw/usb-ehci.c +1 -1
@@ -660,7 +660,7 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, int async) {EHCIQueue *q; - q =g_malloc0 (sizeof (*q)); + q =g_new0 (EHCIQueue,1 ); q->ehci = ehci; q->async_schedule = async;QTAILQ_INSERT_HEAD (&ehci->queues, q, next);
hw/usb-musb.c +1 -1
@@ -374,7 +374,7 @@ void musb_reset(MUSBState *s)struct MUSBState *musb_init (DeviceState *parent_device,int gpio_base) { -MUSBState *s =g_malloc0 (sizeof (*s)); +MUSBState *s =g_new0 (MUSBState,1 );int i;for (i =0 ; i < musb_irq_max; i++) {
hw/vga-isa-mm.c +3 -3
@@ -102,11 +102,11 @@ static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,MemoryRegion *s_ioport_ctrl, *vga_io_memory; s->it_shift = it_shift; - s_ioport_ctrl =g_malloc (sizeof (*s_ioport_ctrl)); + s_ioport_ctrl =g_new (MemoryRegion,1 );memory_region_init_io (s_ioport_ctrl, &vga_mm_ctrl_ops, s,"vga-mm-ctrl" ,0x100000 ); - vga_io_memory =g_malloc (sizeof (*vga_io_memory)); + vga_io_memory =g_new (MemoryRegion,1 );/* XXX: endianness? */ memory_region_init_io (vga_io_memory, &vga_mem_ops, &s->vga,"vga-mem" ,0x20000 );
@@ -126,7 +126,7 @@ int isa_vga_mm_init(target_phys_addr_t vram_base, {ISAVGAMMState *s; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (ISAVGAMMState,1 );vga_common_init (&s->vga,VGA_RAM_SIZE );vga_mm_init (s, vram_base, ctrl_base, it_shift, address_space);
hw/vga.c +2 -2
@@ -182,7 +182,7 @@ static void vga_update_memory_access(VGACommonState *s)break ; } base += isa_mem_base; - region =g_malloc (sizeof (*region)); + region =g_new (MemoryRegion,1 );memory_region_init_alias (region,"vga.chain4" , &s->vram, offset, size);memory_region_add_subregion_overlap (s->legacy_address_space, base, region,2 );
@@ -2279,7 +2279,7 @@ MemoryRegion *vga_init_io(VGACommonState *s, *vbe_ports = vbe_portio_list;#endif - vga_mem =g_malloc (sizeof (*vga_mem)); + vga_mem =g_new (MemoryRegion,1 );memory_region_init_io (vga_mem, &vga_mem_ops, s,"vga-lowmem" ,0x20000 );
hw/vhost.c +1 -1
@@ -252,7 +252,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)uint64_t log_base;int r;if (size) { - log =g_malloc0 (size *sizeof *log); + log =g_new0 (vhost_log_chunk_t, size); }else { log =NULL ; }
hw/vhost_net.c +1 -1
@@ -92,7 +92,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, int devfd, bool force) {int r; -struct vhost_net *net =g_malloc (sizeof *net); + struct vhost_net *net = g_new(struct vhost_net, 1);if (!backend) {fprintf (stderr,"vhost-net requires backend to be setup\n" ); goto fail;
hw/virtio-blk.c +1 -1
@@ -123,7 +123,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)static VirtIOBlockReq *virtio_blk_alloc_request (VirtIOBlock *s) { -VirtIOBlockReq *req =g_malloc (sizeof (*req)); +VirtIOBlockReq *req =g_new (VirtIOBlockReq,1 ); req->dev = s; req->qiov.size =0 ; req->next =NULL ;
hw/xen_devconfig.c +1 -1
@@ -14,7 +14,7 @@ static void xen_config_cleanup_dir(char *dir) {struct xs_dirs *d; - d =g_malloc (sizeof (*d)); + d = g_new(struct xs_dirs, 1); d->xs_dir = dir;QTAILQ_INSERT_TAIL (&xs_cleanup, d, list); }
hw/xen_disk.c +1 -1
@@ -125,7 +125,7 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev) goto out; }/* allocate new struct */ - ioreq =g_malloc0 (sizeof (*ioreq)); + ioreq = g_new0(struct ioreq, 1); ioreq->blkdev = blkdev; blkdev->requests_total++;qemu_iovec_init (&ioreq->v,BLKIF_MAX_SEGMENTS_PER_REQUEST );
hw/xics.c +2 -2
@@ -437,7 +437,7 @@ struct icp_state *xics_system_init(int nr_irqs) } } - icp =g_malloc0 (sizeof (*icp)); + icp = g_new0(struct icp_state, 1); icp->nr_servers = max_server_num +1 ; icp->ss =g_malloc0 (icp->nr_servers*sizeof (struct icp_server_state ));
@@ -464,7 +464,7 @@ struct icp_state *xics_system_init(int nr_irqs) } } - ics =g_malloc0 (sizeof (*ics)); + ics = g_new0(struct ics_state, 1); ics->nr_irqs = nr_irqs; ics->offset =16 ; ics->irqs =g_malloc0 (nr_irqs *sizeof (struct ics_irq_state ));
hw/xtensa_lx60.c +4 -4
@@ -127,7 +127,7 @@ static void lx60_net_init(MemoryRegion *address_space,memory_region_add_subregion (address_space, descriptors,sysbus_mmio_get_region (s,1 )); - ram =g_malloc (sizeof (*ram)); + ram =g_new (MemoryRegion,1 );memory_region_init_ram (ram,NULL ,"open_eth.ram" ,16384 );memory_region_add_subregion (address_space, buffers, ram); }
@@ -171,15 +171,15 @@ static void lx60_init(ram_addr_t ram_size,cpu_reset (env); } - ram =g_malloc (sizeof (*ram)); + ram =g_new (MemoryRegion,1 );memory_region_init_ram (ram,NULL ,"xtensa.sram" , ram_size);memory_region_add_subregion (system_memory,0 , ram); - rom =g_malloc (sizeof (*rom)); + rom =g_new (MemoryRegion,1 );memory_region_init_ram (rom,NULL ,"xtensa.rom" ,0x1000 );memory_region_add_subregion (system_memory,0xfe000000 , rom); - system_io =g_malloc (sizeof (*system_io)); + system_io =g_new (MemoryRegion,1 );memory_region_init (system_io,"system.io" ,224 *1024 *1024 );memory_region_add_subregion (system_memory,0xf0000000 , system_io);lx60_fpga_init (system_io,0x0d020000 );
hw/xtensa_sim.c +2 -2
@@ -65,11 +65,11 @@ static void sim_init(ram_addr_t ram_size,sim_reset (env); } - ram =g_malloc (sizeof (*ram)); + ram =g_new (MemoryRegion,1 );memory_region_init_ram (ram,NULL ,"xtensa.sram" , ram_size);memory_region_add_subregion (get_system_memory (),0 , ram); - rom =g_malloc (sizeof (*rom)); + rom =g_new (MemoryRegion,1 );memory_region_init_ram (rom,NULL ,"xtensa.rom" ,0x1000 );memory_region_add_subregion (get_system_memory (),0xfe000000 , rom);
linux-aio.c +1 -1
@@ -207,7 +207,7 @@ void *laio_init(void) {struct qemu_laio_state *s; - s =g_malloc0 (sizeof (*s)); + s = g_new0(struct qemu_laio_state, 1); s->efd =eventfd (0 ,0 );if (s->efd ==-1 ) goto out_free_state;
linux-user/elfload.c +3 -3
@@ -2115,7 +2115,7 @@ static struct mm_struct *vma_init(void) {struct mm_struct *mm; -if ((mm =g_malloc (sizeof (*mm))) ==NULL ) + if ((mm = g_new(struct mm_struct, 1)) == NULL)return (NULL ); mm->mm_count =0 ;
@@ -2140,7 +2140,7 @@ static int vma_add_mapping(struct mm_struct *mm, abi_ulong start, {struct vm_area_struct *vma; -if ((vma =g_malloc0 (sizeof (*vma))) ==NULL ) + if ((vma = g_new0(struct vm_area_struct, 1)) == NULL)return (-1 ); vma->vma_start = start;
@@ -2464,7 +2464,7 @@ static void fill_thread_info(struct elf_note_info *info, const CPUState *env)TaskState *ts = (TaskState *)env->opaque;struct elf_thread_status *ets; - ets =g_malloc0 (sizeof (*ets)); + ets = g_new0(struct elf_thread_status, 1); ets->num_notes =1 ;/* only prstatus is dumped */ fill_prstatus (&ets->prstatus, ts,0 );elf_core_copy_regs (&ets->prstatus.pr_reg, env);
memory.c +1 -1
@@ -1123,7 +1123,7 @@ void memory_region_add_coalescing(MemoryRegion *mr, target_phys_addr_t offset, uint64_t size) { -CoalescedMemoryRange *cmr =g_malloc (sizeof (*cmr)); +CoalescedMemoryRange *cmr =g_new (CoalescedMemoryRange,1 ); cmr->addr =addrrange_make (offset, size);QTAILQ_INSERT_TAIL (&mr->coalesced, cmr, link);
migration-exec.c +1 -1
@@ -71,7 +71,7 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,FdMigrationState *s;FILE *f; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (FdMigrationState,1 ); f =popen (command,"w" );if (f ==NULL ) {
migration-fd.c +1 -1
@@ -59,7 +59,7 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon, {FdMigrationState *s; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (FdMigrationState,1 ); s->fd =monitor_get_fd (mon, fdname);if (s->fd ==-1 ) {
migration-tcp.c +1 -1
@@ -89,7 +89,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,if (parse_host_port (&addr, host_port) <0 )return NULL ; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (FdMigrationState,1 ); s->get_error = socket_errno; s->write = socket_write;
migration-unix.c +1 -1
@@ -88,7 +88,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon, addr.sun_family =AF_UNIX ;snprintf (addr.sun_path,sizeof (addr.sun_path),"%s" , path); - s =g_malloc0 (sizeof (*s)); + s =g_new0 (FdMigrationState,1 ); s->get_error = unix_errno; s->write = unix_write;
module.c +1 -1
@@ -59,7 +59,7 @@ void register_module_init(void (*fn)(void), module_init_type type)ModuleEntry *e;ModuleTypeList *l; - e =g_malloc0 (sizeof (*e)); + e =g_new0 (ModuleEntry,1 ); e->init = fn; l =find_type (type);
monitor.c +5 -5
@@ -674,7 +674,7 @@ static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, {int ret; -MonitorCompletionData *cb_data =g_malloc (sizeof (*cb_data)); +MonitorCompletionData *cb_data =g_new (MonitorCompletionData,1 ); cb_data->mon = mon; cb_data->user_print = cmd->user_print;monitor_suspend (mon);
@@ -690,7 +690,7 @@ static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd) {int ret; -MonitorCompletionData *cb_data =g_malloc (sizeof (*cb_data)); +MonitorCompletionData *cb_data =g_new (MonitorCompletionData,1 ); cb_data->mon = mon; cb_data->user_print = cmd->user_print;monitor_suspend (mon);
@@ -743,7 +743,7 @@ static CommandInfoList *alloc_cmd_entry(const char *cmd_name) {CommandInfoList *info; - info =g_malloc0 (sizeof (*info)); + info =g_new0 (CommandInfoList,1 ); info->value =g_malloc0 (sizeof (*info->value)); info->value->name =g_strdup (cmd_name);
@@ -2480,7 +2480,7 @@ static void do_wav_capture(Monitor *mon, const QDict *qdict)int nchannels =qdict_get_try_int (qdict,"nchannels" ,-1 );CaptureState *s; - s =g_malloc0 (sizeof (*s)); + s =g_new0 (CaptureState,1 ); freq = has_freq ? freq :44100 ; bits = has_bits ? bits :16 ;
@@ -5114,7 +5114,7 @@ void monitor_init(CharDriverState *chr, int flags) is_first_init =0 ; } - mon =g_malloc0 (sizeof (*mon)); + mon =g_new0 (Monitor,1 ); mon->chr = chr; mon->flags = flags;
net/slirp.c +3 -3
@@ -450,7 +450,7 @@ int net_slirp_redir(const char *redir_str)struct slirp_config_str *config;if (QTAILQ_EMPTY (&slirp_stacks)) { - config =g_malloc (sizeof (*config)); + config = g_new(struct slirp_config_str, 1);pstrcpy (config->str,sizeof (config->str), redir_str); config->flags =SLIRP_CFG_HOSTFWD |SLIRP_CFG_LEGACY ; config->next = slirp_configs;
@@ -662,7 +662,7 @@ static int net_init_slirp_configs(const char *name, const char *value, void *opareturn 0 ; } - config =g_malloc0 (sizeof (*config)); + config = g_new0(struct slirp_config_str, 1);pstrcpy (config->str,sizeof (config->str), value);
@@ -764,7 +764,7 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *retif (QTAILQ_EMPTY (&slirp_stacks)) {struct slirp_config_str *config; - config =g_malloc (sizeof (*config)); + config = g_new(struct slirp_config_str, 1);pstrcpy (config->str,sizeof (config->str), optarg); config->flags =SLIRP_CFG_LEGACY ; config->next = slirp_configs;
qapi/qapi-dealloc-visitor.c +2 -2
@@ -37,7 +37,7 @@ static QapiDeallocVisitor *to_qov(Visitor *v)static void qapi_dealloc_push (QapiDeallocVisitor *qov,void *value) { -StackEntry *e =g_malloc0 (sizeof (*e)); +StackEntry *e =g_new0 (StackEntry,1 ); e->value = value;
@@ -152,7 +152,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) {QapiDeallocVisitor *v; - v =g_malloc0 (sizeof (*v)); + v =g_new0 (QapiDeallocVisitor,1 ); v->visitor.start_struct = qapi_dealloc_start_struct; v->visitor.end_struct = qapi_dealloc_end_struct;
qapi/qmp-input-visitor.c +2 -2
@@ -135,7 +135,7 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list,return NULL ; } - entry =g_malloc0 (sizeof (*entry)); + entry =g_new0 (GenericList,1 );if (*list) { so->entry =qlist_next (so->entry);if (so->entry ==NULL ) {
@@ -279,7 +279,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) {QmpInputVisitor *v; - v =g_malloc0 (sizeof (*v)); + v =g_new0 (QmpInputVisitor,1 ); v->visitor.start_struct = qmp_input_start_struct; v->visitor.end_struct = qmp_input_end_struct;
qapi/qmp-output-visitor.c +2 -2
@@ -43,7 +43,7 @@ static QmpOutputVisitor *to_qov(Visitor *v)static void qmp_output_push_obj (QmpOutputVisitor *qov,QObject *value) { -QStackEntry *e =g_malloc0 (sizeof (*e)); +QStackEntry *e =g_new0 (QStackEntry,1 ); e->value = value;if (qobject_type (e->value) ==QTYPE_QLIST ) {
@@ -232,7 +232,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void) {QmpOutputVisitor *v; - v =g_malloc0 (sizeof (*v)); + v =g_new0 (QmpOutputVisitor,1 ); v->visitor.start_struct = qmp_output_start_struct; v->visitor.end_struct = qmp_output_end_struct;
qapi/qmp-registry.c +1 -1
@@ -19,7 +19,7 @@ static QTAILQ_HEAD(, QmpCommand) qmp_commands =void qmp_register_command (const char *name,QmpCommandFunc *fn) { -QmpCommand *cmd =g_malloc0 (sizeof (*cmd)); +QmpCommand *cmd =g_new0 (QmpCommand,1 ); cmd->name = name; cmd->type =QCT_NORMAL ;
qbool.c +1 -1
@@ -31,7 +31,7 @@ QBool *qbool_from_int(int value) {QBool *qb; - qb =g_malloc (sizeof (*qb)); + qb =g_new (QBool,1 ); qb->value = value;QOBJECT_INIT (qb, &qbool_type);
qdict.c +2 -2
@@ -35,7 +35,7 @@ QDict *qdict_new(void) {QDict *qdict; - qdict =g_malloc0 (sizeof (*qdict)); + qdict =g_new0 (QDict,1 );QOBJECT_INIT (qdict, &qdict_type);return qdict;
@@ -75,7 +75,7 @@ static QDictEntry *alloc_entry(const char *key, QObject *value) {QDictEntry *entry; - entry =g_malloc0 (sizeof (*entry)); + entry =g_new0 (QDictEntry,1 ); entry->key =g_strdup (key); entry->value = value;
qemu-char.c +2 -2
@@ -2348,7 +2348,7 @@ void qemu_chr_init_mem(CharDriverState *chr) {MemoryDriver *d; - d =g_malloc (sizeof (*d)); + d =g_new (MemoryDriver,1 ); d->outbuf_size =0 ; d->outbuf_capacity =4096 ; d->outbuf =g_malloc0 (d->outbuf_capacity);
@@ -2656,7 +2656,7 @@ ChardevInfoList *qmp_query_chardev(Error **errp)CharDriverState *chr; QTAILQ_FOREACH(chr, &chardevs, next) { -ChardevInfoList *info =g_malloc0 (sizeof (*info)); +ChardevInfoList *info =g_new0 (ChardevInfoList,1 ); info->value =g_malloc0 (sizeof (*info->value)); info->value->label =g_strdup (chr->label); info->value->filename =g_strdup (chr->filename);
qemu-io.c +3 -3
@@ -950,9 +950,9 @@ static int multiwrite_f(int argc, char **argv) } } - reqs =g_malloc (nr_reqs *sizeof (*reqs)); - buf =g_malloc (nr_reqs *sizeof (*buf)); - qiovs =g_malloc (nr_reqs *sizeof (*qiovs)); + reqs =g_new (BlockRequest, nr_reqs); + buf = g_new(char *, nr_reqs); + qiovs =g_new (QEMUIOVector, nr_reqs);for (i =0 ; i < nr_reqs; i++) {int j;
qemu-option.c +2 -2
@@ -619,7 +619,7 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) } } - opt =g_malloc0 (sizeof (*opt)); + opt =g_new0 (QemuOpt,1 ); opt->name =g_strdup (name); opt->opts = opts;QTAILQ_INSERT_TAIL (&opts->head, opt, next);
@@ -701,7 +701,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist } } } - opts =g_malloc0 (sizeof (*opts)); + opts =g_new0 (QemuOpts,1 );if (id) { opts->id =g_strdup (id); }
qemu-thread-win32.c +1 -1
@@ -249,7 +249,7 @@ void qemu_thread_create(QemuThread *thread,struct QemuThreadData *data;qemu_thread_init (); - data =g_malloc (sizeof *data); + data = g_new(struct QemuThreadData, 1); data->thread = thread; data->start_routine = start_routine; data->arg = arg;
qerror.c +1 -1
@@ -246,7 +246,7 @@ QError *qerror_new(void) {QError *qerr; - qerr =g_malloc0 (sizeof (*qerr)); + qerr =g_new0 (QError,1 );QOBJECT_INIT (qerr, &qerror_type);return qerr;
qfloat.c +1 -1
@@ -31,7 +31,7 @@ QFloat *qfloat_from_double(double value) {QFloat *qf; - qf =g_malloc (sizeof (*qf)); + qf =g_new (QFloat,1 ); qf->value = value;QOBJECT_INIT (qf, &qfloat_type);
qint.c +1 -1
@@ -30,7 +30,7 @@ QInt *qint_from_int(int64_t value) {QInt *qi; - qi =g_malloc (sizeof (*qi)); + qi =g_new (QInt,1 ); qi->value = value;QOBJECT_INIT (qi, &qint_type);
qlist.c +2 -2
@@ -31,7 +31,7 @@ QList *qlist_new(void) {QList *qlist; - qlist =g_malloc (sizeof (*qlist)); + qlist =g_new (QList,1 );QTAILQ_INIT (&qlist->head);QOBJECT_INIT (qlist, &qlist_type);
@@ -64,7 +64,7 @@ void qlist_append_obj(QList *qlist, QObject *value) {QListEntry *entry; - entry =g_malloc (sizeof (*entry)); + entry =g_new (QListEntry,1 ); entry->value = value;QTAILQ_INSERT_TAIL (&qlist->head, entry, next);
qmp.c +4 -4
@@ -19,7 +19,7 @@NameInfo *qmp_query_name (Error **errp) { -NameInfo *info =g_malloc0 (sizeof (*info)); +NameInfo *info =g_new0 (NameInfo,1 );if (qemu_name) { info->has_name = true;
@@ -31,7 +31,7 @@ NameInfo *qmp_query_name(Error **errp)VersionInfo *qmp_query_version (Error **err) { -VersionInfo *info =g_malloc0 (sizeof (*info)); +VersionInfo *info =g_new0 (VersionInfo,1 );const char *version =QEMU_VERSION ;char *tmp;
@@ -47,7 +47,7 @@ VersionInfo *qmp_query_version(Error **err)KvmInfo *qmp_query_kvm (Error **errp) { -KvmInfo *info =g_malloc0 (sizeof (*info)); +KvmInfo *info =g_new0 (KvmInfo,1 ); info->enabled =kvm_enabled (); info->present =kvm_available ();
@@ -57,7 +57,7 @@ KvmInfo *qmp_query_kvm(Error **errp)UuidInfo *qmp_query_uuid (Error **errp) { -UuidInfo *info =g_malloc0 (sizeof (*info)); +UuidInfo *info =g_new0 (UuidInfo,1 );char uuid[64 ]; snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
qstring.c +1 -1
@@ -40,7 +40,7 @@ QString *qstring_from_substr(const char *str, int start, int end) {QString *qstring; - qstring =g_malloc (sizeof (*qstring)); + qstring =g_new (QString,1 ); qstring->length = end - start +1 ; qstring->capacity = qstring->length;
readline.c +1 -1
@@ -466,7 +466,7 @@ const char *readline_get_history(ReadLineState *rs, unsigned int index)ReadLineState *readline_init (Monitor *mon,ReadLineCompletionFunc *completion_finder) { -ReadLineState *rs =g_malloc0 (sizeof (*rs)); +ReadLineState *rs =g_new0 (ReadLineState,1 ); rs->hist_entry =-1 ; rs->mon = mon;
target-xtensa/helper.c +1 -1
@@ -74,7 +74,7 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model)return NULL ; } - env =g_malloc0 (sizeof (*env)); + env =g_new0 (CPUXtensaState,1 ); env->config = config;cpu_exec_init (env);
ui/keymaps.c +1 -1
@@ -52,7 +52,7 @@ static void add_to_key_range(struct key_range **krp, int code) { } }if (kr ==NULL ) { - kr =g_malloc0 (sizeof (*kr)); + kr = g_new0(struct key_range, 1); kr->start = kr->end = code; kr->next = *krp; *krp = kr;
ui/spice-core.c +3 -3
@@ -57,7 +57,7 @@ static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque) {SpiceTimer *timer; - timer =g_malloc0 (sizeof (*timer)); + timer =g_new0 (SpiceTimer,1 ); timer->timer =qemu_new_timer_ms (rt_clock, func, opaque);QTAILQ_INSERT_TAIL (&timers, timer, next);return timer;
@@ -121,7 +121,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void * {SpiceWatch *watch; - watch =g_malloc0 (sizeof (*watch)); + watch =g_new0 (SpiceWatch,1 ); watch->fd = fd; watch->func = func; watch->opaque = opaque;
@@ -151,7 +151,7 @@ static void channel_list_add(SpiceChannelEventInfo *info) {ChannelList *item; - item =g_malloc0 (sizeof (*item)); + item =g_new0 (ChannelList,1 ); item->info = info;QTAILQ_INSERT_TAIL (&channel_list, item, link); }
ui/spice-display.c +1 -1
@@ -142,7 +142,7 @@ static SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd) ssd->dirty.left, ssd->dirty.right, ssd->dirty.top, ssd->dirty.bottom); - update =g_malloc0 (sizeof (*update)); + update =g_new0 (SimpleSpiceUpdate,1 ); drawable = &update->drawable; image = &update->image; cmd = &update->ext.cmd;
ui/spice-input.c +2 -2
@@ -200,12 +200,12 @@ void qemu_spice_input_init(void)QemuSpiceKbd *kbd;QemuSpicePointer *pointer; - kbd =g_malloc0 (sizeof (*kbd)); + kbd =g_new0 (QemuSpiceKbd,1 ); kbd->sin.base.sif = &kbd_interface.base;qemu_spice_add_interface (&kbd->sin.base);qemu_add_led_event_handler (kbd_leds, kbd); - pointer =g_malloc0 (sizeof (*pointer)); + pointer =g_new0 (QemuSpicePointer,1 ); pointer->mouse.base.sif = &mouse_interface.base; pointer->tablet.base.sif = &tablet_interface.base;qemu_spice_add_interface (&pointer->mouse.base);
ui/vnc-palette.c +1 -1
@@ -55,7 +55,7 @@ VncPalette *palette_new(size_t max, int bpp) {VncPalette *palette; - palette =g_malloc0 (sizeof (*palette)); + palette =g_new0 (VncPalette,1 );palette_init (palette, max, bpp);return palette; }
ui/vnc.c +1 -1
@@ -2576,7 +2576,7 @@ static void vnc_listen_read(void *opaque)void vnc_display_init (DisplayState *ds) { -VncDisplay *vs =g_malloc0 (sizeof (*vs)); +VncDisplay *vs =g_new0 (VncDisplay,1 ); dcl =g_malloc0 (sizeof (DisplayChangeListener));
usb-linux.c +1 -1
@@ -632,7 +632,7 @@ static AsyncURB *usb_host_alloc_iso(USBHostDevice *s, int pid, uint8_t ep)AsyncURB *aurb;int i, j, len =get_max_packet_size (s, pid, ep); - aurb =g_malloc0 (s->iso_urb_count *sizeof (*aurb)); + aurb =g_new0 (AsyncURB, s->iso_urb_count);for (i =0 ; i < s->iso_urb_count; i++) { aurb[i].urb.endpoint = ep; aurb[i].urb.buffer_length =ISO_FRAME_DESC_PER_URB * len;
vl.c +2 -2
@@ -409,7 +409,7 @@ int runstate_is_running(void)StatusInfo *qmp_query_status (Error **errp) { -StatusInfo *info =g_malloc0 (sizeof (*info)); +StatusInfo *info =g_new0 (StatusInfo,1 ); info->running =runstate_is_running (); info->singlestep = singlestep;
@@ -1958,7 +1958,7 @@ static void add_device_config(int type, const char *cmdline) {struct device_config *conf; - conf =g_malloc0 (sizeof (*conf)); + conf = g_new0(struct device_config, 1); conf->type = type; conf->cmdline = cmdline;QTAILQ_INSERT_TAIL (&device_configs, conf, next);
xen-all.c +2 -2
@@ -140,7 +140,7 @@ static void xen_ram_init(ram_addr_t ram_size)RAMBlock *new_block;ram_addr_t below_4g_mem_size, above_4g_mem_size =0 ; - new_block =g_malloc0 (sizeof (*new_block)); + new_block =g_new0 (RAMBlock,1 );pstrcpy (new_block->idstr,sizeof (new_block->idstr),"xen.ram" ); new_block->host =NULL ; new_block->offset =0 ;
@@ -190,7 +190,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)trace_xen_ram_alloc (ram_addr, size); nr_pfn = size >>TARGET_PAGE_BITS ; - pfn_list =g_malloc (sizeof (*pfn_list) * nr_pfn); + pfn_list =g_new (xen_pfn_t, nr_pfn);for (i =0 ; i < nr_pfn; i++) { pfn_list[i] = (ram_addr >>TARGET_PAGE_BITS ) + i;
Signature · 1 line
1.7.4.1
PATCH 3/5 Convert use of ptr = g_malloc(sizeof(type)) to g_new()
In reply to Stuart BradyConvert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the size passed to g_malloc() is specified in terms of sizeof(type) where the result is assigned to a variable of the same type.
This was achieved using Coccinelle with the following semantic patch:
@@ type T; T *E; @@
-E = g_malloc(sizeof(T))
+E = g_new(T, 1)
@@ type T; T *E; @@
-E = g_malloc0(sizeof(T))
+E = g_new0(T, 1)
@@ type T; T *E; expression N; @@
-E = g_malloc(sizeof(T) * N)
+E = g_new(T, N)
@@ type T; T *E; expression N; @@
-E = g_malloc0(sizeof(T) * N)
+E = g_new0(T, N)
--- aio.c | 2 +- async.c | 2 +- block-migration.c | 6 ++-- block.c | 2 +- block/qcow.c | 4 +- block/qcow2-cluster.c | 2 +- block/qcow2-refcount.c | 4 +- block/qcow2-snapshot.c | 6 ++-- block/rbd.c | 4 +- block/sheepdog.c | 2 +- block/vdi.c | 2 +- block/vmdk.c | 3 +- bt-host.c | 2 +- bt-vhci.c | 2 +- console.c | 8 +++--- cutils.c | 2 +- exec.c | 10 ++++---- gdbstub.c | 4 +- hw/9pfs/virtio-9p-handle.c | 2 +- hw/9pfs/virtio-9p.c | 6 ++-- hw/adb.c | 4 +- hw/applesmc.c | 2 +- hw/baum.c | 4 +- hw/bitbang_i2c.c | 2 +- hw/blizzard.c | 3 +- hw/bt-hci.c | 4 +- hw/bt-l2cap.c | 4 +- hw/bt.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dp8393x.c | 2 +- hw/heathrow_pic.c | 2 +- hw/i8259.c | 2 +- hw/ide/macio.c | 2 +- hw/ide/mmio.c | 2 +- hw/irq.c | 2 +- hw/ivshmem.c | 6 ++-- hw/jazz_led.c | 2 +- hw/leon3.c | 2 +- hw/lm32_boards.c | 4 +- hw/lm32_hwsetup.h | 2 +- hw/mac_dbdma.c | 2 +- hw/mac_nvram.c | 2 +- hw/mcf_intc.c | 2 +- hw/mcf_uart.c | 2 +- hw/milkymist.c | 2 +- hw/mips_mipssim.c | 2 +- hw/mips_r4k.c | 2 +- hw/msmouse.c | 2 +- hw/omap.h | 2 +- hw/omap_gpio.c | 4 +- hw/omap_l4.c | 2 +- hw/parallel.c | 2 +- hw/pckbd.c | 2 +- hw/pflash_cfi01.c | 2 +- hw/pflash_cfi02.c | 2 +- hw/ppc.c | 8 +++--- hw/ppc405_boards.c | 4 +- hw/ppc405_uc.c | 28 +++++++++++++------------- hw/ppc440.c | 4 +- hw/ppc4xx_devs.c | 4 +- hw/ppc4xx_pci.c | 2 +- hw/ppc_booke.c | 4 +- hw/ppc_newworld.c | 2 +- hw/ppc_oldworld.c | 2 +- hw/ppc_prep.c | 2 +- hw/ppce500_mpc8544ds.c | 4 +- hw/prep_pci.c | 2 +- hw/pxa2xx_dma.c | 2 +- hw/qxl.c | 2 +- hw/r2d.c | 4 +- hw/rc4030.c | 2 +- hw/s390-virtio.c | 2 +- hw/serial.c | 4 +- hw/sh7750.c | 2 +- hw/sh_serial.c | 2 +- hw/slavio_timer.c | 2 +- hw/strongarm.c | 2 +- hw/sun4u.c | 4 +- hw/syborg_interrupt.c | 2 +- hw/usb-uhci.c | 2 +- hw/vga.c | 2 +- hw/virtex_ml507.c | 2 +- hw/xenfb.c | 4 +- hw/xics.c | 4 +- hw/xtensa_lx60.c | 2 +- input.c | 4 +- iohandler.c | 4 +- kvm-all.c | 4 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- monitor.c | 2 +- net.c | 2 +- net/queue.c | 2 +- net/slirp.c | 2 +- net/socket.c | 2 +- os-win32.c | 2 +- pflib.c | 2 +- posix-aio-compat.c | 2 +- qemu-char.c | 40 +++++++++++++++++++------------------- qemu-ga.c | 2 +- qemu-img.c | 2 +- qemu-nbd.c | 2 +- qemu-timer.c | 4 +- qga/guest-agent-command-state.c | 4 +- qga/guest-agent-commands.c | 10 ++++---- savevm.c | 16 +++++++------- slirp/slirp.c | 2 +- spice-qemu-char.c | 4 +- target-alpha/translate.c | 2 +- target-arm/helper.c | 2 +- target-cris/translate.c | 2 +- target-i386/cpuid.c | 2 +- target-i386/helper.c | 2 +- target-i386/kvm.c | 2 +- target-lm32/helper.c | 2 +- target-m68k/helper.c | 2 +- target-microblaze/translate.c | 2 +- target-mips/translate.c | 2 +- target-ppc/helper.c | 2 +- target-s390x/helper.c | 2 +- target-sh4/translate.c | 2 +- target-sparc/helper.c | 2 +- target-unicore32/helper.c | 2 +- tcg/tcg.c | 4 +- test-qmp-commands.c | 14 ++++++------ test-visitor.c | 2 +- ui/keymaps.c | 2 +- ui/sdl.c | 4 +- ui/vnc-jobs-async.c | 6 ++-- ui/vnc.c | 4 +- usb-linux.c | 2 +- usb-redir.c | 2 +- vl.c | 8 +++--- xen-all.c | 4 +- xen-mapcache.c | 10 ++++---- 135 files changed, 241 insertions(+), 243 deletions(-)
aio.c +1 -1
@@ -81,7 +81,7 @@ int qemu_aio_set_fd_handler(int fd, }else {if (node ==NULL ) {/* Alloc and insert if it's not already there */ - node =g_malloc0 (sizeof (AioHandler)); + node =g_new0 (AioHandler,1 ); node->fd = fd;QLIST_INSERT_HEAD (&aio_handlers, node, node); }
async.c +1 -1
@@ -43,7 +43,7 @@ struct QEMUBH {QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque) {QEMUBH *bh; - bh =g_malloc0 (sizeof (QEMUBH )); + bh =g_new0 (QEMUBH ,1 ); bh->cb = cb; bh->opaque = opaque; bh->next = first_bh;
block-migration.c +3 -3
@@ -235,7 +235,7 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f, nr_sectors = total_sectors - cur_sector; } - blk =g_malloc (sizeof (BlkMigBlock)); + blk =g_new (BlkMigBlock,1 ); blk->buf =g_malloc (BLOCK_SIZE ); blk->bmds = bmds; blk->sector = cur_sector;
@@ -290,7 +290,7 @@ static void init_blk_migration_it(void *opaque, BlockDriverState *bs)return ; } - bmds =g_malloc0 (sizeof (BlkMigDevState)); + bmds =g_new0 (BlkMigDevState,1 ); bmds->bs = bs; bmds->bulk_completed =0 ; bmds->total_sectors = sectors;
@@ -395,7 +395,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f, }else { nr_sectors =BDRV_SECTORS_PER_DIRTY_CHUNK ; } - blk =g_malloc (sizeof (BlkMigBlock)); + blk =g_new (BlkMigBlock,1 ); blk->buf =g_malloc (BLOCK_SIZE ); blk->bmds = bmds; blk->sector = sector;
block.c +1 -1
@@ -214,7 +214,7 @@ BlockDriverState *bdrv_new(const char *device_name) {BlockDriverState *bs; - bs =g_malloc0 (sizeof (BlockDriverState)); + bs =g_new0 (BlockDriverState,1 );pstrcpy (bs->device_name,sizeof (bs->device_name), device_name);if (device_name[0 ] !='\0' ) {QTAILQ_INSERT_TAIL (&bdrv_states, bs, list);
block/qcow.c +2 -2
@@ -129,7 +129,7 @@ static int qcow_open(BlockDriverState *bs, int flags) s->l1_size = (header.size + (1LL << shift) -1 ) >> shift; s->l1_table_offset = header.l1_table_offset; - s->l1_table =g_malloc (s->l1_size *sizeof (uint64_t )); + s->l1_table =g_new (uint64_t, s->l1_size);if (!s->l1_table) goto fail; if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
@@ -139,7 +139,7 @@ static int qcow_open(BlockDriverState *bs, int flags)be64_to_cpus (&s->l1_table[i]); }/* alloc L2 cache */ - s->l2_cache =g_malloc (s->l2_size *L2_CACHE_SIZE *sizeof (uint64_t )); + s->l2_cache =g_new (uint64_t, s->l2_size *L2_CACHE_SIZE );if (!s->l2_cache) goto fail; s->cluster_cache =g_malloc (s->cluster_size);
block/qcow2-cluster.c +1 -1
@@ -612,7 +612,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)if (m->nb_clusters ==0 )return 0 ; - old_cluster =g_malloc (m->nb_clusters *sizeof (uint64_t )); + old_cluster =g_new (uint64_t, m->nb_clusters);/* copy content of unmodified sectors */ start_sect = (m->offset & ~(s->cluster_size -1 )) >>9 ;
block/qcow2-refcount.c +2 -2
@@ -324,7 +324,7 @@ static int alloc_refcount_block(BlockDriverState *bs, s->cluster_size;uint64_t table_offset = meta_offset + blocks_clusters * s->cluster_size;uint16_t *new_blocks =g_malloc0 (blocks_clusters * s->cluster_size); -uint64_t *new_table =g_malloc0 (table_size *sizeof (uint64_t )); +uint64_t *new_table =g_new0 (uint64_t, table_size);assert (meta_offset >= (s->free_cluster_index * s->cluster_size));
@@ -1074,7 +1074,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) size =bdrv_getlength (bs->file); nb_clusters =size_to_clusters (s, size); - refcount_table =g_malloc0 (nb_clusters *sizeof (uint16_t )); + refcount_table =g_new0 (uint16_t, nb_clusters);/* header */ inc_refcounts(bs, res, refcount_table, nb_clusters,
block/qcow2-snapshot.c +3 -3
@@ -278,7 +278,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->l1_size = s->l1_size;if (s->l1_size !=0 ) { - l1_table =g_malloc (s->l1_size *sizeof (uint64_t )); + l1_table =g_new (uint64_t, s->l1_size); }else { l1_table =NULL ; }
@@ -292,7 +292,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)g_free (l1_table); l1_table =NULL ; - snapshots1 =g_malloc ((s->nb_snapshots +1 ) *sizeof (QCowSnapshot)); + snapshots1 =g_new (QCowSnapshot, (s->nb_snapshots +1 ));if (s->snapshots) {memcpy (snapshots1, s->snapshots, s->nb_snapshots *sizeof (QCowSnapshot));g_free (s->snapshots);
@@ -416,7 +416,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)return s->nb_snapshots; } - sn_tab =g_malloc0 (s->nb_snapshots *sizeof (QEMUSnapshotInfo)); + sn_tab =g_new0 (QEMUSnapshotInfo, s->nb_snapshots);for (i =0 ; i < s->nb_snapshots; i++) { sn_info = sn_tab + i; sn = s->snapshots + i;
block/rbd.c +2 -2
@@ -655,7 +655,7 @@ static BlockDriverAIOCB *rbd_aio_rw_vector(BlockDriverState *bs, s->qemu_aio_count++;/* All the RADOSCB */ - rcb =g_malloc (sizeof (RADOSCB )); + rcb =g_new (RADOSCB ,1 ); rcb->done =0 ; rcb->acb = acb; rcb->buf = buf;
@@ -811,7 +811,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,return snap_count; } - sn_tab =g_malloc0 (snap_count *sizeof (QEMUSnapshotInfo)); + sn_tab =g_new0 (QEMUSnapshotInfo, snap_count);for (i =0 ; i < snap_count; i++) {const char *snap_name = snaps[i].name;
block/sheepdog.c +1 -1
@@ -1852,7 +1852,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)uint32_t snapid =0 ;int ret = -ENOENT , fd; - old_s =g_malloc (sizeof (BDRVSheepdogState)); + old_s =g_new (BDRVSheepdogState,1 );memcpy (old_s, s,sizeof (BDRVSheepdogState));
block/vdi.c +1 -1
@@ -301,7 +301,7 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res)uint32_t *bmap;logout ("\n" ); - bmap =g_malloc (s->header.blocks_in_image *sizeof (uint32_t )); + bmap =g_new (uint32_t, s->header.blocks_in_image);memset (bmap,0xff , s->header.blocks_in_image *sizeof (uint32_t ));/* Check block map and value of blocks_allocated. */
block/vmdk.c +1 -2
@@ -377,8 +377,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent) } } - extent->l2_cache = -g_malloc (extent->l2_size *L2_CACHE_SIZE *sizeof (uint32_t )); + extent->l2_cache =g_new (uint32_t, extent->l2_size *L2_CACHE_SIZE );return 0 ; fail_l1b:g_free (extent->l1_backup_table);
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;
console.c +4 -4
@@ -522,7 +522,7 @@ static void text_console_resize(TextConsole *s)if (s->width < w1) w1 = s->width; - cells =g_malloc (s->width * s->total_height *sizeof (TextCell)); + cells =g_new (TextCell, s->width * s->total_height);for (y =0 ; y < s->total_height; y++) { c = &cells[y * s->width];if (w1 >0 ) {
@@ -1243,7 +1243,7 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)if (nb_consoles >=MAX_CONSOLES )return NULL ; - s =g_malloc0 (sizeof (TextConsole)); + s =g_new0 (TextConsole,1 );if (!active_console || ((active_console->console_type !=GRAPHIC_CONSOLE ) && (console_type ==GRAPHIC_CONSOLE ))) { active_console = s;
@@ -1342,7 +1342,7 @@ static struct DisplayAllocator default_allocator = {static void dumb_display_init (void ) { -DisplayState *ds =g_malloc0 (sizeof (DisplayState)); +DisplayState *ds =g_new0 (DisplayState,1 );int width =640 ;int height =480 ;
@@ -1514,7 +1514,7 @@ int text_console_init(QemuOpts *opts, CharDriverState **_chr)unsigned width;unsigned height; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 );if (n_text_consoles ==128 ) {fprintf (stderr,"Too many text consoles\n" );
cutils.c +1 -1
@@ -136,7 +136,7 @@ int qemu_fdatasync(int fd)void qemu_iovec_init (QEMUIOVector *qiov,int alloc_hint) { - qiov->iov =g_malloc (alloc_hint *sizeof (struct iovec )); + qiov->iov = g_new(struct iovec, alloc_hint); qiov->niov =0 ; qiov->nalloc = alloc_hint; qiov->size =0 ;
exec.c +5 -5
@@ -413,7 +413,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc)if (!alloc) {return NULL ; } - *lp = p =g_malloc0 (sizeof (void *) *L2_SIZE ); + *lp = p = g_new0(void *, L2_SIZE); } lp = p + ((index >> (i *L2_BITS )) & (L2_SIZE -1 )); }
@@ -426,7 +426,7 @@ static PhysPageDesc *phys_page_find_alloc(target_phys_addr_t index, int alloc)return NULL ; } - *lp = pd =g_malloc (sizeof (PhysPageDesc) *L2_SIZE ); + *lp = pd =g_new (PhysPageDesc,L2_SIZE );for (i =0 ; i <L2_SIZE ; i++) { pd[i].phys_offset =IO_MEM_UNASSIGNED ;
@@ -562,7 +562,7 @@ static void code_gen_alloc(unsigned long tb_size) code_gen_buffer_max_size = code_gen_buffer_size - (TCG_MAX_OP_SIZE *OPC_BUF_SIZE ); code_gen_max_blocks = code_gen_buffer_size /CODE_GEN_AVG_BLOCK_SIZE ; - tbs =g_malloc (code_gen_max_blocks *sizeof (TranslationBlock)); + tbs =g_new (TranslationBlock, code_gen_max_blocks); }/* Must be called before using the QEMU cpus. 'tb_size' is the size
@@ -3598,7 +3598,7 @@ static subpage_t *subpage_init (target_phys_addr_t base, ram_addr_t *phys,subpage_t *mmio;int subpage_memory; - mmio =g_malloc0 (sizeof (subpage_t)); + mmio =g_new0 (subpage_t,1 ); mmio->base = base; subpage_memory = cpu_register_io_memory(subpage_read, subpage_write, mmio,
@@ -3704,7 +3704,7 @@ static CPUWriteMemoryFunc * const swapendian_writefn[3]={static void swapendian_init (int io_index) { -SwapEndianContainer *c =g_malloc (sizeof (SwapEndianContainer)); +SwapEndianContainer *c =g_new (SwapEndianContainer,1 );int i;/* Swap mmio for big endian targets */
gdbstub.c +2 -2
@@ -2712,7 +2712,7 @@ static void gdb_accept(void) val =1 ;setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&val,sizeof (val)); - s =g_malloc0 (sizeof (GDBState)); + s =g_new0 (GDBState,1 ); s->c_cpu = first_cpu; s->g_cpu = first_cpu; s->fd = fd;
@@ -2880,7 +2880,7 @@ int gdbserver_start(const char *device) s = gdbserver_state;if (!s) { - s =g_malloc0 (sizeof (GDBState)); + s =g_new0 (GDBState,1 ); gdbserver_state = s;qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );
hw/9pfs/virtio-9p-handle.c +1 -1
@@ -550,7 +550,7 @@ static int handle_init(FsContext *ctx) {int ret, mnt_id;struct file_handle fh; -struct handle_data *data =g_malloc (sizeof (struct handle_data )); + struct handle_data *data = g_new(struct handle_data, 1); data->mountfd =open (ctx->fs_root,O_DIRECTORY );if (data->mountfd <0 ) { ret = data->mountfd;
hw/9pfs/virtio-9p.c +3 -3
@@ -336,7 +336,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)return NULL ; } } - f =g_malloc0 (sizeof (V9fsFidState)); + f =g_new0 (V9fsFidState,1 ); f->fid = fid; f->fid_type =P9_FID_NONE ; f->ref =1 ;
@@ -1771,7 +1771,7 @@ static int v9fs_do_readdir_with_stat(V9fsPDU *pdu,return saved_dir_pos; } - dent =g_malloc (sizeof (struct dirent )); + dent = g_new(struct dirent, 1);while (1 ) {v9fs_path_init (&path);
@@ -1915,7 +1915,7 @@ static int v9fs_do_readdir(V9fsPDU *pdu,return saved_dir_pos; } - dent =g_malloc (sizeof (struct dirent )); + dent = g_new(struct dirent, 1);while (1 ) { err =v9fs_co_readdir_r (pdu, fidp, dent, &result);
hw/adb.c +2 -2
@@ -290,7 +290,7 @@ void adb_kbd_init(ADBBusState *bus) {ADBDevice *d;KBDState *s; - s =g_malloc0 (sizeof (KBDState)); + s =g_new0 (KBDState,1 ); d =adb_register_device (bus,ADB_KEYBOARD , adb_kbd_request, adb_kbd_reset, s);qemu_add_kbd_event_handler (adb_kbd_put_keycode, d);
@@ -447,7 +447,7 @@ void adb_mouse_init(ADBBusState *bus)ADBDevice *d;MouseState *s; - s =g_malloc0 (sizeof (MouseState)); + s =g_new0 (MouseState,1 ); d =adb_register_device (bus,ADB_MOUSE , adb_mouse_request, adb_mouse_reset, s);qemu_add_mouse_event_handler (adb_mouse_event, d,0 ,"QEMU ADB Mouse" );
hw/applesmc.c +1 -1
@@ -170,7 +170,7 @@ static void applesmc_add_key(struct AppleSMCStatus *s, const char *key, {struct AppleSMCData *def; - def =g_malloc0 (sizeof (struct AppleSMCData )); + def = g_new0(struct AppleSMCData, 1); def->key = key; def->len = len; def->data = data;
hw/baum.c +2 -2
@@ -572,8 +572,8 @@ int chr_baum_init(QemuOpts *opts, CharDriverState **_chr)#endif int tty; - baum =g_malloc0 (sizeof (BaumDriverState)); - baum->chr = chr =g_malloc0 (sizeof (CharDriverState)); + baum =g_new0 (BaumDriverState,1 ); + baum->chr = chr =g_new0 (CharDriverState,1 ); chr->opaque = baum; chr->chr_write = baum_write;
hw/bitbang_i2c.c +1 -1
@@ -171,7 +171,7 @@ bitbang_i2c_interface *bitbang_i2c_init(i2c_bus *bus) {bitbang_i2c_interface *s; - s =g_malloc0 (sizeof (bitbang_i2c_interface)); + s =g_new0 (bitbang_i2c_interface,1 ); s->bus = bus; s->last_data =1 ;
hw/blizzard.c +1 -2
@@ -963,8 +963,7 @@ void *s1d13745_init(qemu_irq gpio_int)switch (ds_get_bits_per_pixel (s->state)) {case 0 : - s->line_fn_tab[0 ] = s->line_fn_tab[1 ] = -g_malloc0 (sizeof (blizzard_fn_t) *0x10 ); + s->line_fn_tab[0 ] = s->line_fn_tab[1 ] =g_new0 (blizzard_fn_t,0x10 );break ;case 8 : s->line_fn_tab[0 ] = blizzard_draw_fn_8;
hw/bt-hci.c +2 -2
@@ -721,7 +721,7 @@ static void bt_hci_connection_reject_event(struct bt_hci_s *hci,static void bt_hci_connection_accept (struct bt_hci_s *hci,struct bt_device_s *host) { -struct bt_hci_link_s *link =g_malloc0 (sizeof (struct bt_hci_link_s )); + struct bt_hci_link_s *link = g_new0(struct bt_hci_link_s, 1);evt_conn_complete params;uint16_t handle;uint8_t status =HCI_SUCCESS ;
@@ -2143,7 +2143,7 @@ static void bt_hci_destroy(struct bt_device_s *dev)struct HCIInfo *bt_new_hci (struct bt_scatternet_s *net) { -struct bt_hci_s *s =g_malloc0 (sizeof (struct bt_hci_s )); + struct bt_hci_s *s = g_new0(struct bt_hci_s, 1); s->lm.inquiry_done =qemu_new_timer_ns (vm_clock, bt_hci_inquiry_done, s); s->lm.inquiry_next =qemu_new_timer_ns (vm_clock, bt_hci_inquiry_next, s);
hw/bt-l2cap.c +2 -2
@@ -1236,7 +1236,7 @@ static void l2cap_lmp_connection_request(struct bt_link_s *link)/* Always accept - we only get called if (dev->device->page_scan). */ - l2cap =g_malloc0 (sizeof (struct slave_l2cap_instance_s )); + l2cap = g_new0(struct slave_l2cap_instance_s, 1); l2cap->link.slave = &dev->device; l2cap->link.host = link->host;l2cap_init (&l2cap->l2cap, &l2cap->link,0 );
@@ -1257,7 +1257,7 @@ static void l2cap_lmp_connection_complete(struct bt_link_s *link)return ; } - l2cap =g_malloc0 (sizeof (struct l2cap_instance_s )); + l2cap = g_new0(struct l2cap_instance_s, 1);l2cap_init (l2cap, link,1 ); link->acl_mode = acl_active;
hw/bt.c +1 -1
@@ -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;
hw/cirrus_vga.c +1 -1
@@ -2903,7 +2903,7 @@ void isa_cirrus_vga_init(MemoryRegion *system_memory) {CirrusVGAState *s; - s =g_malloc0 (sizeof (CirrusVGAState)); + s =g_new0 (CirrusVGAState,1 );vga_common_init (&s->vga,VGA_RAM_SIZE );cirrus_init_common (s,CIRRUS_ID_CLGD5430 ,0 , system_memory);
hw/dp8393x.c +1 -1
@@ -889,7 +889,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,qemu_check_nic_model (nd,"dp83932" ); - s =g_malloc0 (sizeof (dp8393xState)); + s =g_new0 (dp8393xState,1 ); s->mem_opaque = mem_opaque; s->memory_rw = memory_rw;
hw/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, &heathrow_pic_ops, s,
hw/i8259.c +1 -1
@@ -524,7 +524,7 @@ qemu_irq *i8259_init(qemu_irq parent_irq)ISADevice *dev;int i; - irq_set =g_malloc (ISA_NUM_IRQS *sizeof (qemu_irq)); + irq_set =g_new (qemu_irq,ISA_NUM_IRQS ); dev =isa_create ("isa-i8259" );qdev_prop_set_uint32 (&dev->qdev,"iobase" ,0x20 );
hw/ide/macio.c +1 -1
@@ -342,7 +342,7 @@ MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq, {MACIOIDEState *d; - d =g_malloc0 (sizeof (MACIOIDEState)); + d =g_new0 (MACIOIDEState,1 );ide_init2_with_non_qdev_drives (&d->bus, hd_table[0 ], hd_table[1 ], irq);if (dbdma)
hw/ide/mmio.c +1 -1
@@ -120,7 +120,7 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2, qemu_irq irq, int shift, DriveInfo *hd0, DriveInfo *hd1) { - MMIOState *s = g_malloc0(sizeof(MMIOState)); + MMIOState *s = g_new0(MMIOState, 1);int mem1, mem2;ide_init2_with_non_qdev_drives (&s->bus, hd0, hd1, irq);
hw/irq.c +1 -1
@@ -85,7 +85,7 @@ static void qemu_splitirq(void *opaque, int line, int level)qemu_irq qemu_irq_split (qemu_irq irq1,qemu_irq irq2) { -qemu_irq *s =g_malloc0 (2 *sizeof (qemu_irq)); +qemu_irq *s =g_new0 (qemu_irq,2 ); s[0 ] = irq1; s[1 ] = irq2;return qemu_allocate_irqs (qemu_splitirq, s,1 )[0 ];
hw/ivshmem.c +3 -3
@@ -556,7 +556,7 @@ static void ivshmem_setup_msi(IVShmemState * s) { }/* allocate Qemu char devices for receiving interrupts */ - s->eventfd_table =g_malloc0 (s->vectors *sizeof (EventfdEntry)); + s->eventfd_table =g_new0 (EventfdEntry, s->vectors); }static void ivshmem_save (QEMUFile * f,void *opaque)
@@ -690,12 +690,12 @@ static int pci_ivshmem_init(PCIDevice *dev) s->vm_id =-1 ;/* allocate/initialize space for interrupt handling */ - s->peers =g_malloc0 (s->nb_peers *sizeof (Peer)); + s->peers =g_new0 (Peer, s->nb_peers);pci_register_bar (&s->dev,2 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &s->ivshmem); - s->eventfd_chr =g_malloc0 (s->vectors *sizeof (CharDriverState *)); + s->eventfd_chr = g_new0(CharDriverState *, s->vectors);qemu_chr_add_handlers (s->server_chr, ivshmem_can_receive, ivshmem_read, ivshmem_event, s);
hw/jazz_led.c +1 -1
@@ -312,7 +312,7 @@ void jazz_led_init(target_phys_addr_t base)LedState *s;int io; - s =g_malloc0 (sizeof (LedState)); + s =g_new0 (LedState,1 ); s->state =REDRAW_SEGMENTS |REDRAW_BACKGROUND ;
hw/leon3.c +1 -1
@@ -125,7 +125,7 @@ static void leon3_generic_hw_init(ram_addr_t ram_size,cpu_sparc_set_id (env,0 );/* Reset data */ - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->env = env;qemu_register_reset (main_cpu_reset, reset_info);
hw/lm32_boards.c +2 -2
@@ -96,7 +96,7 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,int timer0_irq =1 ;int timer1_irq =3 ; - reset_info =g_malloc0 (sizeof (ResetInfo)); + reset_info =g_new0 (ResetInfo,1 );if (cpu_model ==NULL ) { cpu_model ="lm32-full" ;
@@ -190,7 +190,7 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,target_phys_addr_t initrd_base =0x08400000 ;size_t initrd_max =0x01000000 ; - reset_info =g_malloc0 (sizeof (ResetInfo)); + reset_info =g_new0 (ResetInfo,1 );if (cpu_model ==NULL ) { cpu_model ="lm32-full" ;
hw/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/mac_dbdma.c +1 -1
@@ -846,7 +846,7 @@ void* DBDMA_init (MemoryRegion **dbdma_mem) {DBDMAState *s; - s =g_malloc0 (sizeof (DBDMAState)); + s =g_new0 (DBDMAState,1 );memory_region_init_io (&s->mem, &dbdma_ops, s,"dbdma" ,0x1000 ); *dbdma_mem = &s->mem;
hw/mac_nvram.c +1 -1
@@ -121,7 +121,7 @@ MacIONVRAMState *macio_nvram_init (target_phys_addr_t size, {MacIONVRAMState *s; - s =g_malloc0 (sizeof (MacIONVRAMState)); + s =g_new0 (MacIONVRAMState,1 ); s->data =g_malloc0 (size); s->size = size; s->it_shift = it_shift;
hw/mcf_intc.c +1 -1
@@ -144,7 +144,7 @@ qemu_irq *mcf_intc_init(target_phys_addr_t base, CPUState *env)mcf_intc_state *s;int iomemtype; - s =g_malloc0 (sizeof (mcf_intc_state)); + s =g_new0 (mcf_intc_state,1 ); s->env = env;mcf_intc_reset (s);
hw/mcf_uart.c +1 -1
@@ -272,7 +272,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr) {mcf_uart_state *s; - s =g_malloc0 (sizeof (mcf_uart_state)); + s =g_new0 (mcf_uart_state,1 ); s->chr = chr; s->irq = irq;if (chr) {
hw/milkymist.c +1 -1
@@ -100,7 +100,7 @@ milkymist_init(ram_addr_t ram_size_not_used,target_phys_addr_t cmdline_base = sdram_base +0x1000000 ;size_t initrd_max = sdram_size -0x1002000 ; - reset_info =g_malloc0 (sizeof (ResetInfo)); + reset_info =g_new0 (ResetInfo,1 );if (cpu_model ==NULL ) { cpu_model ="lm32-full" ;
hw/mips_mipssim.c +1 -1
@@ -157,7 +157,7 @@ mips_mipssim_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->env = env; reset_info->vector = env->active_tc.PC;qemu_register_reset (main_cpu_reset, reset_info);
hw/mips_r4k.c +1 -1
@@ -182,7 +182,7 @@ void mips_r4k_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->env = env; reset_info->vector = env->active_tc.PC;qemu_register_reset (main_cpu_reset, reset_info);
hw/msmouse.c +1 -1
@@ -68,7 +68,7 @@ int qemu_chr_open_msmouse(QemuOpts *opts, CharDriverState **_chr) {CharDriverState *chr; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 ); chr->chr_write = msmouse_chr_write; chr->chr_close = msmouse_chr_close;
hw/omap.h +1 -1
@@ -1113,7 +1113,7 @@ inline static int debug_register_io_memory(CPUReadMemoryFunc * const *mem_read, CPUWriteMemoryFunc * const *mem_write, void *opaque) { -struct io_fn *s =g_malloc (sizeof (struct io_fn )); + struct io_fn *s = g_new(struct io_fn, 1); s->mem_read = mem_read; s->mem_write = mem_write;
hw/omap_gpio.c +2 -2
@@ -696,8 +696,8 @@ static int omap2_gpio_init(SysBusDevice *dev) }else { s->modulecount =6 ; } - s->modules =g_malloc0 (s->modulecount *sizeof (struct omap2_gpio_s )); - s->handler =g_malloc0 (s->modulecount *32 *sizeof (qemu_irq)); + s->modules = g_new0(struct omap2_gpio_s, s->modulecount); + s->handler =g_new0 (qemu_irq, s->modulecount *32 );qdev_init_gpio_in (&dev->qdev, omap2_gpio_set, s->modulecount *32 );qdev_init_gpio_out (&dev->qdev, s->handler, s->modulecount *32 );for (i =0 ; i < s->modulecount; i++) {
hw/omap_l4.c +1 -1
@@ -140,7 +140,7 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num) omap_l4_io_writeb_fn =g_malloc0 (sizeof (void *) *L4_PAGES ); omap_l4_io_writeh_fn =g_malloc0 (sizeof (void *) *L4_PAGES ); omap_l4_io_writew_fn =g_malloc0 (sizeof (void *) *L4_PAGES ); - omap_l4_io_opaque =g_malloc0 (sizeof (void *) *L4_PAGES ); + omap_l4_io_opaque = g_new0(void *, L4_PAGES);#endif return bus;
hw/parallel.c +1 -1
@@ -574,7 +574,7 @@ bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,ParallelState *s;int io_sw; - s =g_malloc0 (sizeof (ParallelState)); + s =g_new0 (ParallelState,1 ); s->irq = irq; s->chr = chr; s->it_shift = it_shift;
hw/pckbd.c +1 -1
@@ -412,7 +412,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, MemoryRegion *region, ram_addr_t size, target_phys_addr_t mask) { - KBDState *s = g_malloc0(sizeof(KBDState)); + KBDState *s = g_new0(KBDState, 1); s->irq_kbd = kbd_irq; s->irq_mouse = mouse_irq;
hw/pflash_cfi01.c +1 -1
@@ -585,7 +585,7 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base,return NULL ;#endif - pfl =g_malloc0 (sizeof (pflash_t)); + pfl =g_new0 (pflash_t,1 ); memory_region_init_rom_device( &pfl->mem, be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl,
hw/pflash_cfi02.c +1 -1
@@ -625,7 +625,7 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))return NULL ;#endif - pfl =g_malloc0 (sizeof (pflash_t)); + pfl =g_new0 (pflash_t,1 );memory_region_init_rom_device ( &pfl->orig_mem, be ? &pflash_cfi02_ops_be : &pflash_cfi02_ops_le, pfl, qdev, name, size);
hw/ppc.c +4 -4
@@ -753,7 +753,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUState *env, uint32_t freq) {ppc_tb_t *tb_env; - tb_env =g_malloc0 (sizeof (ppc_tb_t)); + tb_env =g_new0 (ppc_tb_t,1 ); env->tb_env = tb_env; tb_env->flags =PPC_DECR_UNDERFLOW_TRIGGERED ;/* Create new timer */
@@ -1007,10 +1007,10 @@ clk_setup_cb ppc_40x_timers_init (CPUState *env, uint32_t freq,ppc_tb_t *tb_env;ppc40x_timer_t *ppc40x_timer; - tb_env =g_malloc0 (sizeof (ppc_tb_t)); + tb_env =g_new0 (ppc_tb_t,1 ); env->tb_env = tb_env; tb_env->flags =PPC_DECR_UNDERFLOW_TRIGGERED ; - ppc40x_timer =g_malloc0 (sizeof (ppc40x_timer_t)); + ppc40x_timer =g_new0 (ppc40x_timer_t,1 ); tb_env->tb_freq = freq; tb_env->decr_freq = freq; tb_env->opaque = ppc40x_timer;
@@ -1115,7 +1115,7 @@ int ppc_dcr_init (CPUState *env, int (*read_error)(int dcrn), {ppc_dcr_t *dcr_env; - dcr_env =g_malloc0 (sizeof (ppc_dcr_t)); + dcr_env =g_new0 (ppc_dcr_t,1 ); dcr_env->read_error = read_error; dcr_env->write_error = write_error; env->dcr_env = dcr_env;
hw/ppc405_boards.c +2 -2
@@ -163,7 +163,7 @@ static void ref405ep_fpga_init (MemoryRegion *sysmem, uint32_t base)ref405ep_fpga_t *fpga;MemoryRegion *fpga_memory =g_new (MemoryRegion,1 ); - fpga =g_malloc0 (sizeof (ref405ep_fpga_t)); + fpga =g_new0 (ref405ep_fpga_t,1 );memory_region_init_io (fpga_memory, &ref405ep_fpga_ops, fpga,"fpga" ,0x00000100 );memory_region_add_subregion (sysmem, base, fpga_memory);
@@ -486,7 +486,7 @@ static void taihu_cpld_init (MemoryRegion *sysmem, uint32_t base)taihu_cpld_t *cpld;MemoryRegion *cpld_memory =g_new (MemoryRegion,1 ); - cpld =g_malloc0 (sizeof (taihu_cpld_t)); + cpld =g_new0 (taihu_cpld_t,1 );memory_region_init_io (cpld_memory, &taihu_cpld_ops, cpld,"cpld" ,0x100 );memory_region_add_subregion (sysmem, base, cpld_memory);qemu_register_reset (&taihu_cpld_reset, cpld);
hw/ppc405_uc.c +14 -14
@@ -173,7 +173,7 @@ static void ppc4xx_plb_init(CPUState *env) {ppc4xx_plb_t *plb; - plb =g_malloc0 (sizeof (ppc4xx_plb_t)); + plb =g_new0 (ppc4xx_plb_t,1 );ppc_dcr_register (env,PLB0_ACR , plb, &dcr_read_plb, &dcr_write_plb);ppc_dcr_register (env,PLB0_BEAR , plb, &dcr_read_plb, &dcr_write_plb);ppc_dcr_register (env,PLB0_BESR , plb, &dcr_read_plb, &dcr_write_plb);
@@ -249,7 +249,7 @@ static void ppc4xx_pob_init(CPUState *env) {ppc4xx_pob_t *pob; - pob =g_malloc0 (sizeof (ppc4xx_pob_t)); + pob =g_new0 (ppc4xx_pob_t,1 );ppc_dcr_register (env,POB0_BEAR , pob, &dcr_read_pob, &dcr_write_pob);ppc_dcr_register (env,POB0_BESR0 , pob, &dcr_read_pob, &dcr_write_pob);ppc_dcr_register (env,POB0_BESR1 , pob, &dcr_read_pob, &dcr_write_pob);
@@ -380,7 +380,7 @@ static void ppc4xx_opba_init(target_phys_addr_t base) {ppc4xx_opba_t *opba; - opba =g_malloc0 (sizeof (ppc4xx_opba_t)); + opba =g_new0 (ppc4xx_opba_t,1 );#ifdef DEBUG_OPBA printf ("%s: offset " TARGET_FMT_plx"\n" , __func__, base);#endif
@@ -578,7 +578,7 @@ static void ppc405_ebc_init(CPUState *env) {ppc4xx_ebc_t *ebc; - ebc =g_malloc0 (sizeof (ppc4xx_ebc_t)); + ebc =g_new0 (ppc4xx_ebc_t,1 );qemu_register_reset (&ebc_reset, ebc);ppc_dcr_register (env,EBC0_CFGADDR , ebc, &dcr_read_ebc, &dcr_write_ebc);
@@ -661,7 +661,7 @@ static void ppc405_dma_init(CPUState *env, qemu_irq irqs[4]) {ppc405_dma_t *dma; - dma =g_malloc0 (sizeof (ppc405_dma_t)); + dma =g_new0 (ppc405_dma_t,1 );memcpy (dma->irqs, irqs,4 *sizeof (qemu_irq));qemu_register_reset (&ppc405_dma_reset, dma); ppc_dcr_register(env, DMA0_CR0,
@@ -802,7 +802,7 @@ static void ppc405_gpio_init(target_phys_addr_t base) {ppc405_gpio_t *gpio; - gpio =g_malloc0 (sizeof (ppc405_gpio_t)); + gpio =g_new0 (ppc405_gpio_t,1 );#ifdef DEBUG_GPIO printf ("%s: offset " TARGET_FMT_plx"\n" , __func__, base);#endif
@@ -964,7 +964,7 @@ static void ppc405_ocm_init(CPUState *env) {ppc405_ocm_t *ocm; - ocm =g_malloc0 (sizeof (ppc405_ocm_t)); + ocm =g_new0 (ppc405_ocm_t,1 );/* XXX: Size is 4096 or 0x04000000 */ memory_region_init_ram (&ocm->isarc_ram,NULL ,"ppc405.ocm" ,4096 ); memory_region_init_alias(&ocm->dsarc_ram, "ppc405.dsarc", &ocm->isarc_ram,
@@ -1210,7 +1210,7 @@ static void ppc405_i2c_init(target_phys_addr_t base, qemu_irq irq) {ppc4xx_i2c_t *i2c; - i2c =g_malloc0 (sizeof (ppc4xx_i2c_t)); + i2c =g_new0 (ppc4xx_i2c_t,1 ); i2c->irq = irq;#ifdef DEBUG_I2C printf ("%s: offset " TARGET_FMT_plx"\n" , __func__, base);
@@ -1486,7 +1486,7 @@ static void ppc4xx_gpt_init(target_phys_addr_t base, qemu_irq irqs[5])ppc4xx_gpt_t *gpt;int i; - gpt =g_malloc0 (sizeof (ppc4xx_gpt_t)); + gpt =g_new0 (ppc4xx_gpt_t,1 );for (i =0 ; i <5 ; i++) { gpt->irqs[i] = irqs[i]; }
@@ -1717,7 +1717,7 @@ static void ppc405_mal_init(CPUState *env, qemu_irq irqs[4])ppc40x_mal_t *mal;int i; - mal =g_malloc0 (sizeof (ppc40x_mal_t)); + mal =g_new0 (ppc40x_mal_t,1 );for (i =0 ; i <4 ; i++) mal->irqs[i] = irqs[i];qemu_register_reset (&ppc40x_mal_reset, mal);
@@ -2082,7 +2082,7 @@ static void ppc405cr_cpc_init (CPUState *env, clk_setup_t clk_setup[7], {ppc405cr_cpc_t *cpc; - cpc =g_malloc0 (sizeof (ppc405cr_cpc_t)); + cpc =g_new0 (ppc405cr_cpc_t,1 );memcpy (cpc->clk_setup, clk_setup,PPC405CR_CLK_NB *sizeof (clk_setup_t)); cpc->sysclk = sysclk;
@@ -2130,7 +2130,7 @@ CPUState *ppc405cr_init(MemoryRegion *address_space_mem,/* OBP arbitrer */ ppc4xx_opba_init (0xef600600 );/* Universal interrupt controller */ - irqs =g_malloc0 (sizeof (qemu_irq) *PPCUIC_OUTPUT_NB ); + irqs =g_new0 (qemu_irq,PPCUIC_OUTPUT_NB ); irqs[PPCUIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; irqs[PPCUIC_OUTPUT_CINT] =
@@ -2424,7 +2424,7 @@ static void ppc405ep_cpc_init (CPUState *env, clk_setup_t clk_setup[8], {ppc405ep_cpc_t *cpc; - cpc =g_malloc0 (sizeof (ppc405ep_cpc_t)); + cpc =g_new0 (ppc405ep_cpc_t,1 );memcpy (cpc->clk_setup, clk_setup,PPC405EP_CLK_NB *sizeof (clk_setup_t)); cpc->jtagid =0x20267049 ;
@@ -2483,7 +2483,7 @@ CPUState *ppc405ep_init(MemoryRegion *address_space_mem,/* OBP arbitrer */ ppc4xx_opba_init (0xef600600 );/* Universal interrupt controller */ - irqs =g_malloc0 (sizeof (qemu_irq) *PPCUIC_OUTPUT_NB ); + irqs =g_new0 (qemu_irq,PPCUIC_OUTPUT_NB ); irqs[PPCUIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; irqs[PPCUIC_OUTPUT_CINT] =
hw/ppc440.c +2 -2
@@ -58,7 +58,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,ppc_dcr_init (env,NULL ,NULL );/* interrupt controller */ - irqs =g_malloc0 (sizeof (qemu_irq) *PPCUIC_OUTPUT_NB ); + irqs =g_new0 (qemu_irq,PPCUIC_OUTPUT_NB ); irqs[PPCUIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; irqs[PPCUIC_OUTPUT_CINT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; pic =ppcuic_init (env, irqs,0x0C0 ,0 ,1 );
@@ -75,7 +75,7 @@ CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size, ram_bases, ram_sizes, do_init);/* PCI */ - pci_irqs =g_malloc (sizeof (qemu_irq) *4 ); + pci_irqs =g_new (qemu_irq,4 ); pci_irqs[0 ] = pic[pci_irq_nrs[0 ]]; pci_irqs[1 ] = pic[pci_irq_nrs[1 ]]; pci_irqs[2 ] = pic[pci_irq_nrs[2 ]];
hw/ppc4xx_devs.c +2 -2
@@ -294,7 +294,7 @@ qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs,ppcuic_t *uic;int i; - uic =g_malloc0 (sizeof (ppcuic_t)); + uic =g_new0 (ppcuic_t,1 ); uic->dcr_base = dcr_base; uic->irqs = irqs;if (has_vr)
@@ -642,7 +642,7 @@ void ppc4xx_sdram_init (CPUState *env, qemu_irq irq, int nbanks, {ppc4xx_sdram_t *sdram; - sdram =g_malloc0 (sizeof (ppc4xx_sdram_t)); + sdram =g_new0 (ppc4xx_sdram_t,1 ); sdram->irq = irq; sdram->nbanks = nbanks; sdram->ram_memories = ram_memories;
hw/ppc4xx_pci.c +1 -1
@@ -341,7 +341,7 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],static int ppc4xx_pci_id;uint8_t *pci_conf; - controller =g_malloc0 (sizeof (PPC4xxPCIState)); + controller =g_new0 (PPC4xxPCIState,1 ); controller->pci_state.bus = pci_register_bus(NULL, "pci", ppc4xx_pci_set_irq,
hw/ppc_booke.c +2 -2
@@ -236,8 +236,8 @@ void ppc_booke_timers_init(CPUState *env, uint32_t freq, uint32_t flags)ppc_tb_t *tb_env;booke_timer_t *booke_timer; - tb_env =g_malloc0 (sizeof (ppc_tb_t)); - booke_timer =g_malloc0 (sizeof (booke_timer_t)); + tb_env =g_new0 (ppc_tb_t,1 ); + booke_timer =g_new0 (booke_timer_t,1 ); env->tb_env = tb_env; tb_env->flags = flags |PPC_TIMER_BOOKE |PPC_DECR_ZERO_TRIGGERED ;
hw/ppc_newworld.c +1 -1
@@ -266,7 +266,7 @@ static void ppc_core99_init (ram_addr_t ram_size,memory_region_init_io (unin_memory, &unin_ops,NULL ,"unin" ,0x1000 );memory_region_add_subregion (get_system_memory (),0xf8000000 , unin_memory); - openpic_irqs =g_malloc0 (smp_cpus *sizeof (qemu_irq *)); + openpic_irqs = g_new0(qemu_irq *, smp_cpus); openpic_irqs[0 ] =g_malloc0 (smp_cpus *sizeof (qemu_irq) *OPENPIC_OUTPUT_NB );for (i =0 ; i < smp_cpus; i++) {
hw/ppc_oldworld.c +1 -1
@@ -212,7 +212,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,isa_mmio_init (0xfe000000 ,0x00200000 );/* XXX: we register only 1 output pin for heathrow PIC */ - heathrow_irqs =g_malloc0 (smp_cpus *sizeof (qemu_irq *)); + heathrow_irqs = g_new0(qemu_irq *, smp_cpus); heathrow_irqs[0 ] =g_malloc0 (smp_cpus *sizeof (qemu_irq) *1 );/* Connect the heathrow PIC outputs to the 6xx bus */
hw/ppc_prep.c +1 -1
@@ -550,7 +550,7 @@ static void ppc_prep_init (ram_addr_t ram_size,DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ];DriveInfo *fd[MAX_FD ]; - sysctrl =g_malloc0 (sizeof (sysctrl_t)); + sysctrl =g_new0 (sysctrl_t,1 ); linux_boot = (kernel_filename !=NULL );
hw/ppce500_mpc8544ds.c +2 -2
@@ -250,7 +250,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, cpu_model ="e500v2_v30" ; } - irqs =g_malloc0 (smp_cpus *sizeof (qemu_irq *)); + irqs = g_new0(qemu_irq *, smp_cpus); irqs[0 ] =g_malloc0 (smp_cpus *sizeof (qemu_irq) *OPENPIC_OUTPUT_NB );for (i =0 ; i < smp_cpus; i++) {qemu_irq *input;
@@ -276,7 +276,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,if (!i) {/* Primary CPU */ struct boot_info *boot_info; - boot_info =g_malloc0 (sizeof (struct boot_info )); + boot_info = g_new0(struct boot_info, 1);qemu_register_reset (mpc8544ds_cpu_reset, env); env->load_info = boot_info; }else {
hw/prep_pci.c +1 -1
@@ -118,7 +118,7 @@ PCIBus *pci_prep_init(qemu_irq *pic,PCIDevice *d;int PPC_io_memory; - s =g_malloc0 (sizeof (PREPPCIState)); + s =g_new0 (PREPPCIState,1 ); s->bus = pci_register_bus(NULL, "pci", prep_set_irq, prep_map_irq, pic, address_space_mem,
hw/pxa2xx_dma.c +1 -1
@@ -461,7 +461,7 @@ static int pxa2xx_dma_init(SysBusDevice *dev)return -1 ; } - s->chan =g_malloc0 (sizeof (PXA2xxDMAChannel) * s->channels); + s->chan =g_new0 (PXA2xxDMAChannel, s->channels);memset (s->chan,0 ,sizeof (PXA2xxDMAChannel) * s->channels);for (i =0 ; i < s->channels; i ++)
hw/qxl.c +1 -1
@@ -1700,7 +1700,7 @@ static int qxl_post_load(void *opaque, int version)qxl_create_guest_primary (d,1 ,QXL_SYNC );/* replay surface-create and cursor-set commands */ - cmds =g_malloc0 (sizeof (QXLCommandExt) * (NUM_SURFACES +1 )); + cmds =g_new0 (QXLCommandExt, (NUM_SURFACES +1 ));for (in =0 , out =0 ; in <NUM_SURFACES ; in++) {if (d->guest_surfaces.cmds[in] ==0 ) {continue ;
hw/r2d.c +2 -2
@@ -185,7 +185,7 @@ static qemu_irq *r2d_fpga_init(target_phys_addr_t base, qemu_irq irl)int iomemtype;r2d_fpga_t *s; - s =g_malloc0 (sizeof (r2d_fpga_t)); + s =g_new0 (r2d_fpga_t,1 ); s->irl = irl;
@@ -246,7 +246,7 @@ static void r2d_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->env = env; reset_info->vector = env->pc;qemu_register_reset (main_cpu_reset, reset_info);
hw/rc4030.c +1 -1
@@ -806,7 +806,7 @@ void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus,rc4030State *s;int s_chipset, s_jazzio; - s =g_malloc0 (sizeof (rc4030State)); + s =g_new0 (rc4030State,1 ); *irqs =qemu_allocate_irqs (rc4030_irq_jazz_request, s,16 ); *dmas =rc4030_allocate_dmas (s,4 );
hw/s390-virtio.c +1 -1
@@ -161,7 +161,7 @@ static void s390_init(ram_addr_t my_ram_size, cpu_model ="host" ; } - ipi_states =g_malloc (sizeof (CPUState *) * smp_cpus); + ipi_states = g_new(CPUState *, smp_cpus);for (i =0 ; i < smp_cpus; i++) {CPUState *tmp_env;
hw/serial.c +2 -2
@@ -806,7 +806,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase, {SerialState *s; - s =g_malloc0 (sizeof (SerialState)); + s =g_new0 (SerialState,1 ); s->irq = irq; s->baudbase = baudbase;
@@ -861,7 +861,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space, {SerialState *s; - s =g_malloc0 (sizeof (SerialState)); + s =g_new0 (SerialState,1 ); s->it_shift = it_shift; s->irq = irq;
hw/sh7750.c +1 -1
@@ -712,7 +712,7 @@ SH7750State *sh7750_init(CPUSH4State * cpu)int sh7750_io_memory;int sh7750_mm_cache_and_tlb;/* memory mapped cache and tlb */ - s =g_malloc0 (sizeof (SH7750State)); + s =g_new0 (SH7750State,1 ); s->cpu = cpu; s->periph_freq =60000000 ;/* 60MHz */ sh7750_io_memory = cpu_register_io_memory(sh7750_mem_read,
hw/sh_serial.c +1 -1
@@ -361,7 +361,7 @@ void sh_serial_init (target_phys_addr_t base, int feat,sh_serial_state *s;int s_io_memory; - s =g_malloc0 (sizeof (sh_serial_state)); + s =g_new0 (sh_serial_state,1 ); s->feat = feat; s->flags =SH_SERIAL_FLAG_TEND |SH_SERIAL_FLAG_TDE ;
hw/slavio_timer.c +1 -1
@@ -381,7 +381,7 @@ static int slavio_timer_init1(SysBusDevice *dev)TimerContext *tc;for (i =0 ; i <=MAX_CPUS ; i++) { - tc =g_malloc0 (sizeof (TimerContext)); + tc =g_new0 (TimerContext,1 ); tc->s = s; tc->timer_index = i;
hw/strongarm.c +1 -1
@@ -1529,7 +1529,7 @@ StrongARMState *sa1110_init(unsigned int sdram_size, const char *rev)qemu_irq *pic;int i; - s =g_malloc0 (sizeof (StrongARMState)); + s =g_new0 (StrongARMState,1 );if (!rev) { rev ="sa1110-b5" ;
hw/sun4u.c +2 -2
@@ -348,7 +348,7 @@ static CPUTimer* cpu_timer_create(const char* name, CPUState *env, QEMUBHFunc *cb, uint32_t frequency, uint64_t disabled_mask) { - CPUTimer *timer = g_malloc0(sizeof (CPUTimer)); + CPUTimer *timer = g_new0(CPUTimer, 1); timer->name = name; timer->frequency = frequency;
@@ -720,7 +720,7 @@ static CPUState *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef) env->hstick =cpu_timer_create ("hstick" , env, hstick_irq, hstick_frequency,TICK_INT_DIS ); - reset_info =g_malloc0 (sizeof (ResetData)); + reset_info =g_new0 (ResetData,1 ); reset_info->env = env; reset_info->prom_addr = hwdef->prom_addr;qemu_register_reset (main_cpu_reset, reset_info);
hw/syborg_interrupt.c +1 -1
@@ -213,7 +213,7 @@ static int syborg_int_init(SysBusDevice *dev) syborg_int_writefn, s, DEVICE_NATIVE_ENDIAN);sysbus_init_mmio (dev,0x1000 , iomemtype); - s->flags =g_malloc0 (s->num_irqs *sizeof (syborg_int_flags)); + s->flags =g_new0 (syborg_int_flags, s->num_irqs);register_savevm (&dev->qdev,"syborg_int" ,-1 ,1 , syborg_int_save, syborg_int_load, s);
hw/usb-uhci.c +1 -1
@@ -168,7 +168,7 @@ typedef struct UHCI_QH {static UHCIAsync *uhci_async_alloc (UHCIState *s) { -UHCIAsync *async =g_malloc (sizeof (UHCIAsync)); +UHCIAsync *async =g_new (UHCIAsync,1 );memset (&async->packet,0 ,sizeof (async->packet)); async->uhci = s;
hw/vga.c +1 -1
@@ -2394,7 +2394,7 @@ static DisplayChangeListener* vga_screen_dump_init(DisplayState *ds) {DisplayChangeListener *dcl; - dcl =g_malloc0 (sizeof (DisplayChangeListener)); + dcl =g_new0 (DisplayChangeListener,1 ); dcl->dpy_update = vga_save_dpy_update; dcl->dpy_resize = vga_save_dpy_resize; dcl->dpy_refresh = vga_save_dpy_refresh;
hw/virtex_ml507.c +1 -1
@@ -98,7 +98,7 @@ static CPUState *ppc440_init_xilinx(ram_addr_t *ram_size,ppc_dcr_init (env,NULL ,NULL );/* interrupt controller */ - irqs =g_malloc0 (sizeof (qemu_irq) *PPCUIC_OUTPUT_NB ); + irqs =g_new0 (qemu_irq,PPCUIC_OUTPUT_NB ); irqs[PPCUIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; irqs[PPCUIC_OUTPUT_CINT ] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];ppcuic_init (env, irqs,0x0C0 ,0 ,1 );
hw/xenfb.c +2 -2
@@ -493,8 +493,8 @@ static int xenfb_map_fb(struct XenFB *xenfb) n_fbdirs = xenfb->fbpages * mode /8 ; n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE -1 )) /XC_PAGE_SIZE ; - pgmfns =g_malloc0 (sizeof (unsigned long ) * n_fbdirs); - fbmfns =g_malloc0 (sizeof (unsigned long ) * xenfb->fbpages); + pgmfns = g_new0(unsigned long, n_fbdirs); + fbmfns = g_new0(unsigned long, xenfb->fbpages);xenfb_copy_mfns (mode, n_fbdirs, pgmfns, pd); map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
hw/xics.c +2 -2
@@ -439,7 +439,7 @@ struct icp_state *xics_system_init(int nr_irqs) icp = g_new0(struct icp_state, 1); icp->nr_servers = max_server_num +1 ; - icp->ss =g_malloc0 (icp->nr_servers*sizeof (struct icp_server_state )); + icp->ss = g_new0(struct icp_server_state, icp->nr_servers);for (i =0 ; i < icp->nr_servers; i++) { icp->ss[i].mfrr =0xff ;
@@ -467,7 +467,7 @@ struct icp_state *xics_system_init(int nr_irqs) ics = g_new0(struct ics_state, 1); ics->nr_irqs = nr_irqs; ics->offset =16 ; - ics->irqs =g_malloc0 (nr_irqs *sizeof (struct ics_irq_state )); + ics->irqs = g_new0(struct ics_irq_state, nr_irqs); icp->ics = ics; ics->icp = icp;
hw/xtensa_lx60.c +1 -1
@@ -96,7 +96,7 @@ static const MemoryRegionOps lx60_fpga_ops = {static Lx60FpgaState *lx60_fpga_init (MemoryRegion *address_space,target_phys_addr_t base) { -Lx60FpgaState *s =g_malloc (sizeof (Lx60FpgaState)); +Lx60FpgaState *s =g_new (Lx60FpgaState,1 );memory_region_init_io (&s->iomem, &lx60_fpga_ops, s,"lx60-fpga" ,0x10000 );
input.c +2 -2
@@ -73,7 +73,7 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,QEMUPutMouseEntry *s;static int mouse_index =0 ; - s =g_malloc0 (sizeof (QEMUPutMouseEntry)); + s =g_new0 (QEMUPutMouseEntry,1 ); s->qemu_put_mouse_event = func; s->qemu_put_mouse_event_opaque = opaque;
@@ -111,7 +111,7 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, {QEMUPutLEDEntry *s; - s =g_malloc0 (sizeof (QEMUPutLEDEntry)); + s =g_new0 (QEMUPutLEDEntry,1 ); s->put_led = func; s->opaque = opaque;
iohandler.c +2 -2
@@ -67,7 +67,7 @@ int qemu_set_fd_handler2(int fd,if (ioh->fd == fd) goto found; } - ioh =g_malloc0 (sizeof (IOHandlerRecord)); + ioh =g_new0 (IOHandlerRecord,1 );QLIST_INSERT_HEAD (&io_handlers, ioh, next); found: ioh->fd = fd;
@@ -237,7 +237,7 @@ int qemu_add_child_watch(pid_t pid)return 1 ; } } - rec =g_malloc0 (sizeof (ChildProcessRecord)); + rec =g_new0 (ChildProcessRecord,1 ); rec->pid = pid;QLIST_INSERT_HEAD (&child_watches, rec, next);return 0 ;
kvm-all.c +2 -2
@@ -702,7 +702,7 @@ int kvm_init(void)int ret;int i; - s =g_malloc0 (sizeof (KVMState)); + s =g_new0 (KVMState,1 );#ifdef KVM_CAP_SET_GUEST_DEBUG QTAILQ_INIT (&s->kvm_sw_breakpoints);
@@ -1188,7 +1188,7 @@ int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,return 0 ; } - bp =g_malloc (sizeof (struct kvm_sw_breakpoint )); + bp = g_new(struct kvm_sw_breakpoint, 1);if (!bp) {return -ENOMEM ; }
linux-user/main.c +1 -1
@@ -3463,7 +3463,7 @@ int main(int argc, char **argv, char **envp) } target_argv[target_argc] =NULL ; - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* build Task State */ ts->info = info;
linux-user/syscall.c +1 -1
@@ -4002,7 +4002,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,new_thread_info info;pthread_attr_t attr;#endif - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* we create a new CPU instance. */ new_env =cpu_copy (env);
monitor.c +1 -1
@@ -2673,7 +2673,7 @@ static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)return 0 ; } - monfd =g_malloc0 (sizeof (mon_fd_t)); + monfd =g_new0 (mon_fd_t,1 ); monfd->name =g_strdup (fdname); monfd->fd = fd;
net.c +1 -1
@@ -640,7 +640,7 @@ VLANState *qemu_find_vlan(int id, int allocate)return NULL ; } - vlan =g_malloc0 (sizeof (VLANState)); + vlan =g_new0 (VLANState,1 ); vlan->id = id;QTAILQ_INIT (&vlan->clients);
net/queue.c +1 -1
@@ -63,7 +63,7 @@ NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver, {NetQueue *queue; - queue =g_malloc0 (sizeof (NetQueue)); + queue =g_new0 (NetQueue,1 ); queue->deliver = deliver; queue->deliver_iov = deliver_iov;
net/slirp.c +1 -1
@@ -614,7 +614,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, goto fail_syntax; } - fwd =g_malloc (sizeof (struct GuestFwd )); + fwd = g_new(struct GuestFwd, 1);snprintf (buf,sizeof (buf),"guestfwd.tcp.%d" , port); fwd->hd =qemu_chr_new (buf, p,NULL );if (!fwd->hd) {
net/socket.c +1 -1
@@ -404,7 +404,7 @@ static int net_socket_listen_init(VLANState *vlan,if (parse_host_port (&saddr, host_str) <0 )return -1 ; - s =g_malloc0 (sizeof (NetSocketListenState)); + s =g_new0 (NetSocketListenState,1 ); fd =qemu_socket (PF_INET ,SOCK_STREAM ,0 );if (fd <0 ) {
os-win32.c +1 -1
@@ -62,7 +62,7 @@ static PollingEntry *first_polling_entry;int qemu_add_polling_cb (PollingFunc *func,void *opaque) {PollingEntry **ppe, *pe; - pe =g_malloc0 (sizeof (PollingEntry)); + pe =g_new0 (PollingEntry,1 ); pe->func = func; pe->opaque = opaque;for (ppe = &first_polling_entry; *ppe !=NULL ; ppe = &(*ppe)->next);
pflib.c +1 -1
@@ -156,7 +156,7 @@ static void convert_generic(QemuPfConv *conv, void *dst, void *src, uint32_t cntQemuPfConv *qemu_pf_conv_get (PixelFormat *dst,PixelFormat *src) { -QemuPfConv *conv =g_malloc0 (sizeof (QemuPfConv)); +QemuPfConv *conv =g_new0 (QemuPfConv,1 ); conv->src = *src; conv->dst = *dst;
posix-aio-compat.c +1 -1
@@ -662,7 +662,7 @@ int paio_init(void)if (posix_aio_state)return 0 ; - s =g_malloc (sizeof (PosixAioState)); + s =g_new (PosixAioState,1 ); s->first_aio =NULL ;if (qemu_pipe (fds) ==-1 ) {
qemu-char.c +20 -20
@@ -222,7 +222,7 @@ static int qemu_chr_open_null(QemuOpts *opts, CharDriverState **_chr) {CharDriverState *chr; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 ); chr->chr_write = null_chr_write; *_chr= chr;
@@ -471,8 +471,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)CharDriverState *chr;MuxDriver *d; - chr =g_malloc0 (sizeof (CharDriverState)); - d =g_malloc0 (sizeof (MuxDriver)); + chr =g_new0 (CharDriverState,1 ); + d =g_new0 (MuxDriver,1 ); chr->opaque = d; d->drv = drv;
@@ -621,8 +621,8 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)CharDriverState *chr;FDCharDriver *s; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (FDCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (FDCharDriver,1 ); s->fd_in = fd_in; s->fd_out = fd_out; chr->opaque = s;
@@ -993,8 +993,8 @@ static int qemu_chr_open_pty(QemuOpts *opts, CharDriverState **_chr)#define q_ptsname (x) ptsname(x)#endif - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (PtyCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (PtyCharDriver,1 );if (openpty (&s->fd, &slave_fd, pty_name,NULL ,NULL ) <0 ) {return -errno;
@@ -1373,11 +1373,11 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)return -errno; } - drv =g_malloc0 (sizeof (ParallelCharDriver)); + drv =g_new0 (ParallelCharDriver,1 ); drv->fd = fd; drv->mode =IEEE1284_MODE_COMPAT ; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 ); chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl; chr->chr_close = pp_close;
@@ -1439,7 +1439,7 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr)return -errno; } - chr =g_malloc0 (sizeof (CharDriverState)); + chr =g_new0 (CharDriverState,1 ); chr->opaque = (void *)(intptr_t )fd; chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl;
@@ -1657,8 +1657,8 @@ static int qemu_chr_open_win(QemuOpts *opts, CharDriverState **_chr)CharDriverState *chr;WinCharState *s; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (WinCharState)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (WinCharState,1 ); chr->opaque = s; chr->chr_write = win_chr_write; chr->chr_close = win_chr_close;
@@ -1759,8 +1759,8 @@ static int qemu_chr_open_win_pipe(QemuOpts *opts, CharDriverState **_chr)CharDriverState *chr;WinCharState *s; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (WinCharState)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (WinCharState,1 ); chr->opaque = s; chr->chr_write = win_chr_write; chr->chr_close = win_chr_close;
@@ -1781,8 +1781,8 @@ static int qemu_chr_open_win_file(HANDLE fd_out, CharDriverState **pchr)CharDriverState *chr;WinCharState *s; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (WinCharState)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (WinCharState,1 ); s->hcom = fd_out; chr->opaque = s; chr->chr_write = win_chr_write;
@@ -1895,8 +1895,8 @@ static int qemu_chr_open_udp(QemuOpts *opts, CharDriverState **_chr)int fd =-1 ;int ret; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (NetCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (NetCharDriver,1 ); fd =inet_dgram_opts (opts);if (fd <0 ) {
@@ -2233,8 +2233,8 @@ static int qemu_chr_open_socket(QemuOpts *opts, CharDriverState **_chr)if (!is_listen) is_waitconnect =0 ; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (TCPCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (TCPCharDriver,1 );if (is_unix) {if (is_listen) {
qemu-ga.c +1 -1
@@ -610,7 +610,7 @@ int main(int argc, char **argv)become_daemon (pidfile); } - s =g_malloc0 (sizeof (GAState)); + s =g_new0 (GAState,1 ); s->conn_channel =NULL ; s->path = path; s->method = method;
qemu-img.c +1 -1
@@ -750,7 +750,7 @@ static int img_convert(int argc, char **argv)qemu_progress_init (progress,2.0 );qemu_progress_print (0 ,100 ); - bs =g_malloc0 (bs_n *sizeof (BlockDriverState *)); + bs = g_new0(BlockDriverState *, bs_n); total_sectors =0 ;for (bs_i =0 ; bs_i < bs_n; bs_i++) {
qemu-nbd.c +1 -1
@@ -430,7 +430,7 @@ int main(int argc, char **argv)/* children */ } - sharing_fds =g_malloc ((shared +1 ) *sizeof (int )); + sharing_fds =g_new (int, (shared +1 ));if (socket) { sharing_fds[0 ] =unix_socket_incoming (socket);
qemu-timer.c +2 -2
@@ -364,7 +364,7 @@ static QEMUClock *qemu_new_clock(int type) {QEMUClock *clock; - clock =g_malloc0 (sizeof (QEMUClock)); + clock =g_new0 (QEMUClock,1 ); clock->type = type; clock->enabled =1 ;notifier_list_init (&clock->reset_notifiers);
@@ -469,7 +469,7 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, {QEMUTimer *ts; - ts =g_malloc0 (sizeof (QEMUTimer)); + ts =g_new0 (QEMUTimer,1 ); ts->clock = clock; ts->cb = cb; ts->opaque = opaque;
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/guest-agent-commands.c +5 -5
@@ -56,7 +56,7 @@ void qmp_guest_ping(Error **err)struct GuestAgentInfo *qmp_guest_info (Error **err) { -GuestAgentInfo *info =g_malloc0 (sizeof (GuestAgentInfo)); +GuestAgentInfo *info =g_new0 (GuestAgentInfo,1 ); info->version =g_strdup (QGA_VERSION );
@@ -114,7 +114,7 @@ static void guest_file_handle_add(FILE *fh) {GuestFileHandle *gfh; - gfh =g_malloc0 (sizeof (GuestFileHandle)); + gfh =g_new0 (GuestFileHandle,1 ); gfh->id =fileno (fh); gfh->fh = fh;QTAILQ_INSERT_TAIL (&guest_file_state.filehandles, gfh, next);
@@ -217,7 +217,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,error_set (err,QERR_QGA_COMMAND_FAILED ,"fread() failed" ); }else { buf[read_count] =0 ; - read_data =g_malloc0 (sizeof (GuestFileRead)); + read_data =g_new0 (GuestFileRead,1 ); read_data->count = read_count; read_data->eof =feof (fh);if (read_count) {
@@ -261,7 +261,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,slog ("guest-file-write failed, handle: %ld" , handle);error_set (err,QERR_QGA_COMMAND_FAILED ,"fwrite() error" ); }else { - write_data =g_malloc0 (sizeof (GuestFileWrite)); + write_data =g_new0 (GuestFileWrite,1 ); write_data->count = write_count; write_data->eof =feof (fh); }
@@ -379,7 +379,7 @@ static int guest_fsfreeze_build_mount_list(void)continue ; } - mount =g_malloc0 (sizeof (GuestFsfreezeMount)); + mount =g_new0 (GuestFsfreezeMount,1 ); mount->dirname =g_strdup (ment->mnt_dir); mount->devtype =g_strdup (ment->mnt_type);
savevm.c +8 -8
@@ -255,7 +255,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileStdio)); + s =g_new0 (QEMUFileStdio,1 ); s->stdio_file = stdio_file;
@@ -303,7 +303,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileStdio)); + s =g_new0 (QEMUFileStdio,1 ); s->stdio_file =fdopen (fd, mode);if (!s->stdio_file) goto fail;
@@ -324,7 +324,7 @@ fail:QEMUFile *qemu_fopen_socket (int fd) { -QEMUFileSocket *s =g_malloc0 (sizeof (QEMUFileSocket)); +QEMUFileSocket *s =g_new0 (QEMUFileSocket,1 ); s->fd = fd; s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close,
@@ -358,7 +358,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)return NULL ; } - s =g_malloc0 (sizeof (QEMUFileStdio)); + s =g_new0 (QEMUFileStdio,1 ); s->stdio_file =fopen (filename, mode);if (!s->stdio_file)
@@ -411,7 +411,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, {QEMUFile *f; - f =g_malloc0 (sizeof (QEMUFile)); + f =g_new0 (QEMUFile,1 ); f->opaque = opaque; f->put_buffer = put_buffer;
@@ -1114,7 +1114,7 @@ int register_savevm_live(DeviceState *dev, {SaveStateEntry *se; - se =g_malloc0 (sizeof (SaveStateEntry)); + se =g_new0 (SaveStateEntry,1 ); se->version_id = version_id; se->section_id = global_section_id++; se->set_params = set_params;
@@ -1225,7 +1225,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,/* If this triggers, alias support can be dropped for the vmsd. */ assert (alias_id ==-1 || required_for_version >= vmsd->minimum_version_id); - se =g_malloc0 (sizeof (SaveStateEntry)); + se =g_new0 (SaveStateEntry,1 ); se->version_id = vmsd->version_id; se->section_id = global_section_id++; se->save_live_state =NULL ;
@@ -2141,7 +2141,7 @@ void do_info_snapshots(Monitor *mon)return ; } - available_snapshots =g_malloc0 (sizeof (int ) * nb_sns); + available_snapshots =g_new0 (int, nb_sns); total =0 ;for (i =0 ; i < nb_sns; i++) { sn = &sn_tab[i];
slirp/slirp.c +1 -1
@@ -202,7 +202,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, const char *bootfile, struct in_addr vdhcp_start, struct in_addr vnameserver, void *opaque) { - Slirp *slirp = g_malloc0(sizeof(Slirp)); + Slirp *slirp = g_new0(Slirp, 1);slirp_init_once ();
spice-qemu-char.c +2 -2
@@ -185,8 +185,8 @@ int qemu_chr_open_spice(QemuOpts *opts, CharDriverState **_chr)return -EINVAL ; } - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (SpiceCharDriver)); + chr =g_new0 (CharDriverState,1 ); + s =g_new0 (SpiceCharDriver,1 ); s->chr = chr; s->debug = debug; s->active = false;
target-alpha/translate.c +1 -1
@@ -3494,7 +3494,7 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)CPUAlphaState *env;int implver, amask, i, max; - env =g_malloc0 (sizeof (CPUAlphaState)); + env =g_new0 (CPUAlphaState,1 );cpu_exec_init (env);alpha_translate_init ();tlb_flush (env,1 );
target-arm/helper.c +1 -1
@@ -384,7 +384,7 @@ CPUARMState *cpu_arm_init(const char *cpu_model) id =cpu_arm_find_by_name (cpu_model);if (id ==0 )return NULL ; - env =g_malloc0 (sizeof (CPUARMState)); + env =g_new0 (CPUARMState,1 );cpu_exec_init (env);if (!inited) { inited =1 ;
target-cris/translate.c +1 -1
@@ -3516,7 +3516,7 @@ CPUCRISState *cpu_cris_init (const char *cpu_model)static int tcg_initialized =0 ;int i; - env =g_malloc0 (sizeof (CPUCRISState)); + env =g_new0 (CPUCRISState,1 ); env->pregs[PR_VR ] =vr_by_name (cpu_model);cpu_exec_init (env);
target-i386/cpuid.c +1 -1
@@ -1009,7 +1009,7 @@ static int cpudef_setfield(const char *name, const char *str, void *opaque)*/ static int cpudef_register (QemuOpts *opts,void *opaque) { -x86_def_t *def =g_malloc0 (sizeof (x86_def_t)); +x86_def_t *def =g_new0 (x86_def_t,1 );qemu_opt_foreach (opts, cpudef_setfield, def,1 ); def->next = x86_defs;
target-i386/helper.c +1 -1
@@ -1239,7 +1239,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)CPUX86State *env;static int inited; - env =g_malloc0 (sizeof (CPUX86State)); + env =g_new0 (CPUX86State,1 );cpu_exec_init (env); env->cpu_model_str = cpu_model;
target-i386/kvm.c +1 -1
@@ -201,7 +201,7 @@ static void kvm_hwpoison_page_add(ram_addr_t ram_addr)return ; } } - page =g_malloc (sizeof (HWPoisonPage)); + page =g_new (HWPoisonPage,1 ); page->ram_addr = ram_addr;QLIST_INSERT_HEAD (&hwpoison_page_list, page, list); }
target-lm32/helper.c +1 -1
@@ -208,7 +208,7 @@ CPUState *cpu_lm32_init(const char *cpu_model)return NULL ; } - env =g_malloc0 (sizeof (CPUState)); + env =g_new0 (CPUState,1 ); env->features = def->features; env->num_bps = def->num_breakpoints;
target-m68k/helper.c +1 -1
@@ -172,7 +172,7 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model)CPUM68KState *env;static int inited; - env =g_malloc0 (sizeof (CPUM68KState)); + env =g_new0 (CPUM68KState,1 );cpu_exec_init (env);if (!inited) { inited =1 ;
target-microblaze/translate.c +1 -1
@@ -1851,7 +1851,7 @@ CPUState *cpu_mb_init (const char *cpu_model)static int tcg_initialized =0 ;int i; - env =g_malloc0 (sizeof (CPUState)); + env =g_new0 (CPUState,1 );cpu_exec_init (env);cpu_reset (env);
target-mips/translate.c +1 -1
@@ -12704,7 +12704,7 @@ CPUMIPSState *cpu_mips_init (const char *cpu_model) def =cpu_mips_find_by_name (cpu_model);if (!def)return NULL ; - env =g_malloc0 (sizeof (CPUMIPSState)); + env =g_new0 (CPUMIPSState,1 ); env->cpu_model = def; env->cpu_model_str = cpu_model;
target-ppc/helper.c +1 -1
@@ -3184,7 +3184,7 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)if (!def)return NULL ; - env =g_malloc0 (sizeof (CPUPPCState)); + env =g_new0 (CPUPPCState,1 );cpu_exec_init (env);if (tcg_enabled ()) {ppc_translate_init ();
target-s390x/helper.c +1 -1
@@ -79,7 +79,7 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)static int inited =0 ;static int cpu_num =0 ; - env =g_malloc0 (sizeof (CPUS390XState)); + env =g_new0 (CPUS390XState,1 );cpu_exec_init (env);if (tcg_enabled () && !inited) { inited =1 ;
target-sh4/translate.c +1 -1
@@ -279,7 +279,7 @@ CPUSH4State *cpu_sh4_init(const char *cpu_model) def =cpu_sh4_find_by_name (cpu_model);if (!def)return NULL ; - env =g_malloc0 (sizeof (CPUSH4State)); + env =g_new0 (CPUSH4State,1 ); env->features = def->features;cpu_exec_init (env); env->movcal_backup_tail = &(env->movcal_backup);
target-sparc/helper.c +1 -1
@@ -1208,7 +1208,7 @@ CPUSPARCState *cpu_sparc_init(const char *cpu_model) {CPUSPARCState *env; - env =g_malloc0 (sizeof (CPUSPARCState)); + env =g_new0 (CPUSPARCState,1 );cpu_exec_init (env);gen_intermediate_code_init (env);
target-unicore32/helper.c +1 -1
@@ -53,7 +53,7 @@ CPUState *uc32_cpu_init(const char *cpu_model)uint32_t id;static int inited =1 ; - env =g_malloc0 (sizeof (CPUState)); + env =g_new0 (CPUState,1 );cpu_exec_init (env); id =uc32_cpu_find_by_name (cpu_model);
tcg/tcg.c +2 -2
@@ -243,8 +243,8 @@ void tcg_context_init(TCGContext *s) total_args += n; } - args_ct =g_malloc (sizeof (TCGArgConstraint) * total_args); - sorted_args =g_malloc (sizeof (int ) * total_args); + args_ct =g_new (TCGArgConstraint, total_args); + sorted_args =g_new (int, total_args);for (op =0 ; op <NB_OPS ; op++) { def = &tcg_op_defs[op];
test-qmp-commands.c +7 -7
@@ -15,15 +15,15 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp)UserDefTwo *qmp_user_def_cmd2 (UserDefOne * ud1a,UserDefOne * ud1b,Error **errp) {UserDefTwo *ret; -UserDefOne *ud1c =g_malloc0 (sizeof (UserDefOne)); -UserDefOne *ud1d =g_malloc0 (sizeof (UserDefOne)); +UserDefOne *ud1c =g_new0 (UserDefOne,1 ); +UserDefOne *ud1d =g_new0 (UserDefOne,1 ); ud1c->string =strdup (ud1a->string); ud1c->integer = ud1a->integer; ud1d->string =strdup (ud1b->string); ud1d->integer = ud1b->integer; - ret =g_malloc0 (sizeof (UserDefTwo)); + ret =g_new0 (UserDefTwo,1 ); ret->string =strdup ("blah1" ); ret->dict.string =strdup ("blah2" ); ret->dict.dict.userdef = ud1c;
@@ -104,21 +104,21 @@ static void test_dealloc_types(void)UserDefOne *ud1test, *ud1a, *ud1b;UserDefOneList *ud1list; - ud1test =g_malloc0 (sizeof (UserDefOne)); + ud1test =g_new0 (UserDefOne,1 ); ud1test->integer =42 ; ud1test->string =g_strdup ("hi there 42" );qapi_free_UserDefOne (ud1test); - ud1a =g_malloc0 (sizeof (UserDefOne)); + ud1a =g_new0 (UserDefOne,1 ); ud1a->integer =43 ; ud1a->string =g_strdup ("hi there 43" ); - ud1b =g_malloc0 (sizeof (UserDefOne)); + ud1b =g_new0 (UserDefOne,1 ); ud1b->integer =44 ; ud1b->string =g_strdup ("hi there 44" ); - ud1list =g_malloc0 (sizeof (UserDefOneList)); + ud1list =g_new0 (UserDefOneList,1 ); ud1list->value = ud1a; ud1list->next =g_malloc0 (sizeof (UserDefOneList)); ud1list->next->value = ud1b;
test-visitor.c +1 -1
@@ -282,7 +282,7 @@ static void test_nested_enums(void)QObject *obj;QString *str; - nested_enums =g_malloc0 (sizeof (NestedEnumsOne)); + nested_enums =g_new0 (NestedEnumsOne,1 ); nested_enums->enum1 =ENUM_ONE_VALUE1 ; nested_enums->enum2 =ENUM_ONE_VALUE2 ; nested_enums->enum3 =ENUM_ONE_VALUE3 ;
ui/keymaps.c +1 -1
@@ -94,7 +94,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, filename =qemu_find_file (QEMU_FILE_TYPE_KEYMAP , language);if (!k) - k =g_malloc0 (sizeof (kbd_layout_t)); + k =g_new0 (kbd_layout_t,1 );if (!(filename && (f =fopen (filename,"r" )))) {fprintf (stderr,"Could not read keymap file: '%s'\n" , language);
ui/sdl.c +2 -2
@@ -1019,7 +1019,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)sdl_grab_start (); } - dcl =g_malloc0 (sizeof (DisplayChangeListener)); + dcl =g_new0 (DisplayChangeListener,1 ); dcl->dpy_update = sdl_update; dcl->dpy_resize = sdl_resize; dcl->dpy_refresh = sdl_refresh;
@@ -1029,7 +1029,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) ds->cursor_define = sdl_mouse_define;register_displaychangelistener (ds, dcl); - da =g_malloc0 (sizeof (DisplayAllocator)); + da =g_new0 (DisplayAllocator,1 ); da->create_displaysurface = sdl_create_displaysurface; da->resize_displaysurface = sdl_resize_displaysurface; da->free_displaysurface = sdl_free_displaysurface;
ui/vnc-jobs-async.c +3 -3
@@ -77,7 +77,7 @@ static void vnc_unlock_queue(VncJobQueue *queue)VncJob *vnc_job_new (VncState *vs) { -VncJob *job =g_malloc0 (sizeof (VncJob)); +VncJob *job =g_new0 (VncJob,1 ); job->vs = vs;vnc_lock_queue (queue);
@@ -88,7 +88,7 @@ VncJob *vnc_job_new(VncState *vs)int vnc_job_add_rect (VncJob *job,int x,int y,int w,int h) { -VncRectEntry *entry =g_malloc0 (sizeof (VncRectEntry)); +VncRectEntry *entry =g_new0 (VncRectEntry,1 ); entry->rect.x = x; entry->rect.y = y;
@@ -282,7 +282,7 @@ disconnected:static VncJobQueue *vnc_queue_init (void ) { -VncJobQueue *queue =g_malloc0 (sizeof (VncJobQueue)); +VncJobQueue *queue =g_new0 (VncJobQueue,1 );qemu_cond_init (&queue->cond);qemu_mutex_init (&queue->mutex);
ui/vnc.c +2 -2
@@ -2496,7 +2496,7 @@ static void vnc_remove_timer(VncDisplay *vd)static void vnc_connect (VncDisplay *vd,int csock,int skipauth) { -VncState *vs =g_malloc0 (sizeof (VncState)); +VncState *vs =g_new0 (VncState,1 );int i; vs->csock = csock;
@@ -2578,7 +2578,7 @@ void vnc_display_init(DisplayState *ds) {VncDisplay *vs =g_new0 (VncDisplay,1 ); - dcl =g_malloc0 (sizeof (DisplayChangeListener)); + dcl =g_new0 (DisplayChangeListener,1 ); ds->opaque = vs; dcl->idle =1 ;
usb-linux.c +1 -1
@@ -287,7 +287,7 @@ struct AsyncURBstatic AsyncURB *async_alloc (USBHostDevice *s) { -AsyncURB *aurb =g_malloc0 (sizeof (AsyncURB)); +AsyncURB *aurb =g_new0 (AsyncURB,1 ); aurb->hdev = s;QLIST_INSERT_HEAD (&s->aurbs, aurb, next);return aurb;
usb-redir.c +1 -1
@@ -286,7 +286,7 @@ static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p)static struct buf_packet *bufp_alloc (USBRedirDevice *dev,uint8_t *data,int len,int status,uint8_t ep) { -struct buf_packet *bufp =g_malloc (sizeof (struct buf_packet )); + struct buf_packet *bufp = g_new(struct buf_packet, 1); bufp->data = data; bufp->len = len; bufp->status = status;
vl.c +4 -4
@@ -564,7 +564,7 @@ static struct bt_scatternet_s *qemu_find_bt_vlan(int id)if (vlan->id == id)return &vlan->net; } - vlan =g_malloc0 (sizeof (struct bt_vlan_s )); + vlan = g_new0(struct bt_vlan_s, 1); vlan->id = id; pvlan = &first_bt_vlan;while (*pvlan !=NULL )
@@ -853,7 +853,7 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,assert (dev !=NULL || suffix !=NULL ); - node =g_malloc0 (sizeof (FWBootEntry)); + node =g_new0 (FWBootEntry,1 ); node->bootindex = bootindex; node->suffix = suffix ?g_strdup (suffix) :NULL ; node->dev = dev;
@@ -1112,7 +1112,7 @@ void pcmcia_socket_register(PCMCIASocket *socket) {struct pcmcia_socket_entry_s *entry; - entry =g_malloc (sizeof (struct pcmcia_socket_entry_s )); + entry = g_new(struct pcmcia_socket_entry_s, 1); entry->socket = socket; entry->next = pcmcia_sockets; pcmcia_sockets = entry;
@@ -1339,7 +1339,7 @@ static bool qemu_vmstop_requested(RunState *r)void qemu_register_reset (QEMUResetHandler *func,void *opaque) { -QEMUResetEntry *re =g_malloc0 (sizeof (QEMUResetEntry)); +QEMUResetEntry *re =g_new0 (QEMUResetEntry,1 ); re->func = func; re->opaque = opaque;
xen-all.c +2 -2
@@ -267,7 +267,7 @@ go_physmap: } } - physmap =g_malloc (sizeof (XenPhysmap)); + physmap =g_new (XenPhysmap,1 ); physmap->start_addr = start_addr; physmap->size = size;
@@ -890,7 +890,7 @@ int xen_hvm_init(void)unsigned long ioreq_pfn;XenIOState *state; - state =g_malloc0 (sizeof (XenIOState)); + state =g_new0 (XenIOState,1 ); state->xce_handle =xen_xc_evtchn_open (NULL ,0 );if (state->xce_handle ==XC_HANDLER_INITIAL_VALUE ) {
xen-mapcache.c +5 -5
@@ -94,7 +94,7 @@ void xen_map_cache_init(void)unsigned long size;struct rlimit rlimit_as; - mapcache =g_malloc0 (sizeof (MapCache)); + mapcache =g_new0 (MapCache,1 );QTAILQ_INIT (&mapcache->locked_entries); mapcache->last_address_index =-1 ;
@@ -145,8 +145,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,trace_xen_remap_bucket (address_index); - pfns =g_malloc0 (nb_pfn *sizeof (xen_pfn_t)); - err =g_malloc0 (nb_pfn *sizeof (int )); + pfns =g_new0 (xen_pfn_t, nb_pfn); + err =g_new0 (int, nb_pfn);if (entry->vaddr_base !=NULL ) {if (munmap (entry->vaddr_base, entry->size) !=0 ) {
@@ -220,7 +220,7 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, entry = entry->next; }if (!entry) { - entry =g_malloc0 (sizeof (MapCacheEntry)); + entry =g_new0 (MapCacheEntry,1 ); pentry->next = entry;xen_remap_bucket (entry, __size, address_index); }else if (!entry->lock) {
@@ -242,7 +242,7 @@ uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, mapcache->last_address_index = address_index; mapcache->last_address_vaddr = entry->vaddr_base;if (lock) { -MapCacheRev *reventry =g_malloc0 (sizeof (MapCacheRev)); +MapCacheRev *reventry =g_new0 (MapCacheRev,1 ); entry->lock++; reventry->vaddr_req = mapcache->last_address_vaddr + address_offset; reventry->paddr_index = mapcache->last_address_index;
Signature · 1 line
1.7.4.1
PATCH 4/5 Convert remaining calls to g_malloc(sizeof(type)) using casts to g_new()
In reply to Stuart BradyConvert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the return value is casted to the same type as specified using sizeof(type) as passed to g_malloc().
Coccinelle did not match these when matching assignments involving an expression corresponding to the type used for determining the size to allocate. Such cases deserve more careful review, in case the types do not match, so are submitted separately.
This was achieved using Coccinelle with the following semantic patch:
@@ type T; @@
-(T *)g_malloc(sizeof(T))
+g_new(T, 1)
@@ type T; @@
-(T *)g_malloc0(sizeof(T))
+g_new0(T, 1)
@@ type T; expression N; @@
-(T *)g_malloc(sizeof(T) * N)
+g_new(T, N)
@@ type T; expression N; @@
-(T *)g_malloc0(sizeof(T) * N)
+g_new0(T, N)
--- hw/sd.c | 2 +- libcacard/vcard_emul_nss.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/sd.c +1 -1
@@ -410,7 +410,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)if (sd->wp_groups)g_free (sd->wp_groups); sd->wp_switch = bdrv ?bdrv_is_read_only (bdrv) :0 ; - sd->wp_groups = (int *)g_malloc0 (sizeof (int ) * sect); + sd->wp_groups =g_new0 (int, sect);memset (sd->function_group,0 ,sizeof (int ) *6 ); sd->erase_start =0 ; sd->erase_end =0 ;
libcacard/vcard_emul_nss.c +1 -1
@@ -1180,7 +1180,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,",)" );
Signature · 1 line
1.7.4.1
PATCH 5/5 Convert remaining calls to g_malloc(sizeof(type)) to g_new()
In reply to Stuart BradyConvert calls to g_malloc() and g_malloc0() to g_new() and g_new0() respectively, in cases where the size passed to g_malloc() is specified as sizeof(type).
Coccinelle did not match these when matching assignments involving an expression corresponding to the type used for determining the size to allocate. Such cases deserve more careful review, in case the types do not match, so are submitted separately.
This was achieved using Coccinelle with the following semantic patch:
@@ 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)
Note: changes to omap_l4_io_readb_fn, etc in hw/omap_l4.c have been withheld since the size of the wrong type of pointer is specified. This should not cause a problem as all types of pointer will have the same size on any architecture that we care about, but this should be fixed properly in a separate patch.
Also note that the allocation of seek_data in ga/guest-agent-commands.c is not fixed because it should use GuestFileSeek, not GuestFileRead. This should be fixed separately.
Finally, cris-dis.c appears to perform allocations using the wrong pointer type. This should also be fixed separately.
--- block/qcow2-snapshot.c | 2 +- block/vvfat.c | 2 +- bsd-user/syscall.c | 2 +- cpus.c | 8 ++++---- hw/ide/ahci.c | 2 +- hw/intel-hda.c | 2 +- hw/lsi53c895a.c | 2 +- hw/virtio-serial-bus.c | 4 ++-- hw/virtio.c | 2 +- linux-user/elfload.c | 2 +- monitor.c | 2 +- savevm.c | 4 ++-- test-qmp-commands.c | 2 +- ui/vnc.c | 2 +- xen-all.c | 2 +- 15 files changed, 20 insertions(+), 20 deletions(-)
block/qcow2-snapshot.c +1 -1
@@ -76,7 +76,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++) { offset =align_offset (offset,8 );if (bdrv_pread (bs->file, offset, &h,sizeof (h)) !=sizeof (h))
block/vvfat.c +1 -1
@@ -2782,7 +2782,7 @@ static int enable_write_target(BDRVVVFATState *s) s->bs->backing_hd =calloc (sizeof (BlockDriverState),1 ); 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 ;
bsd-user/syscall.c +1 -1
@@ -231,7 +231,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)
cpus.c +4 -4
@@ -818,8 +818,8 @@ static void qemu_tcg_init_vcpu(void *_env)/* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { - env->thread =g_malloc0 (sizeof (QemuThread)); - env->halt_cond =g_malloc0 (sizeof (QemuCond)); + env->thread =g_new0 (QemuThread,1 ); + env->halt_cond =g_new0 (QemuCond,1 );qemu_cond_init (env->halt_cond); tcg_halt_cond = env->halt_cond;qemu_thread_create (env->thread, qemu_tcg_cpu_thread_fn, env);
@@ -835,8 +835,8 @@ static void qemu_tcg_init_vcpu(void *_env)static void qemu_kvm_start_vcpu (CPUState *env) { - env->thread =g_malloc0 (sizeof (QemuThread)); - env->halt_cond =g_malloc0 (sizeof (QemuCond)); + env->thread =g_new0 (QemuThread,1 ); + env->halt_cond =g_new0 (QemuCond,1 );qemu_cond_init (env->halt_cond);qemu_thread_create (env->thread, qemu_kvm_cpu_thread_fn, env);while (env->created ==0 ) {
hw/ide/ahci.c +1 -1
@@ -1164,7 +1164,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, int ports)int i; 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, &ahci_mem_ops, s,"ahci" ,AHCI_MEM_BAR_SIZE );
hw/intel-hda.c +1 -1
@@ -468,7 +468,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 ) {cpu_physical_memory_read (addr, buf,16 ); st->bpl[i].addr =le64_to_cpu (*(uint64_t *)buf);
hw/lsi53c895a.c +1 -1
@@ -778,7 +778,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/virtio-serial-bus.c +2 -2
@@ -862,8 +862,8 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)QTAILQ_INIT (&vser->ports); vser->bus.max_nr_ports = conf->max_virtserial_ports; - vser->ivqs =g_malloc (conf->max_virtserial_ports *sizeof (VirtQueue *)); - vser->ovqs =g_malloc (conf->max_virtserial_ports *sizeof (VirtQueue *)); + vser->ivqs = g_new(VirtQueue *, conf->max_virtserial_ports); + vser->ovqs = g_new(VirtQueue *, conf->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/virtio.c +1 -1
@@ -871,7 +871,7 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, 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 ;
linux-user/elfload.c +1 -1
@@ -2488,7 +2488,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));
monitor.c +1 -1
@@ -5124,7 +5124,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);
savevm.c +2 -2
@@ -1132,7 +1132,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;
@@ -1243,7 +1243,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;
test-qmp-commands.c +1 -1
@@ -120,7 +120,7 @@ static void test_dealloc_types(void) 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);
ui/vnc.c +1 -1
@@ -2515,7 +2515,7 @@ static void vnc_connect(VncDisplay *vd, int csock, int skipauth) 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);
xen-all.c +1 -1
@@ -924,7 +924,7 @@ int xen_hvm_init(void)hw_error ("map buffered IO page returned error %d" , errno); } - state->ioreq_local_port =g_malloc0 (smp_cpus *sizeof (evtchn_port_t)); + state->ioreq_local_port =g_new0 (evtchn_port_t, smp_cpus);/* FIXME: how about if we overflow the page here? */ for (i =0 ; i < smp_cpus; i++) {
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 5/5] Convert remaining calls to g_malloc(sizeof(type)) to g_new()
Quoted 3 lines · Stuart Brady
Coccinelle did not match these when matching assignments involving an expression corresponding to the type used for determining the size to allocate.
They all look okay, perhaps the include path you passed to Coccinelle is incomplete?
but would be nicer if you fixed the problem.
Paolo
Re: [Qemu-devel] [PATCH 5/5] Convert remaining calls to g_malloc(sizeof(type)) to g_new()
Quoted 7 lines · Paolo Bonzini
Quoted 3 lines · Stuart Brady
Coccinelle did not match these when matching assignments involving an expression corresponding to the type used for determining the size to allocate.
They all look okay, perhaps the include path you passed to Coccinelle is incomplete?
Ah, good point! I'm not sure what include dirs are needed, though... anyone have any advice?
Blue Swirl, I gather you're one of the few other people to have used Coccinelle with Qemu's source...
Quoted 3 lines
Reviewed-by Paolo Bonzini <[email protected]>but would be nicer if you fixed the problem.
Agreed... I'm new to Coccinelle, but I'll experiment and see if I can produce a better patch. After applying my patch series, it seems there are still some additional calls that need converting, so I can readily believe that the semantic patches I've used can be improved!
Cheers,
Signature · 1 line
Stuart
Re: [Qemu-devel] [PATCH 5/5] Convert remaining calls to g_malloc(sizeof(type)) to g_new()
Quoted 7 lines · Stuart Brady
Quoted 2 lines
Quoted 2 lines
They all look okay, perhaps the include path you passed to Coccinelle is incomplete?
Ah, good point! I'm not sure what include dirs are needed, though... anyone have any advice?
Blue Swirl, I gather you're one of the few other people to have used Coccinelle with Qemu's source...
I played a bit yesterday and it turns out that Coccinelle is a bit limited WRT handling headers, because they are very expensive. I used "-I . -I +build -I hw" but it didn't help much.
Stuart/Blue, do you have a macro file? Mine was simply "#define coroutine_fn".
Paolo
Re: [Qemu-devel] [PATCH 5/5] Convert remaining calls to g_malloc(sizeof(type)) to g_new()
Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Stuart Brady
Quoted 2 lines
Quoted 2 lines
They all look okay, perhaps the include path you passed to Coccinelle is incomplete?
Ah, good point! I'm not sure what include dirs are needed, though... anyone have any advice?
Blue Swirl, I gather you're one of the few other people to have used Coccinelle with Qemu's source...
Quoted 6 lines
I played a bit yesterday and it turns out that Coccinelle is a bit limited WRT handling headers, because they are very expensive. I used "-I . -I +build -I hw" but it didn't help much.
Stuart/Blue, do you have a macro file? Mine was simply "#define
coroutine_fn".
I didn't even have that, but Coccinelle didn't seem to mind...
It did occur to me that since a lot of Qemu's source is recompiled with different macro definitions for different targets, we need to be really careful about what we do regarding includes. Hopefully the names of types that are used won't vary between targets, though.
Submitting what Coccinelle could process successfully and fixing up the rest manually seemed reasonable, but I'd like to be as confident as possible of these changes.
BTW, I'd thought that noone would ever do E = (T *)g_malloc(sizeof(*E)), but from looking hw/blizzard.c, hw/cbus.c and hw/nseries.c, it seems that this isn't quite the case afterall! I'll be sure to include this in my second attempt, once QEMU 1.0 has been released.
One thing that did not occur to me is use of E = malloc(sizeof(*E1)) or E = malloc(sizeof(T1)) where E is of type void *, but E1 or T1 is not what was intended.
I'm also somewhat astonished to find that sizeof(void) and sizeof(*E) where E is of type void * both compile! It would probably make sense to check for these.
Any remaining calls to g_malloc() would be then be reviewed to make sure that they're all correct.
We could also perhaps search for places where free() is called on memory that is allocated with g_malloc(), as g_free() should be used instead.
---
Some background on my thinking before sending the patch series:
(T *)g_malloc(sizeof(T)) can obviously be safely replaced with g_new(T, 1) since that's what g_new(T, 1) expands to.
Replacing E = g_malloc(sizeof(*E)) with E = g_new(T, 1) adds a cast, but the cast does not provide any extra safety, since sizeof(*T) is pretty much certain to be the correct size (unless T = void *). There seems to be some agreement that this is more readable, though.
Replacing E = g_malloc(sizeof(T)) without a cast with E = g_new(T, 1) effectively just adds a cast to T *, which might result in additional compilation warnings (which are turned into errors) but should have no other effect, so this should be perfectly safe.
Other cases where g_malloc(sizeof(*E)) or g_malloc(sizeof(T)) is used will either be due to Coccinelle not understanding the types, or due to a bug in Qemu, and both of these cases need special consideration.
Cheers,
Signature · 1 line
Stuart
Re: [Qemu-devel] [PATCH 5/5] Convert remaining calls to g_malloc(sizeof(type)) to g_new()
In reply to Stuart BradyQuoted 6 lines · Stuart Brady
Quoted 5 lines · Paolo Bonzini
Quoted 3 lines · Stuart Brady
Coccinelle did not match these when matching assignments involving an expression corresponding to the type used for determining the size to allocate.
Quoted 8 lines
Quoted 2 lines
They all look okay, perhaps the include path you passed to Coccinelle is incomplete?
Ah, good point! I'm not sure what include dirs are needed, though... anyone have any advice?
Blue Swirl, I gather you're one of the few other people to have used Coccinelle with Qemu's source...
Yes, but I can't find the commands from command line history, sorry. Note to self: always make scripts from complex command invocations and remember to use the Internet mirrors for storage.
Quoted 14 lines
Quoted 3 lines
Reviewed-by Paolo Bonzini <[email protected]>but would be nicer if you fixed the problem.
Agreed... I'm new to Coccinelle, but I'll experiment and see if I can produce a better patch. After applying my patch series, it seems there are still some additional calls that need converting, so I can readily believe that the semantic patches I've used can be improved!
Cheers,
--
Stuart
Quoted 4 lines · Stuart Brady
Convert calls to
g_malloc()andg_malloc0()tog_new()andg_new0()respectively, in cases where the return value is casted to the same type as specified usingsizeof()in the parameter tog_malloc()and assigned to a variable of that type.
This is likely to cause conflicts all over the place, and now is a very bad time to do so :( because people are trying to get their patches in during the soft feature freeze. I don't oppose the change, just the timing.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 4 lines · Stuart Brady
Convert calls to
g_malloc()andg_malloc0()tog_new()andg_new0()respectively, in cases where the return value is casted to the same type as specified usingsizeof()in the parameter tog_malloc()and assigned to a variable of that type.This is likely to cause conflicts all over the place, and now is a very bad time to do so :( because people are trying to get their patches in during the soft feature freeze. I don't oppose the change, just the timing.
That makes sense.
Perhaps I should just submit a patch for the allocation of GuestFileRead (which should be GuestFileSeek) in that case -- although since that's benign, I could just wait a little while longer.
Cheers,
Signature · 1 line
Stuart