Re: [Qemu-devel] [PATCH 23/88] M68K: use g_new() family of functions

2017-10-06 Thread Thomas Huth
Am Fri,  6 Oct 2017 20:49:18 -0300
schrieb Philippe Mathieu-Daudé :

> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 
> [PMD: squashed commits]
> ---
>  hw/m68k/mcf5206.c | 4 ++--
>  hw/m68k/mcf5208.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH 59/88] ppce500: use g_new() family of functions

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 08:49:54PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 
> [PMD: replaced g_new0() -> g_new() since no bzero() required]

Acked-by: David Gibson 

> ---
>  hw/ppc/e500.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index db0e49ab8f..b396fd1a22 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -737,8 +737,6 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, 
> PPCE500Params *params,
>  SysBusDevice *s;
>  int i;
>  
> -mpic = g_new0(qemu_irq, 256);
> -
>  if (kvm_enabled()) {
>  Error *err = NULL;
>  
> @@ -756,6 +754,7 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, 
> PPCE500Params *params,
>  dev = ppce500_init_mpic_qemu(params, irqs);
>  }
>  
> +mpic = g_new(qemu_irq, 256);
>  for (i = 0; i < 256; i++) {
>  mpic[i] = qdev_get_gpio_in(dev, i);
>  }
> @@ -808,7 +807,7 @@ void ppce500_init(MachineState *machine, PPCE500Params 
> *params)
>  machine->cpu_model = "e500v2_v30";
>  }
>  
> -irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
> +irqs = g_new0(qemu_irq *, smp_cpus);
>  irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
>  for (i = 0; i < smp_cpus; i++) {
>  PowerPCCPU *cpu;
> @@ -844,7 +843,7 @@ void ppce500_init(MachineState *machine, PPCE500Params 
> *params)
>  if (!i) {
>  /* Primary CPU */
>  struct boot_info *boot_info;
> -boot_info = g_malloc0(sizeof(struct boot_info));
> +boot_info = g_new0(struct boot_info, 1);
>  qemu_register_reset(ppce500_cpu_reset, cpu);
>  env->load_info = boot_info;
>  } else {

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 58/88] ppc4xx: use g_new() family of functions

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 08:49:53PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 
> [PMD: added more changes in hw/ppc/ppc405_uc.c and hw/ppc/ppc4xx_devs.c]

Acked-by: David Gibson 

> ---
>  hw/ppc/ppc405_boards.c |  4 ++--
>  hw/ppc/ppc405_uc.c | 24 
>  hw/ppc/ppc440_bamboo.c |  2 +-
>  hw/ppc/ppc4xx_devs.c   |  6 +++---
>  4 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
> index e92db2c66a..a812985baa 100644
> --- a/hw/ppc/ppc405_boards.c
> +++ b/hw/ppc/ppc405_boards.c
> @@ -169,7 +169,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, 
> uint32_t base)
>  ref405ep_fpga_t *fpga;
>  MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
>  
> -fpga = g_malloc0(sizeof(ref405ep_fpga_t));
> +fpga = g_new0(ref405ep_fpga_t, 1);
>  memory_region_init_io(fpga_memory, NULL, _fpga_ops, fpga,
>"fpga", 0x0100);
>  memory_region_add_subregion(sysmem, base, fpga_memory);
> @@ -472,7 +472,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, 
> uint32_t base)
>  taihu_cpld_t *cpld;
>  MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
>  
> -cpld = g_malloc0(sizeof(taihu_cpld_t));
> +cpld = g_new0(taihu_cpld_t, 1);
>  memory_region_init_io(cpld_memory, NULL, _cpld_ops, cpld, "cpld", 
> 0x100);
>  memory_region_add_subregion(sysmem, base, cpld_memory);
>  qemu_register_reset(_cpld_reset, cpld);
> diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
> index 8e58065f5f..02ab2a24ff 100644
> --- a/hw/ppc/ppc405_uc.c
> +++ b/hw/ppc/ppc405_uc.c
> @@ -181,7 +181,7 @@ void ppc4xx_plb_init(CPUPPCState *env)
>  {
>  ppc4xx_plb_t *plb;
>  
> -plb = g_malloc0(sizeof(ppc4xx_plb_t));
> +plb = g_new0(ppc4xx_plb_t, 1);
>  ppc_dcr_register(env, PLB3A0_ACR, plb, _read_plb, _write_plb);
>  ppc_dcr_register(env, PLB4A0_ACR, plb, _read_plb, _write_plb);
>  ppc_dcr_register(env, PLB0_ACR, plb, _read_plb, _write_plb);
> @@ -266,7 +266,7 @@ static void ppc4xx_pob_init(CPUPPCState *env)
>  {
>  ppc4xx_pob_t *pob;
>  
> -pob = g_malloc0(sizeof(ppc4xx_pob_t));
> +pob = g_new0(ppc4xx_pob_t, 1);
>  ppc_dcr_register(env, POB0_BEAR, pob, _read_pob, _write_pob);
>  ppc_dcr_register(env, POB0_BESR0, pob, _read_pob, _write_pob);
>  ppc_dcr_register(env, POB0_BESR1, pob, _read_pob, _write_pob);
> @@ -397,7 +397,7 @@ static void ppc4xx_opba_init(hwaddr base)
>  {
>  ppc4xx_opba_t *opba;
>  
> -opba = g_malloc0(sizeof(ppc4xx_opba_t));
> +opba = g_new0(ppc4xx_opba_t, 1);
>  #ifdef DEBUG_OPBA
>  printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
>  #endif
> @@ -595,7 +595,7 @@ void ppc405_ebc_init(CPUPPCState *env)
>  {
>  ppc4xx_ebc_t *ebc;
>  
> -ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
> +ebc = g_new0(ppc4xx_ebc_t, 1);
>  qemu_register_reset(_reset, ebc);
>  ppc_dcr_register(env, EBC0_CFGADDR,
>   ebc, _read_ebc, _write_ebc);
> @@ -678,7 +678,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq 
> irqs[4])
>  {
>  ppc405_dma_t *dma;
>  
> -dma = g_malloc0(sizeof(ppc405_dma_t));
> +dma = g_new0(ppc405_dma_t, 1);
>  memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
>  qemu_register_reset(_dma_reset, dma);
>  ppc_dcr_register(env, DMA0_CR0,
> @@ -819,7 +819,7 @@ static void ppc405_gpio_init(hwaddr base)
>  {
>  ppc405_gpio_t *gpio;
>  
> -gpio = g_malloc0(sizeof(ppc405_gpio_t));
> +gpio = g_new0(ppc405_gpio_t, 1);
>  #ifdef DEBUG_GPIO
>  printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
>  #endif
> @@ -981,7 +981,7 @@ static void ppc405_ocm_init(CPUPPCState *env)
>  {
>  ppc405_ocm_t *ocm;
>  
> -ocm = g_malloc0(sizeof(ppc405_ocm_t));
> +ocm = g_new0(ppc405_ocm_t, 1);
>  /* XXX: Size is 4096 or 0x0400 */
>  memory_region_init_ram(>isarc_ram, NULL, "ppc405.ocm", 4096,
> _fatal);
> @@ -1264,7 +1264,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq 
> irqs[5])
>  ppc4xx_gpt_t *gpt;
>  int i;
>  
> -gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
> +gpt = g_new0(ppc4xx_gpt_t, 1);
>  for (i = 0; i < 5; i++) {
>  gpt->irqs[i] = irqs[i];
>  }
> @@ -1590,7 +1590,7 @@ static void ppc405cr_cpc_init (CPUPPCState *env, 
> clk_setup_t clk_setup[7],
>  {
>  ppc405cr_cpc_t *cpc;
>  
> -cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
> +cpc = g_new0(ppc405cr_cpc_t, 1);
>  memcpy(cpc->clk_setup, clk_setup,
> PPC405CR_CLK_NB * sizeof(clk_setup_t));
>  cpc->sysclk = sysclk;
> @@ -1640,7 +1640,7 @@ CPUPPCState *ppc405cr_init(MemoryRegion 
> *address_space_mem,
>  /* OBP arbitrer */
>  ppc4xx_opba_init(0xef600600);
>  /* 

Re: [Qemu-devel] [PATCH] spapr_pci: fail gracefully with non-pseries machine types

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 05:09:04PM +0200, Greg Kurz wrote:
> QEMU currently crashes when the user tries to add a spapr-pci-host-bridge
> on a non-pseries machine:
> 
> $ qemu-system-ppc64 -M ppce500 -device spapr-pci-host-bridge,index=1
> hw/ppc/spapr_pci.c:1535:spapr_phb_realize:
> Object 0x1003dacae60 is not an instance of type spapr-machine
> Aborted (core dumped)
> 
> The same thing happens with the deprecated but still available child type
> spapr-pci-vfio-host-bridge.
> 
> Fix both by checking the machine type with object_dynamic_cast().
> 
> Signed-off-by: Greg Kurz 



> ---
>  hw/ppc/spapr_pci.c |8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 5049ced4e8b4..9e85106f51f8 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1507,7 +1507,7 @@ static void spapr_pci_unplug_request(HotplugHandler 
> *plug_handler,
>  
>  static void spapr_phb_realize(DeviceState *dev, Error **errp)
>  {
> -sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> +sPAPRMachineState *spapr;
>  SysBusDevice *s = SYS_BUS_DEVICE(dev);
>  sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
>  PCIHostState *phb = PCI_HOST_BRIDGE(s);
> @@ -1519,6 +1519,12 @@ static void spapr_phb_realize(DeviceState *dev, Error 
> **errp)
>  const unsigned windows_supported =
>  sphb->ddw_enabled ? SPAPR_PCI_DMA_MAX_WINDOWS : 1;
>  
> +spapr = (sPAPRMachineState *) qdev_get_machine();
> +if (!object_dynamic_cast((Object *) spapr, TYPE_SPAPR_MACHINE)) {
> +error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries 
> machine");
> +return;
> +}

This is slightly clunky.  You could instead use OBJECT_CHECK in the
initializer, then just if (!spapr) here.

> +
>  if (sphb->index != (uint32_t)-1) {
>  sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
>  Error *local_err = NULL;
> 


-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 11:15:31PM +0200, Cédric Le Goater wrote:
> On 10/06/2017 11:07 AM, David Gibson wrote:
> > On Thu, Oct 05, 2017 at 06:49:58PM +0200, Cédric Le Goater wrote:
> >> When a CPU is stopped with the 'stop-self' RTAS call, its state
> >> 'halted' is switched to 1 and, in this case, the MSR is not taken into
> >> account anymore in the cpu_has_work() routine. Only the pending
> >> hardware interrupts are checked with their LPCR:PECE* enablement bit.
> >>
> >> If the DECR timer fires after 'stop-self' is called and before the CPU
> >> 'stop' state is reached, the nearly-dead CPU will have some work to do
> >> and the guest will crash. This case happens very frequently with the
> >> not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is
> >> occasionally fired but after 'stop' state, so no work is to be done
> >> and the guest survives.
> >>
> >> I suspect there is a race between the QEMU mainloop triggering the
> >> timers and the TCG CPU thread but I could not quite identify the root
> >> cause. To be safe, let's disable the decrementer interrupt in the LPCR
> >> when the CPU is halted and reenable it when the CPU is restarted.
> >>
> >> Signed-off-by: Cédric Le Goater 
> >> ---
> >>  hw/ppc/spapr_rtas.c | 16 
> >>  1 file changed, 16 insertions(+)
> >>
> >> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
> >> index cdf0b607a0a0..2389220c9738 100644
> >> --- a/hw/ppc/spapr_rtas.c
> >> +++ b/hw/ppc/spapr_rtas.c
> >> @@ -174,6 +174,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, 
> >> sPAPRMachineState *spapr,
> >>  kvm_cpu_synchronize_state(cs);
> >>  
> >>  env->msr = (1ULL << MSR_SF) | (1ULL << MSR_ME);
> >> +
> >> +/* Enable DECR interrupt */
> >> +if (env->mmu_model == POWERPC_MMU_3_00) {
> > 
> > Hm.  Checking mmu_model doesn't seem right to me.  I mean, it'll get
> > the right answer in practice, but the LPCR programming has nothing
> > whatsoever to do with the MMU.
> > 
> > I think explicitly checking if cpu_ is a POWER9 instance with
> > object_dynamic_cast would be a better option.
> 
> OK. So I guess we should change the switch statement in cpu_ppc_set_papr()
> also.

Yeah, I guess so.  No rush.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 55/88] PReP: use g_new() family of functions

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 08:49:50PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 

Acked-by: David Gibson 

> ---
>  hw/ppc/prep.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> index 94138a4e8c..c638d3d17a 100644
> --- a/hw/ppc/prep.c
> +++ b/hw/ppc/prep.c
> @@ -512,7 +512,7 @@ static void ppc_prep_init(MachineState *machine)
>  int ppc_boot_device;
>  DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
>  
> -sysctrl = g_malloc0(sizeof(sysctrl_t));
> +sysctrl = g_new0(sysctrl_t, 1);
>  
>  linux_boot = (kernel_filename != NULL);
>  

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 57/88] ppc: use g_new() family of functions

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 08:49:52PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 
> [PMD: replaced g_new0() -> g_new() in mac_newworld.c, added
> virtex_ml507]

Acked-by: David Gibson 

> ---
>  hw/intc/heathrow_pic.c | 2 +-
>  hw/ppc/mac_newworld.c  | 5 ++---
>  hw/ppc/mac_oldworld.c  | 2 +-
>  hw/ppc/virtex_ml507.c  | 2 +-
>  4 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/intc/heathrow_pic.c b/hw/intc/heathrow_pic.c
> index 171f5ed814..90c1e6a4b1 100644
> --- a/hw/intc/heathrow_pic.c
> +++ b/hw/intc/heathrow_pic.c
> @@ -201,7 +201,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(>mem, NULL, _pic_ops, s,
> diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
> index 6d0ace20ca..59cded95b8 100644
> --- a/hw/ppc/mac_newworld.c
> +++ b/hw/ppc/mac_newworld.c
> @@ -295,7 +295,7 @@ static void ppc_core99_init(MachineState *machine)
>  memory_region_init_io(unin2_memory, NULL, _ops, token, "unin", 
> 0x1000);
>  memory_region_add_subregion(get_system_memory(), 0xf300, 
> unin2_memory);
>  
> -openpic_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
> +openpic_irqs = g_new0(qemu_irq *, smp_cpus);
>  openpic_irqs[0] =
>  g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
>  for (i = 0; i < smp_cpus; i++) {
> @@ -339,8 +339,6 @@ static void ppc_core99_init(MachineState *machine)
>  }
>  }
>  
> -pic = g_new0(qemu_irq, 64);
> -
>  dev = qdev_create(NULL, TYPE_OPENPIC);
>  qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_KEYLARGO);
>  qdev_init_nofail(dev);
> @@ -353,6 +351,7 @@ static void ppc_core99_init(MachineState *machine)
>  }
>  }
>  
> +pic = g_new(qemu_irq, 64);
>  for (i = 0; i < 64; i++) {
>  pic[i] = qdev_get_gpio_in(dev, i);
>  }
> diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
> index bc7c8b7bd7..50ad9c56cb 100644
> --- a/hw/ppc/mac_oldworld.c
> +++ b/hw/ppc/mac_oldworld.c
> @@ -232,7 +232,7 @@ static void ppc_heathrow_init(MachineState *machine)
>  memory_region_add_subregion(sysmem, 0xfe00, isa);
>  
>  /* XXX: we register only 1 output pin for heathrow PIC */
> -heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
> +heathrow_irqs = g_new0(qemu_irq *, smp_cpus);
>  heathrow_irqs[0] =
>  g_malloc0(smp_cpus * sizeof(qemu_irq) * 1);
>  /* Connect the heathrow PIC outputs to the 6xx bus */
> diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
> index ed9b406fd3..ed6e054611 100644
> --- a/hw/ppc/virtex_ml507.c
> +++ b/hw/ppc/virtex_ml507.c
> @@ -104,7 +104,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t 
> *ram_size,
>  ppc_dcr_init(env, NULL, NULL);
>  
>  /* interrupt controller */
> -irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
> +irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
>  irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq 
> *)env->irq_inputs)[PPC40x_INPUT_INT];
>  irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq 
> *)env->irq_inputs)[PPC40x_INPUT_CINT];
>  ppcuic_init(env, irqs, 0x0C0, 0, 1);

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 56/88] PowerPC: use g_new() family of functions

2017-10-06 Thread David Gibson
On Fri, Oct 06, 2017 at 08:49:51PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 
> [PMD: one more change in target/ppc/translate_init.c, added
> target/ppc/kvm.c]

Acked-by: David Gibson 

> ---
>  hw/ppc/ppc.c|  8 
>  hw/ppc/ppc_booke.c  |  4 ++--
>  target/ppc/kvm.c|  2 +-
>  target/ppc/translate_init.c | 14 +++---
>  4 files changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
> index 05da316e0b..647d70fc13 100644
> --- a/hw/ppc/ppc.c
> +++ b/hw/ppc/ppc.c
> @@ -965,7 +965,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t 
> freq)
>  PowerPCCPU *cpu = ppc_env_get_cpu(env);
>  ppc_tb_t *tb_env;
>  
> -tb_env = g_malloc0(sizeof(ppc_tb_t));
> +tb_env = g_new0(ppc_tb_t, 1);
>  env->tb_env = tb_env;
>  tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
>  if (env->insns_flags & PPC_SEGMENT_64B) {
> @@ -1224,10 +1224,10 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *env, 
> uint32_t freq,
>  ppc_tb_t *tb_env;
>  ppc40x_timer_t *ppc40x_timer;
>  
> -tb_env = g_malloc0(sizeof(ppc_tb_t));
> +tb_env = g_new0(ppc_tb_t, 1);
>  env->tb_env = tb_env;
>  tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
> -ppc40x_timer = g_malloc0(sizeof(ppc40x_timer_t));
> +ppc40x_timer = g_new0(ppc40x_timer_t, 1);
>  tb_env->tb_freq = freq;
>  tb_env->decr_freq = freq;
>  tb_env->opaque = ppc40x_timer;
> @@ -1332,7 +1332,7 @@ int ppc_dcr_init (CPUPPCState *env, int 
> (*read_error)(int dcrn),
>  {
>  ppc_dcr_t *dcr_env;
>  
> -dcr_env = g_malloc0(sizeof(ppc_dcr_t));
> +dcr_env = g_new0(ppc_dcr_t, 1);
>  dcr_env->read_error = read_error;
>  dcr_env->write_error = write_error;
>  env->dcr_env = dcr_env;
> diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c
> index 23bcf1b138..dafc6aa3fc 100644
> --- a/hw/ppc/ppc_booke.c
> +++ b/hw/ppc/ppc_booke.c
> @@ -339,8 +339,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t 
> freq, uint32_t flags)
>  booke_timer_t *booke_timer;
>  int ret = 0;
>  
> -tb_env  = g_malloc0(sizeof(ppc_tb_t));
> -booke_timer = g_malloc0(sizeof(booke_timer_t));
> +tb_env  = g_new0(ppc_tb_t, 1);
> +booke_timer = g_new0(booke_timer_t, 1);
>  
>  cpu->env.tb_env = tb_env;
>  tb_env->flags = flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED;
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 171d3d8040..d8565fd4a3 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -364,7 +364,7 @@ struct ppc_radix_page_info *kvm_get_radix_page_info(void)
>  if (kvm_vm_ioctl(s, KVM_PPC_GET_RMMU_INFO, _info)) {
>  return NULL;
>  }
> -radix_page_info = g_malloc0(sizeof(*radix_page_info));
> +radix_page_info = g_new0(struct ppc_radix_page_info, 1);
>  radix_page_info->count = 0;
>  for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
>  if (rmmu_info.ap_encodings[i]) {
> diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
> index c6399a3a0d..850ff038ca 100644
> --- a/target/ppc/translate_init.c
> +++ b/target/ppc/translate_init.c
> @@ -9341,13 +9341,13 @@ static void init_ppc_proc(PowerPCCPU *cpu)
>  nb_tlb *= 2;
>  switch (env->tlb_type) {
>  case TLB_6XX:
> -env->tlb.tlb6 = g_malloc0(nb_tlb * sizeof(ppc6xx_tlb_t));
> +env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
>  break;
>  case TLB_EMB:
> -env->tlb.tlbe = g_malloc0(nb_tlb * sizeof(ppcemb_tlb_t));
> +env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
>  break;
>  case TLB_MAS:
> -env->tlb.tlbm = g_malloc0(nb_tlb * sizeof(ppcmas_tlb_t));
> +env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
>  break;
>  }
>  /* Pre-compute some useful values */
> @@ -10442,11 +10442,11 @@ static void ppc_cpu_defs_entry(gpointer data, 
> gpointer user_data)
>  }
>  
>  typename = object_class_get_name(oc);
> -info = g_malloc0(sizeof(*info));
> +info = g_new0(CpuDefinitionInfo, 1);
>  info->name = g_strndup(typename,
> strlen(typename) - 
> strlen(POWERPC_CPU_TYPE_SUFFIX));
>  
> -entry = g_malloc0(sizeof(*entry));
> +entry = g_new0(CpuDefinitionInfoList, 1);
>  entry->value = info;
>  entry->next = *first;
>  *first = entry;
> @@ -10473,11 +10473,11 @@ CpuDefinitionInfoList 
> *arch_query_cpu_definitions(Error **errp)
>  continue;
>  }
>  
> -info = g_malloc0(sizeof(*info));
> +info = g_new0(CpuDefinitionInfo, 1);
>  info->name = g_strdup(alias->alias);
>  info->q_typename = g_strdup(object_class_get_name(oc));
>  
> -entry 

[Qemu-devel] [Bug 1050694] Re: Interrupt 0xffffffff when debug is turned on

2017-10-06 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1050694

Title:
  Interrupt 0x when debug is turned on

Status in QEMU:
  Expired

Bug description:
  Hi,

  I have been getting a GPF when I enable interrupts, working on
  implementing processes and a scheduler. When I comment out the
  scheduler code, I still get the GPF. I used the following QEMU command
  line to capture a log:

  qemu-system-i386 -smp 4 -monitor stdio -cpu core2duo -D
  /home/adam/century/util/qemu.log -d int,in_asm -s -hda
  "$harddisk_image" -m 3.5G

  Rather than posting the entire log, I need some help interpreting the 
following section (notice "INT=0x" on the top line):
  Servicing hardware INT=0x
  1: v= e= i=0 cpl=0 IP=0008:0010b63f pc=0010b63f SP=0010:0012b768 
EAX=
  EAX= EBX=2000 ECX=0018 EDX=05a00780
  ESI=00112faa EDI=000b8fa0 EBP=0012b780 ESP=0012b768
  EIP=0010b63f EFL=00207202 [---] CPL=0 II=0 A20=1 SMM=0 HLT=0
  ES =0010   00cf9300 DPL=0 DS [-WA]
  CS =0008   00cf9a00 DPL=0 CS32 [-R-]
  SS =0010   00cf9300 DPL=0 DS [-WA]
  DS =0010   00cf9300 DPL=0 DS [-WA]
  FS =0010   00cf9300 DPL=0 DS [-WA]
  GS =0010   00cf9300 DPL=0 DS [-WA]
  LDT=   8200 DPL=0 LDT
  TR =0008 0580 0067 8900 DPL=0 TSS32-avl
  GDT= 00127760 0027
  IDT= 00122f40 07ff
  CR0=8011 CR2= CR3=0014a000 CR4=
  DR0= DR1= DR2= DR3=
  DR6=0ff0 DR7=0400
  CCS=0024 CCD=0012b75c CCO=ADDL
  EFER=
  check_exception old: 0x new 0xd
  2: v=0d e=fffa i=0 cpl=0 IP=0008:0010b63f pc=0010b63f SP=0010:0012b768 
EAX=
  EAX= EBX=2000 ECX=0018 EDX=05a00780
  ESI=00112faa EDI=000b8fa0 EBP=0012b780 ESP=0012b768
  EIP=0010b63f EFL=00207202 [---] CPL=0 II=0 A20=1 SMM=0 HLT=0
  ES =0010   00cf9300 DPL=0 DS [-WA]
  CS =0008   00cf9a00 DPL=0 CS32 [-R-]
  SS =0010   00cf9300 DPL=0 DS [-WA]
  DS =0010   00cf9300 DPL=0 DS [-WA]
  FS =0010   00cf9300 DPL=0 DS [-WA]
  GS =0010   00cf9300 DPL=0 DS [-WA]
  LDT=   8200 DPL=0 LDT
  TR =0008 0580 0067 8900 DPL=0 TSS32-avl
  GDT= 00127760 0027
  IDT= 00122f40 07ff
  CR0=8011 CR2= CR3=0014a000 CR4=
  DR0= DR1= DR2= DR3=
  DR6=0ff0 DR7=0400
  CCS=0024 CCD=0012b75c CCO=ADDL
  EFER=

  To the best of my ability to interpret, I an getting an undefined
  interrupt, which is then triggering a GPF, which is caught. However,
  do not know where it might be coming from.

  Some additional information:

  This command works:

  qemu-system-i386 -smp 4 -monitor stdio -cpu core2duo -s -hda
  "$harddisk_image" -m 3.5G

  This command works:

  qemu-system-i386 -monitor stdio -cpu core2duo -D
  /home/adam/century/util/qemu.log -d int,in_asm -s -hda
  "$harddisk_image" -m 3.5G

  And, as above, this does not:

  qemu-system-i386 -smp 4 -monitor stdio -cpu core2duo -D
  /home/adam/century/util/qemu.log -d int,in_asm -s -hda
  "$harddisk_image" -m 3.5G

  [adam@os-development ~]$ qemu-system-i386 -version
  QEMU emulator version 1.2.0, Copyright (c) 2003-2008 Fabrice Bellard

  Attached is an image as a test case.  Please let me know if you need
  any additional information.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1050694/+subscriptions



[Qemu-devel] [Bug 1088617] Re: qemu-system-mipsel save/restore broken

2017-10-06 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1088617

Title:
  qemu-system-mipsel save/restore broken

Status in QEMU:
  Expired

Bug description:
  Save and restore on mipsel seems to be broken (tested with commit
  1c97e303d4ea80a2691334b0febe87a50660f99d). To reproduce:

  1. Download debian_squeeze_mipsel_standard.qcow2 and vmlinux-2.6.32-5
  -4kc-malta from from http://people.debian.org/~aurel32/qemu/mipsel/

  2. Boot the system. I had to ^D past a Bus error in fsck, which may be 
another bug (haven't investigated). The command line used was:
  qemu-system-mipsel -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda 
debian_squeeze_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -k 
en-us -vnc :0

  3. Once the system is booted, go to the monitor and do "savevm
  booted". Then quit.

  4. Re-run qemu-system-mipsel again with "-loadvm booted". The guest
  system comes back but is hung (the monitor remains responsive,
  however).

  I also captured a debug log, which is attached. The immediate cause of
  the freeze seems to be that it's stuck in a loop repeatedly handling
  the same page fault over and over.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1088617/+subscriptions



Re: [Qemu-devel] [PATCH 71/88] block: avoid use of g_new0()

2017-10-06 Thread Philippe Mathieu-Daudé
On 10/06/2017 08:50 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  block/qcow2.c | 2 +-
>  block/vhdx.c  | 9 +
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index f63d1831f8..3e7d6c81be 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2738,7 +2738,7 @@ static int qcow2_create2(const char *filename, int64_t 
> total_size,
>  
>  /* Write the header */
>  QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
> -header = g_malloc0(cluster_size);
> +header = g_malloc(cluster_size);

self-NACK since this is wrong.

>  *header = (QCowHeader) {
>  .magic  = cpu_to_be32(QCOW_MAGIC),
>  .version= cpu_to_be32(version),
> diff --git a/block/vhdx.c b/block/vhdx.c
> index 8260fb46cd..91e532df8a 100644
> --- a/block/vhdx.c
> +++ b/block/vhdx.c
> @@ -244,10 +244,11 @@ static void vhdx_region_register(BDRVVHDXState *s,
>  {
>  VHDXRegionEntry *r;
>  
> -r = g_new0(VHDXRegionEntry, 1);
> -
> -r->start = start;
> -r->end = start + length;
> +r = g_new(VHDXRegionEntry, 1);
> +*r = (VHDXRegionEntry) {
> +.start = start,
> +.end = start + length,

this is not wrong since all members are initialized, but it is not good
code practice (if the VHDXRegionEntry structure is expanded with another
member).

> +};
>  
>  QLIST_INSERT_HEAD(>regions, r, entries);
>  }
> 



Re: [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0()

2017-10-06 Thread Philippe Mathieu-Daudé
On 10/06/2017 08:48 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  scripts/coccinelle/g_new.cocci | 46 
> ++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/scripts/coccinelle/g_new.cocci b/scripts/coccinelle/g_new.cocci
> index 368f0c5651..9643ce3f23 100644
> --- a/scripts/coccinelle/g_new.cocci
> +++ b/scripts/coccinelle/g_new.cocci
> @@ -127,6 +127,52 @@ T **m;
>  - *m = g_malloc0(sizeof(**m));
>  + *m = g_new0(T *, 1);
>  
> +
> +//
> +// no point in zeroing the allocation
> +//
> +
> +// the loop right afterwards fully initializes the memory
> +@@
> +type T;
> +identifier a, i;
> +expression c, e;
> +@@
> +(
> +-a = g_new0(T, c);
> +... when != a, c
> ++a = g_new(T, c);
> +for (i = 0; i < c; i++) {
> +a[i] = e;
> +}
> +|
> +-a = g_try_new0(T, c);
> +... when != a, c
> ++a = g_try_new(T, c);
> +for (i = 0; i < c; i++) {
> +a[i] = e;
> +}
> +)
> +
> +// compound literals
> +@@
> +type T;
> +identifier p;
> +expression s, e;
> +@@
> +(
> +- p = g_malloc0(s);
> ++ p = g_malloc(s);
> +|
> +- p = g_try_malloc0(s);
> ++ p = g_try_malloc(s);
> +|
> +- p = g_new0(T, 1);
> ++ p = g_new(T, 1);
> +)
> +  ... when != p
> +  *p = e;

It seems I misunderstood compound literals, I somehow believed this
would imply uninitialized fields would be zeroed.
So this transformation leads to incorrect code.

> +
>  
>  //
>  // last transformations: cleanups
> 



[Qemu-devel] What is the status of the QEMU sound rework?

2017-10-06 Thread Zir Blazer
I'm a VGA Passthrough user that uses a QEMU VM to fully replace a Windows 
native install as the main OS.


Currently, one of the biggest hazzles for many users is that sound is hard to 
get working properly with the emulated AC'97 and Intel HDA Sound Cards due to 
crackle or latency issues (Latency issues heavily affects recording scenarios, 
like voice chat applications in a VM). An example here, through there are far 
more: 
https://www.reddit.com/r/VFIO/comments/746t4h/getting_rid_of_audio_crackling_once_and_for_all/


Some people managed to get sound working at acceptable levels by meddling with 
the environmental variables, but most of the solutions come from a 
trial-and-error esoteric procedure instead of structured troubleshooting, as 
each user has to figure out which settings makes the emulated Sound Cards work 
decently in his system. For those that failed getting the desired results with 
emulation, they have to throw Hardware at the issue by using PCI Passthrough of 
a Sound Card, or an USB Sound Card via USB Passthrough (Or even have it plugged 
to an USB Controller passed to the VM via PCI Passthrough), or using the 
passthroughed Video Card HDMI with a Monitor with speakers, just to solve the 
sound issues. The problem is that this complicates this type of setups a lot, 
and it makes impossible a typical use case that would be that all the VMs 
output the sound to the host, which has control of the Motherboard integrated 
Sound Card, and it mixes it to use a single set of speakers for the entire 
system.



I have been googling around and found that at several times, there were ideas 
and proposal, and even some code, that were intended to overhaul QEMU sound 
system. Examples includes:

GSoC 2011 Xen PV Audio, a paravirtualized Sound Card 
https://wiki.xenproject.org/wiki/Archived/GSoc_2011_Ideas
GSoC 2015 QEMU rework of the sound environmental variables 
https://wiki.qemu.org/Google_Summer_of_Code_2015#QEMU_audio_backend
GSoC 2017 QEMU rework a patch series that did precisely that 
https://wiki.qemu.org/Google_Summer_of_Code_2017#QEMU_audio_backend
https://lists.nongnu.org/archive/html/qemu-devel/2016-01/msg02451.html



Basically, what happened with all the previous ideas and proposals? Did any of 
that work ever get into upstream QEMU?
Is anyone tinkering with the idea of making a paravirtualized Sound Card and 
its associated Drivers for the mainstream OSes to try to fix once and for all 
the sound issues?


Re: [Qemu-devel] [PATCH 00/88] use g_new() family of functions

2017-10-06 Thread no-reply
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20171006235023.11952-1-f4...@amsat.org
Subject: [Qemu-devel] [PATCH 00/88] use g_new() family of functions

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20171006235023.11952-1-f4...@amsat.org -> 
patchew/20171006235023.11952-1-f4...@amsat.org
Switched to a new branch 'test'
c804c28ce1 scripts/coverity-model: use g_new() family of functions
b0e0658a5c hw/net/rocker: use g_new() family of functions
183562cc1d net/hub: use g_new() family of functions
b9f50bfa72 hw/usb: use g_new() family of functions
cff8a0d8e5 hw/scsi: use g_new() family of functions
071370df89 hw/pci: use g_new() family of functions
175fef7b9d hw/ipmi: use g_new() family of functions
5e8c9e184d hw/acpi: use g_new() family of functions
62ee9aea32 numa: use g_new() family of functions
57e59bd5a3 hmp: use g_new() family of functions
5736d72820 gdb: use g_new() family of functions
935c453c3e dump: use g_new() family of functions
fe6b9cd532 dma: use g_new() family of functions
b80633b250 decnumber: use g_new() family of functions
330df41ca1 balloon: use g_new() family of functions
599de671cb hw/block/xen_disk: avoid use of g_new0()
21bb36804a hw/block/nvme: use g_new() family of functions
06226f3349 block: avoid use of g_new0()
ac1388fadb block: use g_new() family of functions
15186d5c50 virtio-9p: use g_new() family of functions
4db380eabf virtio: use g_new() family of functions
3e7a3445ce util/coroutine: use g_new() family of functions
eb8027f518 util/qemu-thread-win32: use g_new() family of functions
6c3385656d util: use g_new() family of functions
d4fcc9cbd7 user: use g_strfreev()
27cbb7ecf7 bsd-user/syscall: fix a memory leak on EFAULT, use g_new()
603f6d2797 user: use g_new() family of functions
8952c25f5d tests: use g_new() family of functions
a76a1c1038 sPAPR: use g_new() family of functions
747d79335c ppce500: use g_new() family of functions
d6737387c5 ppc4xx: use g_new() family of functions
cc4e72bb73 ppc: use g_new() family of functions
f014ab5c23 PowerPC: use g_new() family of functions
1c7f285465 PReP: use g_new() family of functions
a89817ffbd KVM: use g_new() family of functions
62e9ee5d6d iSCSI: use g_new() family of functions
a5f0a975ad i.MX31: use g_new() family of functions
e3c99cd21c hw/timer: use g_new() family of functions
57b0cb6f00 ivshmem: use g_new() family of functions
ab0935ee66 hw/misc: use g_new() family of functions
51edcbd3d0 hw/input: use g_new() family of functions
c5a983b01b hw/i2c: use g_new() family of functions
3d2167e517 hw/display/vga: use g_new() family of functions
6700833717 hw/display: use g_new() family of functions
3b6e0a9ba0 hw/core/loader: use g_new() family of functions
397f1320a0 hw/core: use g_new() family of functions
7fc29ad15d XTFPGA: use g_new() family of functions
c9c7a78335 target/i386: use g_new() family of functions
dcf5c388df hw/xen: use g_new() family of functions
d359058b9c hw/i386: use g_new() family of functions
0f2bd5995e VFIO: use g_new() family of functions
6149f4936f TCG: use g_new() family of functions
2e7bd6ee2c SLIRP: use g_new() family of functions
48c3189a1e Record/replay: use g_new() family of functions
eb4526cfb0 qapi: use g_new() family of functions
317f58f9f2 qom: use g_new() family of functions
f7c8362449 QObject: use g_new() family of functions
61a83549f4 QMP: use g_new() family of functions
3979392544 QEMU Guest Agent: use g_new() family of functions
f00debd577 SPARC: use g_new() family of functions
eb7a298007 disas: use g_new() family of functions
859752d9e4 SH4: use g_new() family of functions
875e2fd57b S390: use g_new() family of functions
18b1a93522 OpenRISC: use g_new() family of functions
98fc4795cd MIPS: use g_new() family of functions
13bc92e683 M68K: use g_new() family of functions
94928b9ef3 LM32: use g_new() family of functions
6014b8ee35 NBD: use g_new() family of functions
3e69886310 Migration: use g_new() family of functions
8920e8ca87 exec: use g_new() family of functions
701099c16e memory: use g_new() family of functions
5f388075f6 Memory API: use g_new() family of functions
ccb604eee5 Main loop: use g_new() family of functions
c294183f4e ui/spice: use g_new() family of functions
9c876c33e2 ui/vnc: use g_new() family of functions
c943798f44 Dirty Bitmaps: use g_new() family of functions
a19287589f backends/hostmem: use g_new() family of functions

Re: [Qemu-devel] [PATCH 51/88] hw/timer: use g_new() family of functions

2017-10-06 Thread xiaoqiang zhao

> 在 2017年10月7日,上午7:49,Philippe Mathieu-Daudé  写道:
> 
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> ---
> hw/timer/slavio_timer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c
> index a8cc9c0148..6d0282a788 100644
> --- a/hw/timer/slavio_timer.c
> +++ b/hw/timer/slavio_timer.c
> @@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
>  uint64_t size;
>  char timer_name[20];
> 
> -tc = g_malloc0(sizeof(TimerContext));
> +tc = g_new0(TimerContext, 1);
>  tc->s = s;
>  tc->timer_index = i;
> 
> -- 
> 2.14.2

Resend due to email blocks.

Reviewed-by: xiaoqiang zhao 





Re: [Qemu-devel] [PATCH for-2.10 3/3] qdev: defer DEVICE_DEL event until instance_finalize()

2017-10-06 Thread Michael Roth
Quoting Auger Eric (2017-08-09 09:04:54)
> Hi Michael,
> 
> On 27/07/2017 03:30, Michael Roth wrote:
> > DEVICE_DEL is currently emitted when a Device is unparented, as
> > opposed to when it is finalized. The main design motivation for this
> > seems to be that after unparent()/unrealize(), the Device is no
> > longer visible to the guest, and thus the operation is complete
> > from the perspective of management.
> > 
> > However, there are cases where remaining host-side cleanup is also
> > pertinent to management. The is generally handled by treating these
> > resources as aspects of the "backend", which can be managed via
> > separate interfaces/events, such as blockdev_add/del, netdev_add/del,
> > object_add/del, etc, but some devices do not have this level of
> > compartmentalization, namely vfio-pci, and possibly to lend themselves
> > well to it.
> > 
> > In the case of vfio-pci, the "backend" cleanup happens as part of
> > the finalization of the vfio-pci device itself, in particular the
> > cleanup of the VFIO group FD. Failing to wait for this cleanup can
> > result in tools like libvirt attempting to rebind the device to
> > the host while it's still being used by VFIO, which can result in
> > host crashes or other misbehavior depending on the host driver.
> > 
> > Deferring DEVICE_DEL still affords us the ability to manage backends
> > explicitly, while also addressing cases like vfio-pci's, so we
> > implement that approach here.
> > 
> > An alternative proposal involving having VFIO emit a separate event
> > to denote completion of host-side cleanup was discussed, but the
> > prevailing opinion seems to be that it is not worth the added
> > complexity, and leaves the issue open for other Device implementations
> > solve in the future.
> > 
> > Signed-off-by: Michael Roth 
> > ---
> >  hw/core/qdev.c | 23 ---
> >  1 file changed, 12 insertions(+), 11 deletions(-)
> > 
> > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > index 08c4061..d14acba 100644
> > --- a/hw/core/qdev.c
> > +++ b/hw/core/qdev.c
> > @@ -1067,7 +1067,6 @@ static void device_finalize(Object *obj)
> >  NamedGPIOList *ngl, *next;
> >  
> >  DeviceState *dev = DEVICE(obj);
> > -qemu_opts_del(dev->opts);
> >  
> >  QLIST_FOREACH_SAFE(ngl, >gpios, node, next) {
> >  QLIST_REMOVE(ngl, node);
> > @@ -1078,6 +1077,18 @@ static void device_finalize(Object *obj)
> >   * here
> >   */
> >  }
> > +
> > +/* Only send event if the device had been completely realized */
> > +if (dev->pending_deleted_event) {
> > +g_assert(dev->canonical_path);
> > +
> > +qapi_event_send_device_deleted(!!dev->id, dev->id, 
> > dev->canonical_path,
> > +   _abort);
> > +g_free(dev->canonical_path);
> > +dev->canonical_path = NULL;
> > +}
> > +
> > +qemu_opts_del(dev->opts);
> >  }
> >  
> >  static void device_class_base_init(ObjectClass *class, void *data)
> > @@ -1107,16 +1118,6 @@ static void device_unparent(Object *obj)
> >  object_unref(OBJECT(dev->parent_bus));
> >  dev->parent_bus = NULL;
> >  }
> > -
> > -/* Only send event if the device had been completely realized */
> > -if (dev->pending_deleted_event) {
> > -g_assert(dev->canonical_path);
> > -
> > -qapi_event_send_device_deleted(!!dev->id, dev->id, 
> > dev->canonical_path,
> > -   _abort);
> > -g_free(dev->canonical_path);
> > -dev->canonical_path = NULL;
> > -}
> is the code below, introduced in patch 1/device_set_realized() still
> relevant?
> /* always re-initialize since we clean up in device_unparent()
> instead
>  * of unrealize()
>  */
> g_free(dev->canonical_path);

Hi Eric,

Sorry for missing your reply previously. That comment does indeed need
some adjusting after patch 3. Will fix it up for v2.

> 
> Thanks
> 
> Eric
> >  }
> >  
> >  static void device_class_init(ObjectClass *class, void *data)
> > 
> 




Re: [Qemu-devel] [PATCH 25/88] OpenRISC: use g_new() family of functions

2017-10-06 Thread Stafford Horne
On Fri, Oct 06, 2017 at 08:49:20PM -0300, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> Signed-off-by: Philippe Mathieu-Daudé 

Acked-by: Stafford Horne 

> [PMD: squashed openrisc_sim.c]
> ---
>  hw/openrisc/openrisc_sim.c | 2 +-
>  target/openrisc/mmu.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
> index 86bf2849c4..1eb381549c 100644
> --- a/hw/openrisc/openrisc_sim.c
> +++ b/hw/openrisc/openrisc_sim.c
> @@ -114,7 +114,7 @@ static void openrisc_sim_init(MachineState *machine)
>  main_cpu_reset(cpu);
>  }
>  
> -ram = g_malloc(sizeof(*ram));
> +ram = g_new(MemoryRegion, 1);
>  memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, 
> _fatal);
>  memory_region_add_subregion(get_system_memory(), 0, ram);
>  
> diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c
> index ce2a29dd1a..4789a35b67 100644
> --- a/target/openrisc/mmu.c
> +++ b/target/openrisc/mmu.c
> @@ -247,7 +247,7 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, 
> vaddr addr)
>  
>  void cpu_openrisc_mmu_init(OpenRISCCPU *cpu)
>  {
> -cpu->env.tlb = g_malloc0(sizeof(CPUOpenRISCTLBContext));
> +cpu->env.tlb = g_new0(CPUOpenRISCTLBContext, 1);
>  
>  cpu->env.tlb->cpu_openrisc_map_address_code = 
> _openrisc_get_phys_nommu;
>  cpu->env.tlb->cpu_openrisc_map_address_data = 
> _openrisc_get_phys_nommu;
> -- 
> 2.14.2
> 



Re: [Qemu-devel] [PATCH v2 17/40] openrisc: cleanup cpu type name composition

2017-10-06 Thread Stafford Horne
On Thu, Oct 05, 2017 at 03:50:51PM +0200, Igor Mammedov wrote:
> use new OPENRISC_CPU_TYPE_NAME to compose CPU type name and get
> rid of intermediate OpenRISCCPUInfo/openrisc_cpu_register_types()
> which is replaced by static TypeInfo array.
> 
> Signed-off-by: Igor Mammedov 
> Reviewed-by: Philippe Mathieu-Daudé 

This is nice

Acked-by: Stafford Horne 

> ---
> v2:  rename type_init_from_array into DEFINE_TYPES
> 
> CC: sho...@gmail.com
> ---
>  target/openrisc/cpu.h |  3 +++
>  target/openrisc/cpu.c | 69 
> +--
>  2 files changed, 26 insertions(+), 46 deletions(-)
> 
> diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h
> index f51b89a..576cf66 100644
> --- a/target/openrisc/cpu.h
> +++ b/target/openrisc/cpu.h
> @@ -390,6 +390,9 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
>  
>  #define cpu_init(cpu_model) cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model)
>  
> +#define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
> +#define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
> +
>  #include "exec/cpu-all.h"
>  
>  #define TB_FLAGS_DFLAG 1
> diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
> index af9cdcc..629831a 100644
> --- a/target/openrisc/cpu.c
> +++ b/target/openrisc/cpu.c
> @@ -108,7 +108,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char 
> *cpu_model)
>  ObjectClass *oc;
>  char *typename;
>  
> -typename = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, cpu_model);
> +typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model);
>  oc = object_class_by_name(typename);
>  g_free(typename);
>  if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) ||
> @@ -133,16 +133,6 @@ static void openrisc_any_initfn(Object *obj)
>  cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_EVBARP;
>  }
>  
> -typedef struct OpenRISCCPUInfo {
> -const char *name;
> -void (*initfn)(Object *obj);
> -} OpenRISCCPUInfo;
> -
> -static const OpenRISCCPUInfo openrisc_cpus[] = {
> -{ .name = "or1200",  .initfn = or1200_initfn },
> -{ .name = "any", .initfn = openrisc_any_initfn },
> -};
> -
>  static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
>  {
>  OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc);
> @@ -172,40 +162,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, 
> void *data)
>  cc->gdb_num_core_regs = 32 + 3;
>  }
>  
> -static void cpu_register(const OpenRISCCPUInfo *info)
> -{
> -TypeInfo type_info = {
> -.parent = TYPE_OPENRISC_CPU,
> -.instance_size = sizeof(OpenRISCCPU),
> -.instance_init = info->initfn,
> -.class_size = sizeof(OpenRISCCPUClass),
> -};
> -
> -type_info.name = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, info->name);
> -type_register(_info);
> -g_free((void *)type_info.name);
> -}
> -
> -static const TypeInfo openrisc_cpu_type_info = {
> -.name = TYPE_OPENRISC_CPU,
> -.parent = TYPE_CPU,
> -.instance_size = sizeof(OpenRISCCPU),
> -.instance_init = openrisc_cpu_initfn,
> -.abstract = true,
> -.class_size = sizeof(OpenRISCCPUClass),
> -.class_init = openrisc_cpu_class_init,
> -};
> -
> -static void openrisc_cpu_register_types(void)
> -{
> -int i;
> -
> -type_register_static(_cpu_type_info);
> -for (i = 0; i < ARRAY_SIZE(openrisc_cpus); i++) {
> -cpu_register(_cpus[i]);
> -}
> -}
> -
>  /* Sort alphabetically by type name, except for "any". */
>  static gint openrisc_cpu_list_compare(gconstpointer a, gconstpointer b)
>  {
> @@ -254,4 +210,25 @@ void cpu_openrisc_list(FILE *f, fprintf_function 
> cpu_fprintf)
>  g_slist_free(list);
>  }
>  
> -type_init(openrisc_cpu_register_types)
> +#define DEFINE_OPENRISC_CPU_TYPE(cpu_model, initfn) \
> +{   \
> +.parent = TYPE_OPENRISC_CPU,\
> +.instance_init = initfn,\
> +.name = OPENRISC_CPU_TYPE_NAME(cpu_model),  \
> +}
> +
> +static const TypeInfo openrisc_cpus_type_infos[] = {
> +{ /* base class should be registered first */
> +.name = TYPE_OPENRISC_CPU,
> +.parent = TYPE_CPU,
> +.instance_size = sizeof(OpenRISCCPU),
> +.instance_init = openrisc_cpu_initfn,
> +.abstract = true,
> +.class_size = sizeof(OpenRISCCPUClass),
> +.class_init = openrisc_cpu_class_init,
> +},
> +DEFINE_OPENRISC_CPU_TYPE("or1200", or1200_initfn),
> +DEFINE_OPENRISC_CPU_TYPE("any", openrisc_any_initfn),
> +};
> +
> +DEFINE_TYPES(openrisc_cpus_type_infos)
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH 00/88] use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
... and I obviously forgot to paste this...
(useful for Marc-André mostly)

[] : patches are identical
[] : number of functional differences between upstream/downstream patch
[down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences,
respectively
001/88:[down] 'cocci: script to use g_new() & friends'
002/88:[down] 'cocci: add more g_new() transformations'
003/88:[down] 'cocci: extract typeof() from g_new()'
004/88:[down] 'cocci: avoid use of g_new0()'
005/88:[down] 'cocci: use g_strfreev()'
006/88:[down] 'ARM: use g_new() family of functions'
007/88:[0018] [FC] 'Audio: use g_new() family of functions'
008/88:[0002] [FC] 'BT: use g_new() family of functions'
009/88:[] [--] 'Bootdevice: use g_new() family of functions'
010/88:[0006] [FC] 'Character devices: use g_new() family of functions'
011/88:[] [--] 'Cryptodev Backends: use g_new() family of functions'
012/88:[down] 'backends/hostmem: use g_new() family of functions'
013/88:[0002] [FC] 'Dirty Bitmaps: use g_new() family of functions'
014/88:[down] 'ui/vnc: use g_new() family of functions'
015/88:[down] 'ui/spice: use g_new() family of functions'
016/88:[0022] [FC] 'Main loop: use g_new() family of functions'
017/88:[] [--] 'Memory API: use g_new() family of functions'
018/88:[] [--] 'memory: use g_new() family of functions'
019/88:[down] 'exec: use g_new() family of functions'
020/88:[0007] [FC] 'Migration: use g_new() family of functions'
021/88:[] [--] 'NBD: use g_new() family of functions'
022/88:[0002] [FC] 'LM32: use g_new() family of functions'
023/88:[0009] [FC] 'M68K: use g_new() family of functions'
024/88:[0006] [FC] 'MIPS: use g_new() family of functions'
025/88:[0002] [FC] 'OpenRISC: use g_new() family of functions'
026/88:[0018] [FC] 'S390: use g_new() family of functions'
027/88:[0008] [FC] 'SH4: use g_new() family of functions'
028/88:[down] 'disas: use g_new() family of functions'
029/88:[0004] [FC] 'SPARC: use g_new() family of functions'
030/88:[0032] [FC] 'QEMU Guest Agent: use g_new() family of functions'
031/88:[0038] [FC] 'QMP: use g_new() family of functions'
032/88:[0016] [FC] 'QObject: use g_new() family of functions'
033/88:[down] 'qom: use g_new() family of functions'
034/88:[down] 'qapi: use g_new() family of functions'
035/88:[] [--] 'Record/replay: use g_new() family of functions'
036/88:[0004] [FC] 'SLIRP: use g_new() family of functions'
037/88:[0002] [FC] 'TCG: use g_new() family of functions'
038/88:[0034] [FC] 'VFIO: use g_new() family of functions'
039/88:[down] 'hw/i386: use g_new() family of functions'
040/88:[down] 'hw/xen: use g_new() family of functions'
041/88:[down] 'target/i386: use g_new() family of functions'
042/88:[] [--] 'XTFPGA: use g_new() family of functions'
043/88:[0002] [FC] 'hw/core: use g_new() family of functions'
044/88:[down] 'hw/core/loader: use g_new() family of functions'
045/88:[0002] [FC] 'hw/display: use g_new() family of functions'
046/88:[down] 'hw/display/vga: use g_new() family of functions'
047/88:[] [--] 'hw/i2c: use g_new() family of functions'
048/88:[0002] [FC] 'hw/input: use g_new() family of functions'
049/88:[0002] [FC] 'hw/misc: use g_new() family of functions'
050/88:[] [--] 'ivshmem: use g_new() family of functions'
051/88:[0002] [FC] 'hw/timer: use g_new() family of functions'
052/88:[] [--] 'i.MX31: use g_new() family of functions'
053/88:[] [--] 'iSCSI: use g_new() family of functions'
054/88:[0002] [FC] 'KVM: use g_new() family of functions'
055/88:[] [--] 'PReP: use g_new() family of functions'
056/88:[0010] [FC] 'PowerPC: use g_new() family of functions'
057/88:[down] 'ppc: use g_new() family of functions'
058/88:[down] 'ppc4xx: use g_new() family of functions'
059/88:[0003] [FC] 'ppce500: use g_new() family of functions'
060/88:[0008] [FC] 'sPAPR: use g_new() family of functions'
061/88:[0020] [FC] 'tests: use g_new() family of functions'
062/88:[0002] [FC] 'user: use g_new() family of functions'
063/88:[down] 'bsd-user/syscall: fix a memory leak on EFAULT, use g_new()'
064/88:[] [--] 'user: use g_strfreev()'
065/88:[0030] [FC] 'util: use g_new() family of functions'
066/88:[down] 'util/qemu-thread-win32: use g_new() family of functions'
067/88:[down] 'util/coroutine: use g_new() family of functions'
068/88:[0012] [FC] 'virtio: use g_new() family of functions'
069/88:[0004] [FC] 'virtio-9p: use g_new() family of functions'
070/88:[down] 'block: use g_new() family of functions'
071/88:[down] 'block: avoid use of g_new0()'
072/88:[down] 'hw/block/nvme: use g_new() family of functions'
073/88:[down] 'hw/block/xen_disk: avoid use of g_new0()'
074/88:[down] 'balloon: use g_new() family of functions'
075/88:[] [--] 'decnumber: use g_new() family of functions'
076/88:[0002] [FC] 'dma: use g_new() family of functions'
077/88:[] [--] 'dump: use g_new() family of functions'
078/88:[] [--] 'gdb: use g_new() family of functions'
079/88:[down] 'hmp: use g_new() 

[Qemu-devel] [PATCH 88/88] scripts/coverity-model: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 scripts/coverity-model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/coverity-model.c b/scripts/coverity-model.c
index c702804f41..de07bffb57 100644
--- a/scripts/coverity-model.c
+++ b/scripts/coverity-model.c
@@ -363,7 +363,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout)
 typedef struct _GIOChannel GIOChannel;
 GIOChannel *g_io_channel_unix_new(int fd)
 {
-GIOChannel *c = g_malloc0(sizeof(GIOChannel));
+GIOChannel *c = g_new0(GIOChannel, 1);
 __coverity_escape__(fd);
 return c;
 }
-- 
2.14.2




Re: [Qemu-devel] [PATCH v2 18/40] openrisc: use generic cpu_model parsing

2017-10-06 Thread Stafford Horne
On Thu, Oct 05, 2017 at 03:50:52PM +0200, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov 
> Reviewed-by: Philippe Mathieu-Daudé 

Less lines of code, thanks.

Acked-by: Stafford Horne 

> ---
> CC: sho...@gmail.com
> ---
>  hw/openrisc/openrisc_sim.c | 8 ++--
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
> index 86bf284..f61b63d 100644
> --- a/hw/openrisc/openrisc_sim.c
> +++ b/hw/openrisc/openrisc_sim.c
> @@ -98,18 +98,13 @@ static void cpu_openrisc_load_kernel(ram_addr_t ram_size,
>  static void openrisc_sim_init(MachineState *machine)
>  {
>  ram_addr_t ram_size = machine->ram_size;
> -const char *cpu_model = machine->cpu_model;
>  const char *kernel_filename = machine->kernel_filename;
>  OpenRISCCPU *cpu = NULL;
>  MemoryRegion *ram;
>  int n;
>  
> -if (!cpu_model) {
> -cpu_model = "or1200";
> -}
> -
>  for (n = 0; n < smp_cpus; n++) {
> -cpu = OPENRISC_CPU(cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model));
> +cpu = OPENRISC_CPU(cpu_create(machine->cpu_type));
>  qemu_register_reset(main_cpu_reset, cpu);
>  main_cpu_reset(cpu);
>  }
> @@ -138,6 +133,7 @@ static void openrisc_sim_machine_init(MachineClass *mc)
>  mc->init = openrisc_sim_init;
>  mc->max_cpus = 1;
>  mc->is_default = 1;
> +mc->default_cpu_type = OPENRISC_CPU_TYPE_NAME("or1200");
>  }
>  
>  DEFINE_MACHINE("or1k-sim", openrisc_sim_machine_init)
> -- 
> 2.7.4
> 



[Qemu-devel] [PATCH 87/88] hw/net/rocker: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/net/rocker/rocker_of_dpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
index 191a58e0a7..990f4157a0 100644
--- a/hw/net/rocker/rocker_of_dpa.c
+++ b/hw/net/rocker/rocker_of_dpa.c
@@ -2306,7 +2306,7 @@ static void of_dpa_flow_fill(void *cookie, void *value, 
void *user_data)
 return;
 }
 
-new = g_malloc0(sizeof(*new));
+new = g_new0(RockerOfDpaFlowList, 1);
 nflow = new->value = g_malloc0(sizeof(*nflow));
 nkey = nflow->key = g_malloc0(sizeof(*nkey));
 nmask = nflow->mask = g_malloc0(sizeof(*nmask));
@@ -2478,7 +2478,7 @@ static void of_dpa_group_fill(void *key, void *value, 
void *user_data)
 return;
 }
 
-new = g_malloc0(sizeof(*new));
+new = g_new0(RockerOfDpaGroupList, 1);
 ngroup = new->value = g_malloc0(sizeof(*ngroup));
 
 ngroup->id = group->id;
-- 
2.14.2




Re: [Qemu-devel] [PATCH 0/5] OpenRISC SMP Support

2017-10-06 Thread Stafford Horne
Hello,

Any takers on this?  If not Ill consider sending a pull request
if/when the merge window is open.

-Stafford

On Wed, Aug 23, 2017 at 2:57 PM, Stafford Horne  wrote:
> Hello,
>
> This series adds SMP support for OpenRISC.  The platform is based on the
> work that Stefan Kristiansson did around 2012 implemented in Verilog and
> run on FPGAs.  I have been working to upstream this work, these are my QEMU
> patches I have been used to help with testing.
>
> I have documented the platform in the OpenRISC 1.2 specification proposal
> available here:
>   
> https://github.com/stffrdhrn/doc/raw/arch-1.2-proposal/openrisc-arch-1.2-rev0.pdf
>
> My latest kernel patches are available here:
>   https://github.com/stffrdhrn/linux.git openrisc-4.13-smp-qspinlock
>
> Stafford Horne (5):
>   openrisc/ompic: Add OpenRISC Multicore PIC (OMPIC)
>   target/openrisc: Make coreid and numcores configurable in state
>   openrisc/cputimer: Perparation for Multicore
>   openrisc: Initial SMP support
>   openrisc: Only kick cpu on timeout, not on update
>
>  default-configs/or1k-softmmu.mak |   1 +
>  hw/intc/Makefile.objs|   1 +
>  hw/intc/ompic.c  | 179 
> +++
>  hw/openrisc/cputimer.c   |  64 ++
>  hw/openrisc/openrisc_sim.c   |  87 ++-
>  target/openrisc/cpu.c|   1 -
>  target/openrisc/cpu.h|   7 +-
>  target/openrisc/machine.c|   8 +-
>  target/openrisc/sys_helper.c |   8 +-
>  9 files changed, 308 insertions(+), 48 deletions(-)
>  create mode 100644 hw/intc/ompic.c
>
> --
> 2.13.5
>



[Qemu-devel] [PATCH 85/88] hw/usb: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/usb/hcd-ehci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 0134232627..34785923f3 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -545,7 +545,7 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, 
uint32_t addr, int async)
 EHCIQueueHead *head = async ? >aqueues : >pqueues;
 EHCIQueue *q;
 
-q = g_malloc0(sizeof(*q));
+q = g_new0(EHCIQueue, 1);
 q->ehci = ehci;
 q->qhaddr = addr;
 q->async = async;
-- 
2.14.2




[Qemu-devel] [PATCH 84/88] hw/scsi: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/scsi/vmw_pvscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
index d8079158ac..24d0306ede 100644
--- a/hw/scsi/vmw_pvscsi.c
+++ b/hw/scsi/vmw_pvscsi.c
@@ -616,7 +616,7 @@ pvscsi_queue_pending_descriptor(PVSCSIState *s, SCSIDevice 
**d,
 PVSCSIRequest *pvscsi_req;
 uint8_t lun;
 
-pvscsi_req = g_malloc0(sizeof(*pvscsi_req));
+pvscsi_req = g_new0(PVSCSIRequest, 1);
 pvscsi_req->dev = s;
 pvscsi_req->req = *descr;
 pvscsi_req->cmp.context = pvscsi_req->req.context;
-- 
2.14.2




[Qemu-devel] [PATCH 86/88] net/hub: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 net/hub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/hub.c b/net/hub.c
index 14b4eec68f..1c403859c6 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -79,7 +79,7 @@ static NetHub *net_hub_new(int id)
 {
 NetHub *hub;
 
-hub = g_malloc(sizeof(*hub));
+hub = g_new(NetHub, 1);
 hub->id = id;
 hub->num_ports = 0;
 QLIST_INIT(>ports);
-- 
2.14.2




[Qemu-devel] [PATCH 82/88] hw/ipmi: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Shouldn't this file be under the PowerPC section of MAINTAINERS?

 hw/ipmi/ipmi_bmc_sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index 277c28cb40..a68792a2cb 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1073,7 +1073,7 @@ static void send_msg(IPMIBmcSim *ibs,
 return;
 }
 
-msg = g_malloc(sizeof(*msg));
+msg = g_new(IPMIRcvBufEntry, 1);
 msg->buf[0] = ((netfn | 1) << 2) | rqLun; /* NetFN, and make a response */
 msg->buf[1] = ipmb_checksum(msg->buf, 1, 0);
 msg->buf[2] = cmd[0]; /* rsSA */
-- 
2.14.2




[Qemu-devel] [PATCH 78/88] gdb: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 2a94030d3b..5f0d8af1c0 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1786,7 +1786,7 @@ static void gdb_accept(void)
 /* set short latency */
 socket_set_nodelay(fd);
 
-s = g_malloc0(sizeof(GDBState));
+s = g_new0(GDBState, 1);
 s->c_cpu = first_cpu;
 s->g_cpu = first_cpu;
 s->fd = fd;
@@ -1980,7 +1980,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);
-- 
2.14.2




[Qemu-devel] [PATCH 83/88] hw/pci: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/pci/pci.c  | 2 +-
 hw/pci/pcie_port.c| 2 +-
 tests/libqos/pci-pc.c | 2 +-
 tests/libqos/pci.c| 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 1e6fb88eba..32625d9fcc 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1644,7 +1644,7 @@ static PciMemoryRegionList *qmp_query_pci_regions(const 
PCIDevice *dev)
 continue;
 }
 
-region = g_malloc0(sizeof(*region));
+region = g_new0(PciMemoryRegionList, 1);
 region->value = g_malloc0(sizeof(*region->value));
 
 if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 6432b9ac1f..236d8bc4db 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -72,7 +72,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(>slots);
 QLIST_INSERT_HEAD(, c, next);
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
index ded1c54c06..cde5e0a627 100644
--- a/tests/libqos/pci-pc.c
+++ b/tests/libqos/pci-pc.c
@@ -119,7 +119,7 @@ QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
 {
 QPCIBusPC *ret;
 
-ret = g_malloc(sizeof(*ret));
+ret = g_new(QPCIBusPC, 1);
 
 ret->bus.pio_readb = qpci_pc_pio_readb;
 ret->bus.pio_readw = qpci_pc_pio_readw;
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index 0b73cb23d0..9dd689c7b5 100644
--- a/tests/libqos/pci.c
+++ b/tests/libqos/pci.c
@@ -54,7 +54,7 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
 {
 QPCIDevice *dev;
 
-dev = g_malloc0(sizeof(*dev));
+dev = g_new0(QPCIDevice, 1);
 dev->bus = bus;
 dev->devfn = devfn;
 
-- 
2.14.2




[Qemu-devel] [PATCH 81/88] hw/acpi: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/acpi/vmgenid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
index 2876d8a639..ced507d218 100644
--- a/hw/acpi/vmgenid.c
+++ b/hw/acpi/vmgenid.c
@@ -269,7 +269,7 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
 }
 vms = VMGENID(obj);
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(GuidInfo, 1);
 info->guid = qemu_uuid_unparse_strdup(>guid);
 return info;
 }
-- 
2.14.2




[Qemu-devel] [PATCH 76/88] dma: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added hw/dma/etraxfs_dma.c]
---
 dma-helpers.c| 4 ++--
 hw/dma/etraxfs_dma.c | 2 +-
 hw/dma/rc4030.c  | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dma-helpers.c b/dma-helpers.c
index 2d7e02d35e..e327fc21c4 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -40,7 +40,7 @@ int dma_memory_set(AddressSpace *as, dma_addr_t addr, uint8_t 
c, dma_addr_t len)
 void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint,
   AddressSpace *as)
 {
-qsg->sg = g_malloc(alloc_hint * sizeof(ScatterGatherEntry));
+qsg->sg = g_new(ScatterGatherEntry, alloc_hint);
 qsg->nsg = 0;
 qsg->nalloc = alloc_hint;
 qsg->size = 0;
@@ -53,7 +53,7 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, 
dma_addr_t len)
 {
 if (qsg->nsg == qsg->nalloc) {
 qsg->nalloc = 2 * qsg->nalloc + 1;
-qsg->sg = g_realloc(qsg->sg, qsg->nalloc * sizeof(ScatterGatherEntry));
+qsg->sg = g_renew(ScatterGatherEntry, qsg->sg, qsg->nalloc);
 }
 qsg->sg[qsg->nsg].base = base;
 qsg->sg[qsg->nsg].len = len;
diff --git a/hw/dma/etraxfs_dma.c b/hw/dma/etraxfs_dma.c
index d5650eb885..97951a2abe 100644
--- a/hw/dma/etraxfs_dma.c
+++ b/hw/dma/etraxfs_dma.c
@@ -768,7 +768,7 @@ void *etraxfs_dmac_init(hwaddr base, int nr_channels)
 {
struct fs_dma_ctrl *ctrl = NULL;
 
-   ctrl = g_malloc0(sizeof *ctrl);
+   ctrl = g_new0(struct fs_dma_ctrl, 1);
 
 ctrl->bh = qemu_bh_new(DMA_run, ctrl);
 
diff --git a/hw/dma/rc4030.c b/hw/dma/rc4030.c
index 5d4833eeca..14bcab9fb3 100644
--- a/hw/dma/rc4030.c
+++ b/hw/dma/rc4030.c
@@ -636,8 +636,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;
-- 
2.14.2




[Qemu-devel] [PATCH 79/88] hmp: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hmp.c b/hmp.c
index 739d330f4e..5157ac4223 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1917,7 +1917,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
 return;
 }
 
-status = g_malloc0(sizeof(*status));
+status = g_new0(HMPMigrationStatus, 1);
 status->mon = mon;
 status->is_block_migration = blk || inc;
 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, 
hmp_migrate_status_cb,
-- 
2.14.2




[Qemu-devel] [PATCH 77/88] dump: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 dump.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/dump.c b/dump.c
index 7ebcf553b2..884221a904 100644
--- a/dump.c
+++ b/dump.c
@@ -1825,29 +1825,28 @@ void qmp_dump_guest_memory(bool paging, const char 
*file,
 DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
 {
 DumpGuestMemoryFormatList *item;
-DumpGuestMemoryCapability *cap =
-  g_malloc0(sizeof(DumpGuestMemoryCapability));
+DumpGuestMemoryCapability *cap = g_new0(DumpGuestMemoryCapability, 1);
 
 /* elf is always available */
-item = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = g_new0(DumpGuestMemoryFormatList, 1);
 cap->formats = item;
 item->value = DUMP_GUEST_MEMORY_FORMAT_ELF;
 
 /* kdump-zlib is always available */
-item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item->next = g_new0(DumpGuestMemoryFormatList, 1);
 item = item->next;
 item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
 
 /* add new item if kdump-lzo is available */
 #ifdef CONFIG_LZO
-item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item->next = g_new0(DumpGuestMemoryFormatList, 1);
 item = item->next;
 item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
 #endif
 
 /* add new item if kdump-snappy is available */
 #ifdef CONFIG_SNAPPY
-item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item->next = g_new0(DumpGuestMemoryFormatList, 1);
 item = item->next;
 item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
 #endif
-- 
2.14.2




[Qemu-devel] [PATCH 74/88] balloon: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/balloon.c b/balloon.c
index 1d720fff81..d77918fd37 100644
--- a/balloon.c
+++ b/balloon.c
@@ -97,7 +97,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 return NULL;
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(BalloonInfo, 1);
 balloon_stat_fn(balloon_opaque, info);
 return info;
 }
-- 
2.14.2




Re: [Qemu-devel] [PATCH 51/88] hw/timer: use g_new() family of functions

2017-10-06 Thread xiaoqiang zhao

> 在 2017年10月7日,上午7:49,Philippe Mathieu-Daudé  写道:
> 
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> ---
> hw/timer/slavio_timer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c
> index a8cc9c0148..6d0282a788 100644
> --- a/hw/timer/slavio_timer.c
> +++ b/hw/timer/slavio_timer.c
> @@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
>   uint64_t size;
>   char timer_name[20];
> 
> -tc = g_malloc0(sizeof(TimerContext));
> +tc = g_new0(TimerContext, 1);
>   tc->s = s;
>   tc->timer_index = i;
> 
> -- 
> 2.14.2

Reviewed-by: xiaoqiang zhao 




[Qemu-devel] [PATCH 73/88] hw/block/xen_disk: avoid use of g_new0()

2017-10-06 Thread Philippe Mathieu-Daudé
From: Jan Beulich 

Prefer g_new() / g_new0() to be farther backwards compatible with older
glib versions. As there's no point in zeroing the allocation here (the
loop right afterwards fully initializes the memory), use the former.

Signed-off-by: Jan Beulich 
Reviewed-by: Paul Durrant 
Acked-by: Anthony Perard 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: rebase & subject tweak]
---
 hw/block/xen_disk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 536e2ee735..6d2fd4d284 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev)
 return -1;
 }
 
-domids = g_new0(uint32_t, blkdev->nr_ring_ref);
+domids = g_new(uint32_t, blkdev->nr_ring_ref);
 for (i = 0; i < blkdev->nr_ring_ref; i++) {
 domids[i] = blkdev->xendev.dom;
 }
-- 
2.14.2




[Qemu-devel] [PATCH 68/88] virtio: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes/files]
---
 hw/char/virtio-serial-bus.c | 6 ++
 hw/display/virtio-gpu.c | 4 ++--
 hw/net/virtio-net.c | 4 ++--
 hw/virtio/vhost.c   | 2 +-
 hw/virtio/virtio-crypto.c   | 2 +-
 hw/virtio/virtio.c  | 2 +-
 tests/libqos/virtio-mmio.c  | 4 ++--
 tests/libqos/virtio-pci.c   | 4 ++--
 8 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 9470bd7be7..fe739bb773 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -1054,10 +1054,8 @@ static void virtio_serial_device_realize(DeviceState 
*dev, Error **errp)
 QTAILQ_INIT(>ports);
 
 vser->bus.max_nr_ports = vser->serial.max_virtserial_ports;
-vser->ivqs = g_malloc(vser->serial.max_virtserial_ports
-  * sizeof(VirtQueue *));
-vser->ovqs = g_malloc(vser->serial.max_virtserial_ports
-  * sizeof(VirtQueue *));
+vser->ivqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);
+vser->ovqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);
 
 /* Add a queue for host to guest transfers for port 0 (backward compat) */
 vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 43bbe09ea0..fb3884220b 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -676,9 +676,9 @@ int virtio_gpu_create_mapping_iov(struct 
virtio_gpu_resource_attach_backing *ab,
 return -1;
 }
 
-*iov = g_malloc0(sizeof(struct iovec) * ab->nr_entries);
+*iov = g_new0(struct iovec, ab->nr_entries);
 if (addr) {
-*addr = g_malloc0(sizeof(uint64_t) * ab->nr_entries);
+*addr = g_new0(uint64_t, ab->nr_entries);
 }
 for (i = 0; i < ab->nr_entries; i++) {
 uint64_t a = le64_to_cpu(ents[i].addr);
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 150fd0748e..ce488b63d5 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -359,7 +359,7 @@ static RxFilterInfo 
*virtio_net_query_rxfilter(NetClientState *nc)
 strList *str_list, *entry;
 int i;
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(RxFilterInfo, 1);
 info->name = g_strdup(nc->name);
 info->promiscuous = n->promisc;
 
@@ -1978,7 +1978,7 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
 virtio_cleanup(vdev);
 return;
 }
-n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
+n->vqs = g_new0(VirtIONetQueue, n->max_queues);
 n->curr_queues = 1;
 n->tx_timeout = n->net_conf.txtimer;
 
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 5fd69f0b2e..f4abc1d26d 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -742,7 +742,7 @@ static void vhost_iommu_region_add(MemoryListener *listener,
 return;
 }
 
-iommu = g_malloc0(sizeof(*iommu));
+iommu = g_new0(struct vhost_iommu, 1);
 end = int128_add(int128_make64(section->offset_within_region),
  section->size);
 end = int128_sub(end, int128_one());
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 19c82e0432..9544ea92ef 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -798,7 +798,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, 
Error **errp)
 
 virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size);
 vcrypto->curr_queues = 1;
-vcrypto->vqs = g_malloc0(sizeof(VirtIOCryptoQueue) * vcrypto->max_queues);
+vcrypto->vqs = g_new0(VirtIOCryptoQueue, vcrypto->max_queues);
 for (i = 0; i < vcrypto->max_queues; i++) {
 vcrypto->vqs[i].dataq =
  virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_bh);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 311929e9df..9a38fe695a 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2245,7 +2245,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,
 atomic_set(>isr, 0);
 vdev->queue_sel = 0;
 vdev->config_vector = VIRTIO_NO_VECTOR;
-vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_QUEUE_MAX);
+vdev->vq = g_new0(VirtQueue, VIRTIO_QUEUE_MAX);
 vdev->vm_running = runstate_is_running();
 vdev->broken = false;
 for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
index 7aa8383338..a48fecab63 100644
--- a/tests/libqos/virtio-mmio.c
+++ b/tests/libqos/virtio-mmio.c
@@ -127,7 +127,7 @@ static QVirtQueue 
*qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,
 QVirtQueue *vq;
 uint64_t addr;
 
-vq = g_malloc0(sizeof(*vq));
+vq = g_new0(QVirtQueue, 1);
 qvirtio_mmio_queue_select(d, index);
 writel(dev->addr + 

[Qemu-devel] [PATCH 66/88] util/qemu-thread-win32: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 util/qemu-thread-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
index 94f3491a87..098fddb2af 100644
--- a/util/qemu-thread-win32.c
+++ b/util/qemu-thread-win32.c
@@ -394,7 +394,7 @@ void qemu_thread_create(QemuThread *thread, const char 
*name,
 HANDLE hThread;
 struct QemuThreadData *data;
 
-data = g_malloc(sizeof *data);
+data = g_new(struct QemuThreadData, 1);
 data->start_routine = start_routine;
 data->arg = arg;
 data->mode = mode;
-- 
2.14.2




[Qemu-devel] [PATCH 71/88] block: avoid use of g_new0()

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 block/qcow2.c | 2 +-
 block/vhdx.c  | 9 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index f63d1831f8..3e7d6c81be 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2738,7 +2738,7 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
 
 /* Write the header */
 QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
-header = g_malloc0(cluster_size);
+header = g_malloc(cluster_size);
 *header = (QCowHeader) {
 .magic  = cpu_to_be32(QCOW_MAGIC),
 .version= cpu_to_be32(version),
diff --git a/block/vhdx.c b/block/vhdx.c
index 8260fb46cd..91e532df8a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -244,10 +244,11 @@ static void vhdx_region_register(BDRVVHDXState *s,
 {
 VHDXRegionEntry *r;
 
-r = g_new0(VHDXRegionEntry, 1);
-
-r->start = start;
-r->end = start + length;
+r = g_new(VHDXRegionEntry, 1);
+*r = (VHDXRegionEntry) {
+.start = start,
+.end = start + length,
+};
 
 QLIST_INSERT_HEAD(>regions, r, entries);
 }
-- 
2.14.2




[Qemu-devel] [PATCH 63/88] bsd-user/syscall: fix a memory leak on EFAULT, use g_new()

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Kamil are you interested in maintaining bsd-user? :)
 
 bsd-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 66492aaf5d..9120cea61e 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -227,7 +227,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t 
namelen, abi_ulong ol
 void *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, *p, *q, i;
 uint32_t kind = 0;
 
 if (oldlenp)
@@ -239,6 +239,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t 
namelen, abi_ulong ol
 if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
 return -TARGET_EFAULT;
 holdlen = oldlen;
+snamep = g_new(int32_t, namelen);
 for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
*q++ = tswap32(*p);
 oidfmt(snamep, namelen, NULL, );
-- 
2.14.2




[Qemu-devel] [PATCH 80/88] numa: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/numa.c b/numa.c
index 100a67febf..35df996738 100644
--- a/numa.c
+++ b/numa.c
@@ -66,7 +66,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, 
uint32_t node)
 return;
 }
 
-range = g_malloc0(sizeof(*range));
+range = g_new0(struct numa_addr_range, 1);
 range->mem_start = addr;
 range->mem_end = addr + size - 1;
 QLIST_INSERT_HEAD(_info[node].addr, range, entry);
-- 
2.14.2




[Qemu-devel] [PATCH 64/88] user: use g_strfreev()

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 bsd-user/main.c   | 6 +-
 linux-user/main.c | 6 +-
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 836daac15c..fb0a4e48cb 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -947,11 +947,7 @@ int main(int argc, char **argv)
 _exit(1);
 }
 
-for (wrk = target_environ; *wrk; wrk++) {
-g_free(*wrk);
-}
-
-g_free(target_environ);
+g_strfreev(target_environ);
 
 if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
 qemu_log("guest_base  0x%lx\n", guest_base);
diff --git a/linux-user/main.c b/linux-user/main.c
index 829f974662..f1e799f570 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -4426,11 +4426,7 @@ int main(int argc, char **argv, char **envp)
 _exit(EXIT_FAILURE);
 }
 
-for (wrk = target_environ; *wrk; wrk++) {
-g_free(*wrk);
-}
-
-g_free(target_environ);
+g_strfreev(target_environ);
 
 if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
 qemu_log("guest_base  0x%lx\n", guest_base);
-- 
2.14.2




[Qemu-devel] [PATCH 69/88] virtio-9p: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added 2 more uses in hw/9pfs/9p-synth.c]
---
 hw/9pfs/9p-handle.c | 2 +-
 hw/9pfs/9p-proxy.c  | 2 +-
 hw/9pfs/9p-synth.c  | 8 
 hw/9pfs/9p.c| 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index 9875f1894c..357ced3079 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -609,7 +609,7 @@ static int handle_init(FsContext *ctx)
 int ret, mnt_id;
 struct statfs stbuf;
 struct file_handle fh;
-struct handle_data *data = g_malloc(sizeof(struct handle_data));
+struct handle_data *data = g_new(struct handle_data, 1);
 
 data->mountfd = open(ctx->fs_root, O_DIRECTORY);
 if (data->mountfd < 0) {
diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index 28b20a7c3d..2de303d713 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -1136,7 +1136,7 @@ static int proxy_parse_opts(QemuOpts *opts, struct 
FsDriverEntry *fs)
 
 static int proxy_init(FsContext *ctx)
 {
-V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy));
+V9fsProxy *proxy = g_new(V9fsProxy, 1);
 int sock_id;
 
 if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index df0a8de08a..3aa69cf465 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -43,7 +43,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode 
*parent, int mode,
 
 /* Add directory type and remove write bits */
 mode = ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH);
-node = g_malloc0(sizeof(V9fsSynthNode));
+node = g_new0(V9fsSynthNode, 1);
 if (attr) {
 /* We are adding .. or . entries */
 node->attr = attr;
@@ -124,7 +124,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int 
mode,
 }
 /* Add file type and remove write bits */
 mode = ((mode & 0777) | S_IFREG);
-node = g_malloc0(sizeof(V9fsSynthNode));
+node = g_new0(V9fsSynthNode, 1);
 node->attr = >actual_attr;
 node->attr->inode  = synth_node_count++;
 node->attr->nlink  = 1;
@@ -180,7 +180,7 @@ static int synth_opendir(FsContext *ctx,
 V9fsSynthOpenState *synth_open;
 V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-synth_open = g_malloc(sizeof(*synth_open));
+synth_open = g_new(V9fsSynthOpenState, 1);
 synth_open->node = node;
 node->open_count++;
 fs->private = synth_open;
@@ -264,7 +264,7 @@ static int synth_open(FsContext *ctx, V9fsPath *fs_path,
 V9fsSynthOpenState *synth_open;
 V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-synth_open = g_malloc(sizeof(*synth_open));
+synth_open = g_new(V9fsSynthOpenState, 1);
 synth_open->node = node;
 node->open_count++;
 fs->private = synth_open;
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 23ac7bb532..510867b4dc 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -298,7 +298,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;
-- 
2.14.2




[Qemu-devel] [PATCH 75/88] decnumber: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 libdecnumber/decNumber.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libdecnumber/decNumber.c b/libdecnumber/decNumber.c
index 8c197023f4..2d13198730 100644
--- a/libdecnumber/decNumber.c
+++ b/libdecnumber/decNumber.c
@@ -4089,7 +4089,7 @@ static decNumber * decAddOp(decNumber *res, const 
decNumber *lhs,
   acc=accbuff; /* assume use local buffer */
   if (need*sizeof(Unit)>sizeof(accbuff)) {
/* printf("malloc add %ld %ld\n", need, sizeof(accbuff)); */
-   allocacc=(Unit *)malloc(need*sizeof(Unit));
+   allocacc=g_new(uint16_t, need);
if (allocacc==NULL) {   /* hopeless -- abandon */
  *status|=DEC_Insufficient_storage;
  break;}
@@ -4452,7 +4452,7 @@ static decNumber * decDivideOp(decNumber *res,
 acclength=D2U(reqdigits+DECDPUN);  /* in Units */
 if (acclength*sizeof(Unit)>sizeof(accbuff)) {
   /* printf("malloc dvacc %ld units\n", acclength); */
-  allocacc=(Unit *)malloc(acclength*sizeof(Unit));
+  allocacc=g_new(uint16_t, acclength);
   if (allocacc==NULL) {/* hopeless -- abandon */
*status|=DEC_Insufficient_storage;
break;}
@@ -4477,7 +4477,7 @@ static decNumber * decDivideOp(decNumber *res,
 if (!(op)) var1units++;
 if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) {
   /* printf("malloc dvvar %ld units\n", var1units+1); */
-  varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit));
+  varalloc=g_new(uint16_t, (var1units+1));
   if (varalloc==NULL) {/* hopeless -- abandon */
*status|=DEC_Insufficient_storage;
break;}
@@ -6314,7 +6314,7 @@ static Int decUnitCompare(const Unit *a, Int alength,
   need+=2;
   acc=accbuff; /* assume use local buffer */
   if (need*sizeof(Unit)>sizeof(accbuff)) {
-allocacc=(Unit *)malloc(need*sizeof(Unit));
+allocacc=g_new(uint16_t, need);
 if (allocacc==NULL) return BADINT; /* hopeless -- abandon */
 acc=allocacc;
 }
-- 
2.14.2




[Qemu-devel] [PATCH 60/88] sPAPR: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: one more change in hw/ppc/spapr_events.c,
  added hw/intc/xics_kvm.c and tests/libqos/pci-spapr.c]
---
 hw/intc/xics.c   | 2 +-
 hw/intc/xics_kvm.c   | 4 ++--
 hw/ppc/spapr.c   | 2 +-
 hw/ppc/spapr_events.c| 4 ++--
 hw/ppc/spapr_iommu.c | 2 +-
 hw/ppc/spapr_pci.c   | 2 +-
 tests/libqos/pci-spapr.c | 2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index cc9816e7f2..e7e1605a1c 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -603,7 +603,7 @@ static void ics_simple_realize(ICSState *ics, Error **errp)
 error_setg(errp, "Number of interrupts needs to be greater 0");
 return;
 }
-ics->irqs = g_malloc0(ics->nr_irqs * sizeof(ICSIRQState));
+ics->irqs = g_new0(ICSIRQState, ics->nr_irqs);
 ics->qirqs = qemu_allocate_irqs(ics_simple_set_irq, ics, ics->nr_irqs);
 
 qemu_register_reset(ics_simple_reset, ics);
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index 3091ad3ac2..e6742b0118 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -143,7 +143,7 @@ static void icp_kvm_realize(ICPState *icp, Error **errp)
strerror(errno));
 return;
 }
-enabled_icp = g_malloc(sizeof(*enabled_icp));
+enabled_icp = g_new(KVMEnabledICP, 1);
 enabled_icp->vcpu_id = vcpu_id;
 QLIST_INSERT_HEAD(_enabled_icps, enabled_icp, node);
 }
@@ -334,7 +334,7 @@ static void ics_kvm_realize(ICSState *ics, Error **errp)
 error_setg(errp, "Number of interrupts needs to be greater 0");
 return;
 }
-ics->irqs = g_malloc0(ics->nr_irqs * sizeof(ICSIRQState));
+ics->irqs = g_new0(ICSIRQState, ics->nr_irqs);
 ics->qirqs = qemu_allocate_irqs(ics_kvm_set_irq, ics, ics->nr_irqs);
 
 qemu_register_reset(ics_kvm_reset, ics);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index ff87f155d5..53492595f2 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2988,7 +2988,7 @@ static sPAPRDIMMState 
*spapr_pending_dimm_unplugs_add(sPAPRMachineState *spapr,
  */
 ds = spapr_pending_dimm_unplugs_find(spapr, dimm);
 if (!ds) {
-ds = g_malloc0(sizeof(sPAPRDIMMState));
+ds = g_new0(sPAPRDIMMState, 1);
 ds->nr_lmbs = nr_lmbs;
 ds->dimm = dimm;
 QTAILQ_INSERT_HEAD(>pending_dimm_unplugs, ds, next);
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index e377fc7dde..0ff4c2404f 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -437,7 +437,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
 struct epow_extended_log *new_epow;
 
 entry = g_new(sPAPREventLogEntry, 1);
-new_epow = g_malloc0(sizeof(*new_epow));
+new_epow = g_new0(struct epow_extended_log, 1);
 entry->extended_log = new_epow;
 
 v6hdr = _epow->v6hdr;
@@ -490,7 +490,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t 
hp_action,
 struct rtas_event_log_v6_hp *hp;
 
 entry = g_new(sPAPREventLogEntry, 1);
-new_hp = g_malloc0(sizeof(struct hp_extended_log));
+new_hp = g_new0(struct hp_extended_log, 1);
 entry->extended_log = new_hp;
 
 v6hdr = _hp->v6hdr;
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 5ccd785d5a..36cf3d6908 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -93,7 +93,7 @@ static uint64_t *spapr_tce_alloc_table(uint32_t liobn,
 
 if (!table) {
 *fd = -1;
-table = g_malloc0(nb_table * sizeof(uint64_t));
+table = g_new0(uint64_t, nb_table);
 }
 
 trace_spapr_iommu_new_table(liobn, table, *fd);
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 5049ced4e8..4ec31f65c5 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1825,7 +1825,7 @@ static int spapr_pci_pre_save(void *opaque)
 if (!sphb->msi_devs_num) {
 return 0;
 }
-sphb->msi_devs = g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_mig));
+sphb->msi_devs = g_new(spapr_pci_msi_mig, sphb->msi_devs_num);
 
 g_hash_table_iter_init(, sphb->msi);
 for (i = 0; g_hash_table_iter_next(, , ); ++i) {
diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c
index 2043f1e123..e3816ec29f 100644
--- a/tests/libqos/pci-spapr.c
+++ b/tests/libqos/pci-spapr.c
@@ -158,7 +158,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
 {
 QPCIBusSPAPR *ret;
 
-ret = g_malloc(sizeof(*ret));
+ret = g_new(QPCIBusSPAPR, 1);
 
 ret->alloc = alloc;
 
-- 
2.14.2




[Qemu-devel] [PATCH 56/88] PowerPC: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: one more change in target/ppc/translate_init.c, added target/ppc/kvm.c]
---
 hw/ppc/ppc.c|  8 
 hw/ppc/ppc_booke.c  |  4 ++--
 target/ppc/kvm.c|  2 +-
 target/ppc/translate_init.c | 14 +++---
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 05da316e0b..647d70fc13 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -965,7 +965,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t 
freq)
 PowerPCCPU *cpu = ppc_env_get_cpu(env);
 ppc_tb_t *tb_env;
 
-tb_env = g_malloc0(sizeof(ppc_tb_t));
+tb_env = g_new0(ppc_tb_t, 1);
 env->tb_env = tb_env;
 tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
 if (env->insns_flags & PPC_SEGMENT_64B) {
@@ -1224,10 +1224,10 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *env, 
uint32_t freq,
 ppc_tb_t *tb_env;
 ppc40x_timer_t *ppc40x_timer;
 
-tb_env = g_malloc0(sizeof(ppc_tb_t));
+tb_env = g_new0(ppc_tb_t, 1);
 env->tb_env = tb_env;
 tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
-ppc40x_timer = g_malloc0(sizeof(ppc40x_timer_t));
+ppc40x_timer = g_new0(ppc40x_timer_t, 1);
 tb_env->tb_freq = freq;
 tb_env->decr_freq = freq;
 tb_env->opaque = ppc40x_timer;
@@ -1332,7 +1332,7 @@ int ppc_dcr_init (CPUPPCState *env, int (*read_error)(int 
dcrn),
 {
 ppc_dcr_t *dcr_env;
 
-dcr_env = g_malloc0(sizeof(ppc_dcr_t));
+dcr_env = g_new0(ppc_dcr_t, 1);
 dcr_env->read_error = read_error;
 dcr_env->write_error = write_error;
 env->dcr_env = dcr_env;
diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c
index 23bcf1b138..dafc6aa3fc 100644
--- a/hw/ppc/ppc_booke.c
+++ b/hw/ppc/ppc_booke.c
@@ -339,8 +339,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, 
uint32_t flags)
 booke_timer_t *booke_timer;
 int ret = 0;
 
-tb_env  = g_malloc0(sizeof(ppc_tb_t));
-booke_timer = g_malloc0(sizeof(booke_timer_t));
+tb_env  = g_new0(ppc_tb_t, 1);
+booke_timer = g_new0(booke_timer_t, 1);
 
 cpu->env.tb_env = tb_env;
 tb_env->flags = flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED;
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 171d3d8040..d8565fd4a3 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -364,7 +364,7 @@ struct ppc_radix_page_info *kvm_get_radix_page_info(void)
 if (kvm_vm_ioctl(s, KVM_PPC_GET_RMMU_INFO, _info)) {
 return NULL;
 }
-radix_page_info = g_malloc0(sizeof(*radix_page_info));
+radix_page_info = g_new0(struct ppc_radix_page_info, 1);
 radix_page_info->count = 0;
 for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
 if (rmmu_info.ap_encodings[i]) {
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
index c6399a3a0d..850ff038ca 100644
--- a/target/ppc/translate_init.c
+++ b/target/ppc/translate_init.c
@@ -9341,13 +9341,13 @@ static void init_ppc_proc(PowerPCCPU *cpu)
 nb_tlb *= 2;
 switch (env->tlb_type) {
 case TLB_6XX:
-env->tlb.tlb6 = g_malloc0(nb_tlb * sizeof(ppc6xx_tlb_t));
+env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
 break;
 case TLB_EMB:
-env->tlb.tlbe = g_malloc0(nb_tlb * sizeof(ppcemb_tlb_t));
+env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
 break;
 case TLB_MAS:
-env->tlb.tlbm = g_malloc0(nb_tlb * sizeof(ppcmas_tlb_t));
+env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
 break;
 }
 /* Pre-compute some useful values */
@@ -10442,11 +10442,11 @@ static void ppc_cpu_defs_entry(gpointer data, 
gpointer user_data)
 }
 
 typename = object_class_get_name(oc);
-info = g_malloc0(sizeof(*info));
+info = g_new0(CpuDefinitionInfo, 1);
 info->name = g_strndup(typename,
strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(CpuDefinitionInfoList, 1);
 entry->value = info;
 entry->next = *first;
 *first = entry;
@@ -10473,11 +10473,11 @@ CpuDefinitionInfoList 
*arch_query_cpu_definitions(Error **errp)
 continue;
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(CpuDefinitionInfo, 1);
 info->name = g_strdup(alias->alias);
 info->q_typename = g_strdup(object_class_get_name(oc));
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(CpuDefinitionInfoList, 1);
 entry->value = info;
 entry->next = cpu_list;
 cpu_list = entry;
-- 
2.14.2




[Qemu-devel] [PATCH 67/88] util/coroutine: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 util/coroutine-sigaltstack.c | 2 +-
 util/coroutine-ucontext.c| 2 +-
 util/coroutine-win32.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/util/coroutine-sigaltstack.c b/util/coroutine-sigaltstack.c
index f6fc49a0e5..4fe4bbf1b5 100644
--- a/util/coroutine-sigaltstack.c
+++ b/util/coroutine-sigaltstack.c
@@ -163,7 +163,7 @@ Coroutine *qemu_coroutine_new(void)
  * sigaltstack way of manipulating stacks.
  */
 
-co = g_malloc0(sizeof(*co));
+co = g_new0(CoroutineSigAltStack, 1);
 co->stack_size = COROUTINE_STACK_SIZE;
 co->stack = qemu_alloc_stack(>stack_size);
 co->base.entry_arg = _env; /* stash away our jmp_buf */
diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c
index 6621f3f692..c14dca19b4 100644
--- a/util/coroutine-ucontext.c
+++ b/util/coroutine-ucontext.c
@@ -100,7 +100,7 @@ Coroutine *qemu_coroutine_new(void)
 abort();
 }
 
-co = g_malloc0(sizeof(*co));
+co = g_new0(CoroutineUContext, 1);
 co->stack_size = COROUTINE_STACK_SIZE;
 co->stack = qemu_alloc_stack(>stack_size);
 co->base.entry_arg = _env; /* stash away our jmp_buf */
diff --git a/util/coroutine-win32.c b/util/coroutine-win32.c
index de6bd4fd3e..6762ff83c2 100644
--- a/util/coroutine-win32.c
+++ b/util/coroutine-win32.c
@@ -74,7 +74,7 @@ Coroutine *qemu_coroutine_new(void)
 const size_t stack_size = COROUTINE_STACK_SIZE;
 CoroutineWin32 *co;
 
-co = g_malloc0(sizeof(*co));
+co = g_new0(CoroutineWin32, 1);
 co->fiber = CreateFiber(stack_size, coroutine_trampoline, >base);
 return >base;
 }
-- 
2.14.2




[Qemu-devel] [PATCH 72/88] hw/block/nvme: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 9aa32692a3..ff712fa8cc 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -454,7 +454,7 @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd)
 if (!(NVME_SQ_FLAGS_PC(qflags))) {
 return NVME_INVALID_FIELD | NVME_DNR;
 }
-sq = g_malloc0(sizeof(*sq));
+sq = g_new0(NvmeSQueue, 1);
 nvme_init_sq(sq, n, prp1, sqid, cqid, qsize + 1);
 return NVME_SUCCESS;
 }
@@ -532,7 +532,7 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)
 return NVME_INVALID_FIELD | NVME_DNR;
 }
 
-cq = g_malloc0(sizeof(*cq));
+cq = g_new0(NvmeCQueue, 1);
 nvme_init_cq(cq, n, prp1, cqid, vector, qsize + 1,
 NVME_CQ_FLAGS_IEN(qflags));
 return NVME_SUCCESS;
-- 
2.14.2




[Qemu-devel] [PATCH 53/88] iSCSI: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 block/iscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 4683f3b244..f9f910168d 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1001,7 +1001,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
 return NULL;
 }
 
-acb->task = malloc(sizeof(struct scsi_task));
+acb->task = g_new(struct scsi_task, 1);
 if (acb->task == NULL) {
 error_report("iSCSI: Failed to allocate task for scsi command. %s",
  iscsi_get_error(iscsi));
-- 
2.14.2




[Qemu-devel] [PATCH 54/88] KVM: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes]
---
 accel/kvm/kvm-all.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 90c88b517d..12568d703c 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -278,7 +278,7 @@ int kvm_destroy_vcpu(CPUState *cpu)
 goto err;
 }
 
-vcpu = g_malloc0(sizeof(*vcpu));
+vcpu = g_new0(struct KVMParkedVcpu, 1);
 vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
 vcpu->kvm_fd = cpu->kvm_fd;
 QLIST_INSERT_HEAD(_state->kvm_parked_vcpus, vcpu, node);
@@ -865,7 +865,7 @@ void kvm_memory_listener_register(KVMState *s, 
KVMMemoryListener *kml,
 {
 int i;
 
-kml->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot));
+kml->slots = g_new0(KVMSlot, s->nr_slots);
 kml->as_id = as_id;
 
 for (i = 0; i < s->nr_slots; i++) {
@@ -1129,7 +1129,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
 return virq;
 }
 
-route = g_malloc0(sizeof(KVMMSIRoute));
+route = g_new0(KVMMSIRoute, 1);
 route->kroute.gsi = virq;
 route->kroute.type = KVM_IRQ_ROUTING_MSI;
 route->kroute.flags = 0;
@@ -2243,7 +2243,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong 
addr,
 return 0;
 }
 
-bp = g_malloc(sizeof(struct kvm_sw_breakpoint));
+bp = g_new(struct kvm_sw_breakpoint, 1);
 bp->pc = addr;
 bp->use_count = 1;
 err = kvm_arch_insert_sw_breakpoint(cpu, bp);
-- 
2.14.2




[Qemu-devel] [PATCH 65/88] util: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes in util/envlist.c, more files updated]
---
 util/acl.c | 6 +++---
 util/envlist.c | 6 +++---
 util/error.c   | 2 +-
 util/iohandler.c   | 2 +-
 util/module.c  | 4 ++--
 util/qemu-option.c | 8 
 util/qht.c | 2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/util/acl.c b/util/acl.c
index c105addadc..f5d8295fe2 100644
--- a/util/acl.c
+++ b/util/acl.c
@@ -56,7 +56,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
@@ -117,7 +117,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;
 
@@ -146,7 +146,7 @@ int qemu_acl_insert(qemu_acl *acl,
 i++;
 if (i == index) {
 qemu_acl_entry *entry;
-entry = g_malloc(sizeof(*entry));
+entry = g_new(qemu_acl_entry, 1);
 entry->match = g_strdup(match);
 entry->deny = deny;
 
diff --git a/util/envlist.c b/util/envlist.c
index 1eeb7fca87..5934095b7d 100644
--- a/util/envlist.c
+++ b/util/envlist.c
@@ -24,7 +24,7 @@ envlist_create(void)
 {
envlist_t *envlist;
 
-   envlist = g_malloc(sizeof(*envlist));
+   envlist = g_new(envlist_t, 1);
 
QLIST_INIT(>el_entries);
envlist->el_count = 0;
@@ -158,7 +158,7 @@ envlist_setenv(envlist_t *envlist, const char *env)
envlist->el_count++;
}
 
-   entry = g_malloc(sizeof(*entry));
+   entry = g_new(struct envlist_entry, 1);
entry->ev_var = g_strdup(env);
QLIST_INSERT_HEAD(>el_entries, entry, ev_link);
 
@@ -218,7 +218,7 @@ envlist_to_environ(const envlist_t *envlist, size_t *count)
struct envlist_entry *entry;
char **env, **penv;
 
-   penv = env = g_malloc((envlist->el_count + 1) * sizeof(char *));
+   penv = env = g_new(char *, envlist->el_count + 1);
 
for (entry = envlist->el_entries.lh_first; entry != NULL;
entry = entry->ev_link.le_next) {
diff --git a/util/error.c b/util/error.c
index 3efdd69162..cfb829b1f8 100644
--- a/util/error.c
+++ b/util/error.c
@@ -56,7 +56,7 @@ static void error_setv(Error **errp,
 }
 assert(*errp == NULL);
 
-err = g_malloc0(sizeof(*err));
+err = g_new0(Error, 1);
 err->msg = g_strdup_vprintf(fmt, ap);
 if (suffix) {
 char *msg = err->msg;
diff --git a/util/iohandler.c b/util/iohandler.c
index 623b55b9ec..518922dcea 100644
--- a/util/iohandler.c
+++ b/util/iohandler.c
@@ -128,7 +128,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(_watches, rec, next);
 return 0;
diff --git a/util/module.c b/util/module.c
index c90973721f..1533dbdc63 100644
--- a/util/module.c
+++ b/util/module.c
@@ -65,7 +65,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;
 e->type = type;
 
@@ -80,7 +80,7 @@ void register_dso_module_init(void (*fn)(void), 
module_init_type type)
 
 init_lists();
 
-e = g_malloc0(sizeof(*e));
+e = g_new0(ModuleEntry, 1);
 e->init = fn;
 e->type = type;
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9b1dc8093b..8a121bfc40 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -534,7 +534,7 @@ static void opt_set(QemuOpts *opts, const char *name, const 
char *value,
 return;
 }
 
-opt = g_malloc0(sizeof(*opt));
+opt = g_new0(QemuOpt, 1);
 opt->name = g_strdup(name);
 opt->opts = opts;
 if (prepend) {
@@ -564,7 +564,7 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, 
bool val,
 QemuOpt *opt;
 const QemuOptDesc *desc = opts->list->desc;
 
-opt = g_malloc0(sizeof(*opt));
+opt = g_new0(QemuOpt, 1);
 opt->desc = find_desc_by_name(desc, name);
 if (!opt->desc && !opts_accepts_any(opts)) {
 error_setg(errp, QERR_INVALID_PARAMETER, name);
@@ -585,7 +585,7 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, 
int64_t val,
 QemuOpt *opt;
 const QemuOptDesc *desc = opts->list->desc;
 
-opt = g_malloc0(sizeof(*opt));
+opt = g_new0(QemuOpt, 1);
 opt->desc = find_desc_by_name(desc, name);
 if (!opt->desc && !opts_accepts_any(opts)) {
 error_setg(errp, 

[Qemu-devel] [PATCH 70/88] block: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 block/backup.c |  2 +-
 block/blkdebug.c   |  4 ++--
 block/commit.c |  2 +-
 block/linux-aio.c  |  2 +-
 block/mirror.c |  2 +-
 block/qapi.c   |  4 ++--
 block/qcow2-refcount.c | 12 +---
 block/qed-l2-cache.c   |  2 +-
 block/sheepdog.c   |  2 +-
 block/stream.c |  2 +-
 block/vhdx.c   |  2 +-
 block/win32-aio.c  |  2 +-
 12 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index 06ddbfd03d..cd73e7d905 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -514,7 +514,7 @@ static void coroutine_fn backup_run(void *opaque)
 qemu_co_rwlock_unlock(>flush_rwlock);
 g_free(job->done_bitmap);
 
-data = g_malloc(sizeof(*data));
+data = g_new(BackupCompleteData, 1);
 data->ret = ret;
 block_job_defer_to_main_loop(>common, backup_complete, data);
 }
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 46e53f2f09..4d05bcb1d9 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -175,7 +175,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error 
**errp)
 }
 
 /* Set attributes common for all actions */
-rule = g_malloc0(sizeof(*rule));
+rule = g_new(struct BlkdebugRule, 1);
 *rule = (struct BlkdebugRule) {
 .event  = event,
 .action = d->action,
@@ -727,7 +727,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, 
const char *event,
 return -ENOENT;
 }
 
-rule = g_malloc(sizeof(*rule));
+rule = g_new(struct BlkdebugRule, 1);
 *rule = (struct BlkdebugRule) {
 .event  = blkdebug_event,
 .action = ACTION_SUSPEND,
diff --git a/block/commit.c b/block/commit.c
index 5036eec434..e698311d5f 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -210,7 +210,7 @@ static void coroutine_fn commit_run(void *opaque)
 out:
 qemu_vfree(buf);
 
-data = g_malloc(sizeof(*data));
+data = g_new(CommitCompleteData, 1);
 data->ret = ret;
 block_job_defer_to_main_loop(>common, commit_complete, data);
 }
diff --git a/block/linux-aio.c b/block/linux-aio.c
index 88b8d55ec7..e5a9d7fdeb 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -474,7 +474,7 @@ LinuxAioState *laio_init(void)
 {
 LinuxAioState *s;
 
-s = g_malloc0(sizeof(*s));
+s = g_new0(LinuxAioState, 1);
 if (event_notifier_init(>e, false) < 0) {
 goto out_free_state;
 }
diff --git a/block/mirror.c b/block/mirror.c
index 153758ca9f..948e5321a7 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -904,7 +904,7 @@ immediate_exit:
 g_free(s->in_flight_bitmap);
 bdrv_dirty_iter_free(s->dbi);
 
-data = g_malloc(sizeof(*data));
+data = g_new(MirrorExitData, 1);
 data->ret = ret;
 
 if (need_drain) {
diff --git a/block/qapi.c b/block/qapi.c
index 7fa2437923..808246bfc4 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -455,7 +455,7 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState 
*bs,
 {
 BlockStats *s = NULL;
 
-s = g_malloc0(sizeof(*s));
+s = g_new0(BlockStats, 1);
 s->stats = g_malloc0(sizeof(*s->stats));
 
 if (!bs) {
@@ -503,7 +503,7 @@ BlockInfoList *qmp_query_block(Error **errp)
 continue;
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(BlockInfoList, 1);
 bdrv_query_info(blk, >value, _err);
 if (local_err) {
 error_propagate(errp, local_err);
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index aa3fd6cf17..dd2387d2bb 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -755,7 +755,7 @@ static void update_refcount_discard(BlockDriverState *bs,
 }
 }
 
-d = g_malloc(sizeof(*d));
+d = g_new(Qcow2DiscardRegion, 1);
 *d = (Qcow2DiscardRegion) {
 .bs = bs,
 .offset = offset,
@@ -2189,9 +2189,8 @@ write_refblocks:
 
 reftable_size = ROUND_UP((refblock_index + 1) * sizeof(uint64_t),
  s->cluster_size) / sizeof(uint64_t);
-new_on_disk_reftable = g_try_realloc(on_disk_reftable,
- reftable_size *
- sizeof(uint64_t));
+new_on_disk_reftable = g_try_renew(uint64_t, on_disk_reftable,
+   reftable_size);
 if (!new_on_disk_reftable) {
 res->check_errors++;
 ret = -ENOMEM;
@@ -2656,8 +2655,7 @@ static int alloc_refblock(BlockDriverState *bs, uint64_t 
**reftable,
 return -ENOTSUP;
 }
 
-new_reftable = g_try_realloc(*reftable, new_reftable_size *
-sizeof(uint64_t));
+new_reftable = g_try_renew(uint64_t, *reftable, new_reftable_size);
 if (!new_reftable) {
 error_setg(errp, "Failed to increase reftable buffer 

[Qemu-devel] [PATCH 51/88] hw/timer: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/timer/slavio_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c
index a8cc9c0148..6d0282a788 100644
--- a/hw/timer/slavio_timer.c
+++ b/hw/timer/slavio_timer.c
@@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
 uint64_t size;
 char timer_name[20];
 
-tc = g_malloc0(sizeof(TimerContext));
+tc = g_new0(TimerContext, 1);
 tc->s = s;
 tc->timer_index = i;
 
-- 
2.14.2




[Qemu-devel] [PATCH 62/88] user: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added linux-user/elfload.c]
---
 linux-user/elfload.c | 2 +-
 thunk.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 79062882ba..0a826071e9 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3014,7 +3014,7 @@ static void fill_thread_info(struct elf_note_info *info, 
const CPUArchState *env
 TaskState *ts = (TaskState *)cpu->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(>prstatus, ts, 0);
 elf_core_copy_regs(>prstatus.pr_reg, env);
diff --git a/thunk.c b/thunk.c
index d5d8645cd4..17f3d320bb 100644
--- a/thunk.c
+++ b/thunk.c
@@ -89,7 +89,7 @@ void thunk_register_struct(int id, const char *name, const 
argtype *types)
 for(i = 0;i < 2; i++) {
 offset = 0;
 max_align = 1;
-se->field_offsets[i] = malloc(nb_fields * sizeof(int));
+se->field_offsets[i] = g_new(int, nb_fields);
 type_ptr = se->field_types;
 for(j = 0;j < nb_fields; j++) {
 size = thunk_type_size(type_ptr, i);
-- 
2.14.2




[Qemu-devel] [PATCH 49/88] hw/misc: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added hw/misc/pvpanic.c]
---
 hw/misc/applesmc.c | 2 +-
 hw/misc/pvpanic.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 7be8b5f13c..12e32b107e 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -252,7 +252,7 @@ static void applesmc_add_key(AppleSMCState *s, const char 
*key,
 {
 struct AppleSMCData *def;
 
-def = g_malloc0(sizeof(struct AppleSMCData));
+def = g_new0(struct AppleSMCData, 1);
 def->key = key;
 def->len = len;
 def->data = data;
diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c
index 2b1e9a6450..dc51e4386c 100644
--- a/hw/misc/pvpanic.c
+++ b/hw/misc/pvpanic.c
@@ -95,7 +95,7 @@ static void pvpanic_isa_realizefn(DeviceState *dev, Error 
**errp)
 return;
 }
 
-pvpanic_port = g_malloc(sizeof(*pvpanic_port));
+pvpanic_port = g_new(uint16_t, 1);
 *pvpanic_port = cpu_to_le16(s->ioport);
 fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
 sizeof(*pvpanic_port));
-- 
2.14.2




[Qemu-devel] [PATCH 61/88] tests: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: split of some files in other commits of the same series, add libqtest.c]
---
 tests/ahci-test.c | 4 ++--
 tests/fw_cfg-test.c   | 4 ++--
 tests/libqos/ahci.c   | 2 +-
 tests/libqos/libqos.c | 2 +-
 tests/libqos/malloc.c | 6 +++---
 tests/libqtest.c  | 2 +-
 tests/pc-cpu-test.c   | 2 +-
 7 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tests/ahci-test.c b/tests/ahci-test.c
index 999121bb7c..cb84edc8fb 100644
--- a/tests/ahci-test.c
+++ b/tests/ahci-test.c
@@ -155,7 +155,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
 {
 AHCIQState *s;
 
-s = g_malloc0(sizeof(AHCIQState));
+s = g_new0(AHCIQState, 1);
 s->parent = qtest_pc_vboot(cli, ap);
 alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
 
@@ -1806,7 +1806,7 @@ static void create_ahci_io_test(enum IOMode type, enum 
AddrMode addr,
 char *name;
 AHCIIOTestOptions *opts;
 
-opts = g_malloc(sizeof(AHCIIOTestOptions));
+opts = g_new(AHCIIOTestOptions, 1);
 opts->length = len;
 opts->address_type = addr;
 opts->io_type = type;
diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
index 688342bed5..81f45bdfc8 100644
--- a/tests/fw_cfg-test.c
+++ b/tests/fw_cfg-test.c
@@ -79,8 +79,8 @@ static void test_fw_cfg_numa(void)
 
 g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
 
-cpu_mask = g_malloc0(sizeof(uint64_t) * max_cpus);
-node_mask = g_malloc0(sizeof(uint64_t) * nb_nodes);
+cpu_mask = g_new0(uint64_t, max_cpus);
+node_mask = g_new0(uint64_t, nb_nodes);
 
 qfw_cfg_read_data(fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
 qfw_cfg_read_data(fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
index 1ca7f456b5..13c0749582 100644
--- a/tests/libqos/ahci.c
+++ b/tests/libqos/ahci.c
@@ -843,7 +843,7 @@ AHCICommand *ahci_command_create(uint8_t command_name)
 AHCICommand *cmd;
 
 g_assert(props);
-cmd = g_malloc0(sizeof(AHCICommand));
+cmd = g_new0(AHCICommand, 1);
 g_assert(!(props->dma && props->pio));
 g_assert(!(props->lba28 && props->lba48));
 g_assert(!(props->read && props->write));
diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
index 6226546c28..991bc1aec2 100644
--- a/tests/libqos/libqos.c
+++ b/tests/libqos/libqos.c
@@ -17,7 +17,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, 
va_list ap)
 {
 char *cmdline;
 
-struct QOSState *qs = g_malloc(sizeof(QOSState));
+struct QOSState *qs = g_new(QOSState, 1);
 
 cmdline = g_strdup_vprintf(cmdline_fmt, ap);
 qs->qts = qtest_start(cmdline);
diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c
index b8eff5f495..ac05874b0a 100644
--- a/tests/libqos/malloc.c
+++ b/tests/libqos/malloc.c
@@ -129,7 +129,7 @@ static MemBlock *mlist_new(uint64_t addr, uint64_t size)
 if (!size) {
 return NULL;
 }
-block = g_malloc0(sizeof(MemBlock));
+block = g_new0(MemBlock, 1);
 
 block->addr = addr;
 block->size = size;
@@ -305,8 +305,8 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end)
 s->start = start;
 s->end = end;
 
-s->used = g_malloc(sizeof(MemList));
-s->free = g_malloc(sizeof(MemList));
+s->used = g_new(MemList, 1);
+s->free = g_new(MemList, 1);
 QTAILQ_INIT(s->used);
 QTAILQ_INIT(s->free);
 
diff --git a/tests/libqtest.c b/tests/libqtest.c
index cbd709470b..adf71188b6 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -171,7 +171,7 @@ QTestState *qtest_init_without_qmp_handshake(const char 
*extra_args)
 gchar *command;
 const char *qemu_binary = qtest_qemu_binary();
 
-s = g_malloc(sizeof(*s));
+s = g_new(QTestState, 1);
 
 socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
 qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
diff --git a/tests/pc-cpu-test.c b/tests/pc-cpu-test.c
index c4211a4e85..11d3e810ef 100644
--- a/tests/pc-cpu-test.c
+++ b/tests/pc-cpu-test.c
@@ -87,7 +87,7 @@ static void add_pc_test_case(const char *mname)
 if (!g_str_has_prefix(mname, "pc-")) {
 return;
 }
-data = g_malloc(sizeof(PCTestData));
+data = g_new(PCTestData, 1);
 data->machine = g_strdup(mname);
 data->cpu_model = "Haswell"; /* 1.3+ theoretically */
 data->sockets = 1;
-- 
2.14.2




[Qemu-devel] [PATCH 59/88] ppce500: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: replaced g_new0() -> g_new() since no bzero() required]
---
 hw/ppc/e500.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index db0e49ab8f..b396fd1a22 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -737,8 +737,6 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, 
PPCE500Params *params,
 SysBusDevice *s;
 int i;
 
-mpic = g_new0(qemu_irq, 256);
-
 if (kvm_enabled()) {
 Error *err = NULL;
 
@@ -756,6 +754,7 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, 
PPCE500Params *params,
 dev = ppce500_init_mpic_qemu(params, irqs);
 }
 
+mpic = g_new(qemu_irq, 256);
 for (i = 0; i < 256; i++) {
 mpic[i] = qdev_get_gpio_in(dev, i);
 }
@@ -808,7 +807,7 @@ void ppce500_init(MachineState *machine, PPCE500Params 
*params)
 machine->cpu_model = "e500v2_v30";
 }
 
-irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+irqs = g_new0(qemu_irq *, smp_cpus);
 irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
 for (i = 0; i < smp_cpus; i++) {
 PowerPCCPU *cpu;
@@ -844,7 +843,7 @@ void ppce500_init(MachineState *machine, PPCE500Params 
*params)
 if (!i) {
 /* Primary CPU */
 struct boot_info *boot_info;
-boot_info = g_malloc0(sizeof(struct boot_info));
+boot_info = g_new0(struct boot_info, 1);
 qemu_register_reset(ppce500_cpu_reset, cpu);
 env->load_info = boot_info;
 } else {
-- 
2.14.2




[Qemu-devel] [PATCH 44/88] hw/core/loader: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/core/loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 4593061445..def4766dbb 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -899,7 +899,7 @@ int rom_add_file(const char *file, const char *fw_dir,
 return -1;
 }
 
-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);
 rom->as = as;
@@ -996,7 +996,7 @@ MemoryRegion *rom_add_blob(const char *name, const void 
*blob, size_t len,
 Rom *rom;
 MemoryRegion *mr = NULL;
 
-rom   = g_malloc0(sizeof(*rom));
+rom   = g_new0(Rom, 1);
 rom->name = g_strdup(name);
 rom->as   = as;
 rom->addr = addr;
@@ -1039,7 +1039,7 @@ int rom_add_elf_program(const char *name, void *data, 
size_t datasize,
 {
 Rom *rom;
 
-rom   = g_malloc0(sizeof(*rom));
+rom = g_new0(Rom, 1);
 rom->name = g_strdup(name);
 rom->addr = addr;
 rom->datasize = datasize;
-- 
2.14.2




[Qemu-devel] [PATCH 48/88] hw/input: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed hw/input/pxa2xx_keypad.c]
---
Andrzej: can you add an entry for tsc2005.c in MAINTAINERS? (or tell me where)

 hw/input/pckbd.c | 2 +-
 hw/input/ps2.c   | 4 ++--
 hw/input/pxa2xx_keypad.c | 2 +-
 hw/input/tsc2005.c   | 3 +--
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index c479f827b6..ef9e055b1d 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -465,7 +465,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
MemoryRegion *region, ram_addr_t size,
hwaddr mask)
 {
-KBDState *s = g_malloc0(sizeof(KBDState));
+KBDState *s = g_new0(KBDState, 1);
 
 s->irq_kbd = kbd_irq;
 s->irq_mouse = mouse_irq;
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index dff3f1e024..3e8f5ee98d 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -1296,7 +1296,7 @@ static QemuInputHandler ps2_keyboard_handler = {
 
 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);
 
 trace_ps2_kbd_init(s);
 s->common.update_irq = update_irq;
@@ -1318,7 +1318,7 @@ static QemuInputHandler ps2_mouse_handler = {
 
 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);
 
 trace_ps2_mouse_init(s);
 s->common.update_irq = update_irq;
diff --git a/hw/input/pxa2xx_keypad.c b/hw/input/pxa2xx_keypad.c
index 2b70bbb95c..016b095e94 100644
--- a/hw/input/pxa2xx_keypad.c
+++ b/hw/input/pxa2xx_keypad.c
@@ -310,7 +310,7 @@ PXA2xxKeyPadState *pxa27x_keypad_init(MemoryRegion *sysmem,
 {
 PXA2xxKeyPadState *s;
 
-s = (PXA2xxKeyPadState *) g_malloc0(sizeof(PXA2xxKeyPadState));
+s = g_new0(PXA2xxKeyPadState, 1);
 s->irq = irq;
 
 memory_region_init_io(>iomem, NULL, _keypad_ops, s,
diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c
index eb5320af40..34dd4ea0da 100644
--- a/hw/input/tsc2005.c
+++ b/hw/input/tsc2005.c
@@ -485,8 +485,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 = false;
-- 
2.14.2




[Qemu-devel] [PATCH 58/88] ppc4xx: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added more changes in hw/ppc/ppc405_uc.c and hw/ppc/ppc4xx_devs.c]
---
 hw/ppc/ppc405_boards.c |  4 ++--
 hw/ppc/ppc405_uc.c | 24 
 hw/ppc/ppc440_bamboo.c |  2 +-
 hw/ppc/ppc4xx_devs.c   |  6 +++---
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index e92db2c66a..a812985baa 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -169,7 +169,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, 
uint32_t base)
 ref405ep_fpga_t *fpga;
 MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
 
-fpga = g_malloc0(sizeof(ref405ep_fpga_t));
+fpga = g_new0(ref405ep_fpga_t, 1);
 memory_region_init_io(fpga_memory, NULL, _fpga_ops, fpga,
   "fpga", 0x0100);
 memory_region_add_subregion(sysmem, base, fpga_memory);
@@ -472,7 +472,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t 
base)
 taihu_cpld_t *cpld;
 MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
 
-cpld = g_malloc0(sizeof(taihu_cpld_t));
+cpld = g_new0(taihu_cpld_t, 1);
 memory_region_init_io(cpld_memory, NULL, _cpld_ops, cpld, "cpld", 
0x100);
 memory_region_add_subregion(sysmem, base, cpld_memory);
 qemu_register_reset(_cpld_reset, cpld);
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 8e58065f5f..02ab2a24ff 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -181,7 +181,7 @@ void ppc4xx_plb_init(CPUPPCState *env)
 {
 ppc4xx_plb_t *plb;
 
-plb = g_malloc0(sizeof(ppc4xx_plb_t));
+plb = g_new0(ppc4xx_plb_t, 1);
 ppc_dcr_register(env, PLB3A0_ACR, plb, _read_plb, _write_plb);
 ppc_dcr_register(env, PLB4A0_ACR, plb, _read_plb, _write_plb);
 ppc_dcr_register(env, PLB0_ACR, plb, _read_plb, _write_plb);
@@ -266,7 +266,7 @@ static void ppc4xx_pob_init(CPUPPCState *env)
 {
 ppc4xx_pob_t *pob;
 
-pob = g_malloc0(sizeof(ppc4xx_pob_t));
+pob = g_new0(ppc4xx_pob_t, 1);
 ppc_dcr_register(env, POB0_BEAR, pob, _read_pob, _write_pob);
 ppc_dcr_register(env, POB0_BESR0, pob, _read_pob, _write_pob);
 ppc_dcr_register(env, POB0_BESR1, pob, _read_pob, _write_pob);
@@ -397,7 +397,7 @@ static void ppc4xx_opba_init(hwaddr base)
 {
 ppc4xx_opba_t *opba;
 
-opba = g_malloc0(sizeof(ppc4xx_opba_t));
+opba = g_new0(ppc4xx_opba_t, 1);
 #ifdef DEBUG_OPBA
 printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -595,7 +595,7 @@ void ppc405_ebc_init(CPUPPCState *env)
 {
 ppc4xx_ebc_t *ebc;
 
-ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
+ebc = g_new0(ppc4xx_ebc_t, 1);
 qemu_register_reset(_reset, ebc);
 ppc_dcr_register(env, EBC0_CFGADDR,
  ebc, _read_ebc, _write_ebc);
@@ -678,7 +678,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq 
irqs[4])
 {
 ppc405_dma_t *dma;
 
-dma = g_malloc0(sizeof(ppc405_dma_t));
+dma = g_new0(ppc405_dma_t, 1);
 memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
 qemu_register_reset(_dma_reset, dma);
 ppc_dcr_register(env, DMA0_CR0,
@@ -819,7 +819,7 @@ static void ppc405_gpio_init(hwaddr base)
 {
 ppc405_gpio_t *gpio;
 
-gpio = g_malloc0(sizeof(ppc405_gpio_t));
+gpio = g_new0(ppc405_gpio_t, 1);
 #ifdef DEBUG_GPIO
 printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -981,7 +981,7 @@ static void ppc405_ocm_init(CPUPPCState *env)
 {
 ppc405_ocm_t *ocm;
 
-ocm = g_malloc0(sizeof(ppc405_ocm_t));
+ocm = g_new0(ppc405_ocm_t, 1);
 /* XXX: Size is 4096 or 0x0400 */
 memory_region_init_ram(>isarc_ram, NULL, "ppc405.ocm", 4096,
_fatal);
@@ -1264,7 +1264,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])
 ppc4xx_gpt_t *gpt;
 int i;
 
-gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
+gpt = g_new0(ppc4xx_gpt_t, 1);
 for (i = 0; i < 5; i++) {
 gpt->irqs[i] = irqs[i];
 }
@@ -1590,7 +1590,7 @@ static void ppc405cr_cpc_init (CPUPPCState *env, 
clk_setup_t clk_setup[7],
 {
 ppc405cr_cpc_t *cpc;
 
-cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
+cpc = g_new0(ppc405cr_cpc_t, 1);
 memcpy(cpc->clk_setup, clk_setup,
PPC405CR_CLK_NB * sizeof(clk_setup_t));
 cpc->sysclk = sysclk;
@@ -1640,7 +1640,7 @@ CPUPPCState *ppc405cr_init(MemoryRegion 
*address_space_mem,
 /* OBP arbitrer */
 ppc4xx_opba_init(0xef600600);
 /* Universal interrupt controller */
-irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
 irqs[PPCUIC_OUTPUT_INT] =
 ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
 irqs[PPCUIC_OUTPUT_CINT] =
@@ -1934,7 +1934,7 @@ static void ppc405ep_cpc_init (CPUPPCState *env, 
clk_setup_t clk_setup[8],
 {
 ppc405ep_cpc_t *cpc;

[Qemu-devel] [PATCH 46/88] hw/display/vga: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
Gerd: should those files go under Graphics section in MAINTAINERS?

 hw/display/vga-isa-mm.c | 6 +++---
 hw/display/vga.c| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/display/vga-isa-mm.c b/hw/display/vga-isa-mm.c
index 51ccbccc41..7af72864df 100644
--- a/hw/display/vga-isa-mm.c
+++ b/hw/display/vga-isa-mm.c
@@ -105,12 +105,12 @@ static void vga_mm_init(ISAVGAMMState *s, hwaddr 
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, NULL, _mm_ctrl_ops, s,
   "vga-mm-ctrl", 0x10);
 memory_region_set_flush_coalesced(s_ioport_ctrl);
 
-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, NULL, _mem_ops, >vga,
   "vga-mem", 0x2);
@@ -130,7 +130,7 @@ int isa_vga_mm_init(hwaddr vram_base,
 {
 ISAVGAMMState *s;
 
-s = g_malloc0(sizeof(*s));
+s = g_new0(ISAVGAMMState, 1);
 
 s->vga.vram_size_mb = VGA_RAM_SIZE >> 20;
 vga_common_init(>vga, NULL, true);
diff --git a/hw/display/vga.c b/hw/display/vga.c
index ed24ef7076..bdefa60f30 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2236,7 +2236,7 @@ MemoryRegion *vga_init_io(VGACommonState *s, Object *obj,
 *vga_ports = vga_portio_list;
 *vbe_ports = vbe_portio_list;
 
-vga_mem = g_malloc(sizeof(*vga_mem));
+vga_mem = g_new(MemoryRegion, 1);
 memory_region_init_io(vga_mem, obj, _mem_ops, s,
   "vga-lowmem", 0x2);
 memory_region_set_flush_coalesced(vga_mem);
-- 
2.14.2




[Qemu-devel] [PATCH 43/88] hw/core: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added changes in hw/core/qdev.c]
---
 hw/core/irq.c| 2 +-
 hw/core/ptimer.c | 2 +-
 hw/core/qdev.c   | 2 +-
 hw/core/reset.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/core/irq.c b/hw/core/irq.c
index b98d1d69f5..d9b13b1762 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -115,7 +115,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_irq(qemu_splitirq, s, 0);
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 7221c68a98..ef4a6646ed 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -349,7 +349,7 @@ ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask)
 {
 ptimer_state *s;
 
-s = (ptimer_state *)g_malloc0(sizeof(ptimer_state));
+s = g_new0(ptimer_state, 1);
 s->bh = bh;
 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ptimer_tick, s);
 s->policy_mask = policy_mask;
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 606ab53c42..7b92af1013 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -378,7 +378,7 @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState 
*dev,
 }
 }
 
-ngl = g_malloc0(sizeof(*ngl));
+ngl = g_new0(NamedGPIOList, 1);
 ngl->name = g_strdup(name);
 QLIST_INSERT_HEAD(>gpios, ngl, node);
 return ngl;
diff --git a/hw/core/reset.c b/hw/core/reset.c
index 84c8869371..01d86c3a95 100644
--- a/hw/core/reset.c
+++ b/hw/core/reset.c
@@ -40,7 +40,7 @@ static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) 
reset_handlers =
 
 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;
-- 
2.14.2




[Qemu-devel] [PATCH 57/88] ppc: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: replaced g_new0() -> g_new() in mac_newworld.c, added virtex_ml507]
---
 hw/intc/heathrow_pic.c | 2 +-
 hw/ppc/mac_newworld.c  | 5 ++---
 hw/ppc/mac_oldworld.c  | 2 +-
 hw/ppc/virtex_ml507.c  | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/intc/heathrow_pic.c b/hw/intc/heathrow_pic.c
index 171f5ed814..90c1e6a4b1 100644
--- a/hw/intc/heathrow_pic.c
+++ b/hw/intc/heathrow_pic.c
@@ -201,7 +201,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(>mem, NULL, _pic_ops, s,
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 6d0ace20ca..59cded95b8 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -295,7 +295,7 @@ static void ppc_core99_init(MachineState *machine)
 memory_region_init_io(unin2_memory, NULL, _ops, token, "unin", 
0x1000);
 memory_region_add_subregion(get_system_memory(), 0xf300, unin2_memory);
 
-openpic_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+openpic_irqs = g_new0(qemu_irq *, smp_cpus);
 openpic_irqs[0] =
 g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
 for (i = 0; i < smp_cpus; i++) {
@@ -339,8 +339,6 @@ static void ppc_core99_init(MachineState *machine)
 }
 }
 
-pic = g_new0(qemu_irq, 64);
-
 dev = qdev_create(NULL, TYPE_OPENPIC);
 qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_KEYLARGO);
 qdev_init_nofail(dev);
@@ -353,6 +351,7 @@ static void ppc_core99_init(MachineState *machine)
 }
 }
 
+pic = g_new(qemu_irq, 64);
 for (i = 0; i < 64; i++) {
 pic[i] = qdev_get_gpio_in(dev, i);
 }
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index bc7c8b7bd7..50ad9c56cb 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -232,7 +232,7 @@ static void ppc_heathrow_init(MachineState *machine)
 memory_region_add_subregion(sysmem, 0xfe00, isa);
 
 /* XXX: we register only 1 output pin for heathrow PIC */
-heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+heathrow_irqs = g_new0(qemu_irq *, smp_cpus);
 heathrow_irqs[0] =
 g_malloc0(smp_cpus * sizeof(qemu_irq) * 1);
 /* Connect the heathrow PIC outputs to the 6xx bus */
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index ed9b406fd3..ed6e054611 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -104,7 +104,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
 ppc_dcr_init(env, NULL, NULL);
 
 /* interrupt controller */
-irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
 irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
 irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq 
*)env->irq_inputs)[PPC40x_INPUT_CINT];
 ppcuic_init(env, irqs, 0x0C0, 0, 1);
-- 
2.14.2




[Qemu-devel] [PATCH 40/88] hw/xen: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: replaced g_new0() -> g_new() in xen_remap_bucket() (no bzero required),
  renamed X86 -> hw/xen and few other changes]
---
 hw/9pfs/xen-9p-backend.c   |  2 +-
 hw/display/xenfb.c |  4 ++--
 hw/i386/xen/xen-hvm.c  | 10 +-
 hw/i386/xen/xen-mapcache.c | 14 +++---
 hw/xen/xen_pvdev.c |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index ee87f08926..d76fa0df8e 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -365,7 +365,7 @@ static int xen_9pfs_connect(struct XenDevice *xendev)
 return -1;
 }
 
-xen_9pdev->rings = g_malloc0(xen_9pdev->num_rings * sizeof(Xen9pfsRing));
+xen_9pdev->rings = g_new0(Xen9pfsRing, xen_9pdev->num_rings);
 for (i = 0; i < xen_9pdev->num_rings; i++) {
 char *str;
 int ring_order;
diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 8e2547ac05..5b5fa34131 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -479,8 +479,8 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 n_fbdirs = xenfb->fbpages * mode / 8;
 n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
 
-pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
-fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
+pgmfns = g_new0(xen_pfn_t, n_fbdirs);
+fbmfns = g_new0(xen_pfn_t, xenfb->fbpages);
 
 xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
 map = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index d9ccd5d0d6..37a4e1cd6c 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -376,7 +376,7 @@ go_physmap:
 
 mr_name = memory_region_name(mr);
 
-physmap = g_malloc(sizeof(XenPhysmap));
+physmap = g_new(XenPhysmap, 1);
 
 physmap->start_addr = start_addr;
 physmap->size = size;
@@ -1188,7 +1188,7 @@ static void xen_read_physmap(XenIOState *state)
 return;
 
 for (i = 0; i < num; i++) {
-physmap = g_malloc(sizeof (XenPhysmap));
+physmap = g_new(XenPhysmap, 1);
 physmap->phys_offset = strtoull(entries[i], NULL, 16);
 snprintf(path, sizeof(path),
 "/local/domain/0/device-model/%d/physmap/%s/start_addr",
@@ -1240,7 +1240,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion 
**ram_memory)
 evtchn_port_t bufioreq_evtchn;
 XenIOState *state;
 
-state = g_malloc0(sizeof (XenIOState));
+state = g_new0(XenIOState, 1);
 
 state->xce_handle = xenevtchn_open(NULL, 0);
 if (state->xce_handle == NULL) {
@@ -1321,7 +1321,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion 
**ram_memory)
 }
 
 /* Note: cpus is empty at this point in init */
-state->cpu_by_vcpu_id = g_malloc0(max_cpus * sizeof(CPUState *));
+state->cpu_by_vcpu_id = g_new0(CPUState *, max_cpus);
 
 rc = xen_set_ioreq_server_state(xen_domid, state->ioservid, true);
 if (rc < 0) {
@@ -1330,7 +1330,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion 
**ram_memory)
 goto err;
 }
 
-state->ioreq_local_port = g_malloc0(max_cpus * sizeof (evtchn_port_t));
+state->ioreq_local_port = g_new0(evtchn_port_t, max_cpus);
 
 /* FIXME: how about if we overflow the page here? */
 for (i = 0; i < max_cpus; i++) {
diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c
index baab93b614..93cba7fb83 100644
--- a/hw/i386/xen/xen-mapcache.c
+++ b/hw/i386/xen/xen-mapcache.c
@@ -109,7 +109,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void 
*opaque)
 unsigned long size;
 struct rlimit rlimit_as;
 
-mapcache = g_malloc0(sizeof (MapCache));
+mapcache = g_new0(MapCache, 1);
 
 mapcache->phys_offset_to_gaddr = f;
 mapcache->opaque = opaque;
@@ -165,8 +165,7 @@ 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));
+err = g_new0(int, nb_pfn);
 
 if (entry->vaddr_base != NULL) {
 if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) {
@@ -180,6 +179,7 @@ static void xen_remap_bucket(MapCacheEntry *entry,
 g_free(entry->valid_mapping);
 entry->valid_mapping = NULL;
 
+pfns = g_new(xen_pfn_t, nb_pfn);
 for (i = 0; i < nb_pfn; i++) {
 pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
 }
@@ -212,8 +212,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,
+   

[Qemu-devel] [PATCH 45/88] hw/display: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed pxa2xx_lcd.c]
---
Andrzej should the tc6393xb files go under the PXA2XX section in MAINTAINERS?

 hw/display/pxa2xx_lcd.c | 2 +-
 hw/display/tc6393xb.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/display/pxa2xx_lcd.c b/hw/display/pxa2xx_lcd.c
index 845521c5b2..0ca997cae2 100644
--- a/hw/display/pxa2xx_lcd.c
+++ b/hw/display/pxa2xx_lcd.c
@@ -1006,7 +1006,7 @@ PXA2xxLCDState *pxa2xx_lcdc_init(MemoryRegion *sysmem,
 PXA2xxLCDState *s;
 DisplaySurface *surface;
 
-s = (PXA2xxLCDState *) g_malloc0(sizeof(PXA2xxLCDState));
+s = g_new0(PXA2xxLCDState, 1);
 s->invalidated = 1;
 s->irq = irq;
 s->sysmem = sysmem;
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
index 74d10af3d4..2bd73a27e0 100644
--- a/hw/display/tc6393xb.c
+++ b/hw/display/tc6393xb.c
@@ -570,7 +570,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t 
base, qemu_irq irq)
 },
 };
 
-s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
+s = g_new0(TC6393xbState, 1);
 s->irq = irq;
 s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS);
 
-- 
2.14.2




[Qemu-devel] [PATCH 55/88] PReP: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/ppc/prep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 94138a4e8c..c638d3d17a 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -512,7 +512,7 @@ static void ppc_prep_init(MachineState *machine)
 int ppc_boot_device;
 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 
-sysctrl = g_malloc0(sizeof(sysctrl_t));
+sysctrl = g_new0(sysctrl_t, 1);
 
 linux_boot = (kernel_filename != NULL);
 
-- 
2.14.2




[Qemu-devel] [PATCH 52/88] i.MX31: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/misc/imx6_src.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
index cfb08710fb..9342bce6de 100644
--- a/hw/misc/imx6_src.c
+++ b/hw/misc/imx6_src.c
@@ -149,7 +149,7 @@ static void imx6_defer_clear_reset_bit(int cpuid,
 return;
 }
 
-ri = g_malloc(sizeof(struct SRCSCRResetInfo));
+ri = g_new(struct SRCSCRResetInfo, 1);
 ri->s = s;
 ri->reset_bit = reset_shift;
 
-- 
2.14.2




[Qemu-devel] [PATCH 38/88] VFIO: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes in each file, added pci-quirks.c]
---
 hw/vfio/common.c | 12 ++--
 hw/vfio/pci-quirks.c | 18 +-
 hw/vfio/pci.c|  7 +++
 hw/vfio/platform.c   |  6 +++---
 4 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7b2924c0ef..bde4fdba66 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -272,7 +272,7 @@ static void vfio_host_win_add(VFIOContainer *container,
 }
 }
 
-hostwin = g_malloc0(sizeof(*hostwin));
+hostwin = g_new0(VFIOHostDMAWindow, 1);
 
 hostwin->min_iova = min_iova;
 hostwin->max_iova = max_iova;
@@ -488,7 +488,7 @@ static void vfio_listener_region_add(MemoryListener 
*listener,
  * would be the right place to wire that up (tell the KVM
  * device emulation the VFIO iommu handles to use).
  */
-giommu = g_malloc0(sizeof(*giommu));
+giommu = g_new0(VFIOGuestIOMMU, 1);
 giommu->iommu = iommu_mr;
 giommu->iommu_offset = section->offset_within_address_space -
section->offset_within_region;
@@ -688,7 +688,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion 
*region,
 }
 
 region->nr_mmaps = j;
-region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap));
+region->mmaps = g_renew(VFIOMmap, region->mmaps, j);
 
 return 0;
 }
@@ -938,7 +938,7 @@ static VFIOAddressSpace 
*vfio_get_address_space(AddressSpace *as)
 }
 
 /* No suitable VFIOAddressSpace, create a new one */
-space = g_malloc0(sizeof(*space));
+space = g_new0(VFIOAddressSpace, 1);
 space->as = as;
 QLIST_INIT(>containers);
 
@@ -987,7 +987,7 @@ static int vfio_connect_container(VFIOGroup *group, 
AddressSpace *as,
 goto close_fd_exit;
 }
 
-container = g_malloc0(sizeof(*container));
+container = g_new0(VFIOContainer, 1);
 container->space = space;
 container->fd = fd;
 if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) ||
@@ -1202,7 +1202,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, 
Error **errp)
 }
 }
 
-group = g_malloc0(sizeof(*group));
+group = g_new0(VFIOGroup, 1);
 
 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
 group->fd = qemu_open(path, O_RDWR);
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 14291c2a16..b51ee60368 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -288,7 +288,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice 
*vdev)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 quirk->mem = g_new0(MemoryRegion, 1);
 quirk->nr_mem = 1;
 
@@ -323,7 +323,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vdev, 
int nr)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 quirk->mem = g_new0(MemoryRegion, 2);
 quirk->nr_mem = 2;
 window = quirk->data = g_malloc0(sizeof(*window) +
@@ -371,7 +371,7 @@ static void vfio_probe_ati_bar2_quirk(VFIOPCIDevice *vdev, 
int nr)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 mirror = quirk->data = g_malloc0(sizeof(*mirror));
 mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
 quirk->nr_mem = 1;
@@ -547,7 +547,7 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevice 
*vdev)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 quirk->data = data = g_malloc0(sizeof(*data));
 quirk->mem = g_new0(MemoryRegion, 2);
 quirk->nr_mem = 2;
@@ -665,7 +665,7 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice 
*vdev, int nr)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 quirk->mem = g_new0(MemoryRegion, 4);
 quirk->nr_mem = 4;
 bar5 = quirk->data = g_malloc0(sizeof(*bar5) +
@@ -759,7 +759,7 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice 
*vdev, int nr)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 mirror = quirk->data = g_malloc0(sizeof(*mirror));
 mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
 quirk->nr_mem = 1;
@@ -942,7 +942,7 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice 
*vdev, int nr)
 return;
 }
 
-quirk = g_malloc0(sizeof(*quirk));
+quirk = g_new0(VFIOQuirk, 1);
 quirk->mem = g_new0(MemoryRegion, 2);
 quirk->nr_mem = 2;
 quirk->data = rtl = g_malloc0(sizeof(*rtl));
@@ -1500,7 +1500,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 }
 
 /* Setup our quirk to munge GTT addresses to the VM allocated buffer */
-quirk = 

[Qemu-devel] [PATCH 50/88] ivshmem: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/misc/ivshmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index b3ef3ec1e3..9dd432a295 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -429,7 +429,7 @@ static void resize_peers(IVShmemState *s, int nb_peers)
 assert(nb_peers > old_nb_peers);
 IVSHMEM_DPRINTF("bumping storage to %d peers\n", nb_peers);
 
-s->peers = g_realloc(s->peers, nb_peers * sizeof(Peer));
+s->peers = g_renew(Peer, s->peers, nb_peers);
 s->nb_peers = nb_peers;
 
 for (i = old_nb_peers; i < nb_peers; i++) {
@@ -753,7 +753,7 @@ static void ivshmem_reset(DeviceState *d)
 static int ivshmem_setup_interrupts(IVShmemState *s, Error **errp)
 {
 /* allocate QEMU callback data for receiving interrupts */
-s->msi_vectors = g_malloc0(s->vectors * sizeof(MSIVector));
+s->msi_vectors = g_new0(MSIVector, s->vectors);
 
 if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
 if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1, errp)) {
-- 
2.14.2




[Qemu-devel] [PATCH 39/88] hw/i386: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: renamed PC -> hw/i386, split of target/i386/cpu.c, added more changes]
---
 hw/i386/acpi-build.c  | 4 ++--
 hw/i386/amd_iommu.c   | 4 ++--
 hw/i386/intel_iommu.c | 2 +-
 hw/i386/pc.c  | 8 
 hw/i386/pc_sysfw.c| 6 +++---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2af37a9129..1aff7b4d2f 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -777,7 +777,7 @@ static void crs_range_insert(GPtrArray *ranges, uint64_t 
base, uint64_t limit)
 {
 CrsRangeEntry *entry;
 
-entry = g_malloc(sizeof(*entry));
+entry = g_new(CrsRangeEntry, 1);
 entry->base = base;
 entry->limit = limit;
 
@@ -2877,7 +2877,7 @@ void acpi_setup(void)
 return;
 }
 
-build_state = g_malloc0(sizeof *build_state);
+build_state = g_new0(AcpiBuildState, 1);
 
 acpi_build_tables_init();
 acpi_build(, MACHINE(pcms));
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 334938a280..f871025376 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1033,13 +1033,13 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, 
void *opaque, int devfn)
 
 /* allocate memory during the first run */
 if (!iommu_as) {
-iommu_as = g_malloc0(sizeof(AMDVIAddressSpace *) * PCI_DEVFN_MAX);
+iommu_as = g_new0(AMDVIAddressSpace *, PCI_DEVFN_MAX);
 s->address_spaces[bus_num] = iommu_as;
 }
 
 /* set up AMD-Vi region */
 if (!iommu_as[devfn]) {
-iommu_as[devfn] = g_malloc0(sizeof(AMDVIAddressSpace));
+iommu_as[devfn] = g_new0(AMDVIAddressSpace, 1);
 iommu_as[devfn]->bus_num = (uint8_t)bus_num;
 iommu_as[devfn]->devfn = (uint8_t)devfn;
 iommu_as[devfn]->iommu_state = s;
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 3a5bb0bc2e..62c94008ad 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2708,7 +2708,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, 
PCIBus *bus, int devfn)
 
 if (!vtd_dev_as) {
 snprintf(name, sizeof(name), "intel_iommu_devfn_%d", devfn);
-vtd_bus->dev_as[devfn] = vtd_dev_as = 
g_malloc0(sizeof(VTDAddressSpace));
+vtd_bus->dev_as[devfn] = vtd_dev_as = g_new0(VTDAddressSpace, 1);
 
 vtd_dev_as->bus = bus;
 vtd_dev_as->devfn = (uint8_t)devfn;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 05985d4927..393aefdc4c 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1175,7 +1175,7 @@ static void pc_build_feature_control_file(PCMachineState 
*pcms)
 return;
 }
 
-val = g_malloc(sizeof(*val));
+val = g_new(uint64_t, 1);
 *val = cpu_to_le64(feature_control_bits | FEATURE_CONTROL_LOCKED);
 fw_cfg_add_file(pcms->fw_cfg, "etc/msr_feature_control", val, 
sizeof(*val));
 }
@@ -1336,11 +1336,11 @@ void pc_memory_init(PCMachineState *pcms,
  * aliases to address portions of it, mostly for backwards compatibility
  * with older qemus that used qemu_ram_alloc().
  */
-ram = g_malloc(sizeof(*ram));
+ram = g_new(MemoryRegion, 1);
 memory_region_allocate_system_memory(ram, NULL, "pc.ram",
  machine->ram_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, NULL, "ram-below-4g", ram,
  0, pcms->below_4g_mem_size);
 memory_region_add_subregion(system_memory, 0, ram_below_4g);
@@ -1408,7 +1408,7 @@ void pc_memory_init(PCMachineState *pcms,
 /* Initialize PC system firmware */
 pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
 
-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,
_fatal);
 if (pcmc->pci_enabled) {
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 6b183747fc..d80cb17d70 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -56,7 +56,7 @@ static void pc_isa_bios_init(MemoryRegion *rom_memory,
 
 /* map the last 128KB of the BIOS in ISA space */
 isa_bios_size = MIN(flash_size, 128 * 1024);
-isa_bios = g_malloc(sizeof(*isa_bios));
+isa_bios = g_new(MemoryRegion, 1);
 memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size,
_fatal);
 memory_region_add_subregion_overlap(rom_memory,
@@ -193,7 +193,7 @@ static void old_pc_system_rom_init(MemoryRegion 
*rom_memory, bool isapc_ram_fw)
 (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, 

[Qemu-devel] [PATCH 47/88] hw/i2c: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/i2c/bitbang_i2c.c | 2 +-
 hw/i2c/core.c| 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c
index 8be88ee265..20a9deef1a 100644
--- a/hw/i2c/bitbang_i2c.c
+++ b/hw/i2c/bitbang_i2c.c
@@ -186,7 +186,7 @@ bitbang_i2c_interface *bitbang_i2c_init(I2CBus *bus)
 {
 bitbang_i2c_interface *s;
 
-s = g_malloc0(sizeof(bitbang_i2c_interface));
+s = g_new0(bitbang_i2c_interface, 1);
 
 s->bus = bus;
 s->last_data = 1;
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 59068f157e..be84d6735f 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -132,7 +132,7 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int 
recv)
 DeviceState *qdev = kid->child;
 I2CSlave *candidate = I2C_SLAVE(qdev);
 if ((candidate->address == address) || (bus->broadcast)) {
-node = g_malloc(sizeof(struct I2CNode));
+node = g_new(struct I2CNode, 1);
 node->elt = candidate;
 QLIST_INSERT_HEAD(>current_devs, node, next);
 if (!bus->broadcast) {
@@ -258,7 +258,7 @@ static int i2c_slave_post_load(void *opaque, int version_id)
 bus = I2C_BUS(qdev_get_parent_bus(DEVICE(dev)));
 if ((bus->saved_address == dev->address) ||
 (bus->saved_address == I2C_BROADCAST)) {
-node = g_malloc(sizeof(struct I2CNode));
+node = g_new(struct I2CNode, 1);
 node->elt = dev;
 QLIST_INSERT_HEAD(>current_devs, node, next);
 }
-- 
2.14.2




[Qemu-devel] [PATCH 34/88] qapi: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 qapi/opts-visitor.c   | 2 +-
 qapi/qapi-clone-visitor.c | 2 +-
 qapi/qapi-dealloc-visitor.c   | 2 +-
 qapi/qobject-output-visitor.c | 2 +-
 qapi/string-input-visitor.c   | 2 +-
 qapi/string-output-visitor.c  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 324b197495..34ac49f3c2 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -539,7 +539,7 @@ opts_visitor_new(const QemuOpts *opts)
 OptsVisitor *ov;
 
 assert(opts);
-ov = g_malloc0(sizeof *ov);
+ov = g_new0(OptsVisitor, 1);
 
 ov->visitor.type = VISITOR_INPUT;
 
diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c
index d8b62792bc..3d216e5906 100644
--- a/qapi/qapi-clone-visitor.c
+++ b/qapi/qapi-clone-visitor.c
@@ -145,7 +145,7 @@ static Visitor *qapi_clone_visitor_new(void)
 {
 QapiCloneVisitor *v;
 
-v = g_malloc0(sizeof(*v));
+v = g_new0(QapiCloneVisitor, 1);
 
 v->visitor.type = VISITOR_CLONE;
 v->visitor.start_struct = qapi_clone_start_struct;
diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index ed70a0158b..ad0d0eb7e4 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -120,7 +120,7 @@ Visitor *qapi_dealloc_visitor_new(void)
 {
 QapiDeallocVisitor *v;
 
-v = g_malloc0(sizeof(*v));
+v = g_new0(QapiDeallocVisitor, 1);
 
 v->visitor.type = VISITOR_DEALLOC;
 v->visitor.start_struct = qapi_dealloc_start_struct;
diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c
index d325163e55..7228986c0c 100644
--- a/qapi/qobject-output-visitor.c
+++ b/qapi/qobject-output-visitor.c
@@ -229,7 +229,7 @@ Visitor *qobject_output_visitor_new(QObject **result)
 {
 QObjectOutputVisitor *v;
 
-v = g_malloc0(sizeof(*v));
+v = g_new0(QObjectOutputVisitor, 1);
 
 v->visitor.type = VISITOR_OUTPUT;
 v->visitor.start_struct = qobject_output_start_struct;
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index 67a0a4a58b..3a2fe58478 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -356,7 +356,7 @@ Visitor *string_input_visitor_new(const char *str)
 StringInputVisitor *v;
 
 assert(str);
-v = g_malloc0(sizeof(*v));
+v = g_new0(StringInputVisitor, 1);
 
 v->visitor.type = VISITOR_INPUT;
 v->visitor.type_int64 = parse_type_int64;
diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c
index 7ab64468d9..a7bbbae109 100644
--- a/qapi/string-output-visitor.c
+++ b/qapi/string-output-visitor.c
@@ -341,7 +341,7 @@ Visitor *string_output_visitor_new(bool human, char 
**result)
 {
 StringOutputVisitor *v;
 
-v = g_malloc0(sizeof(*v));
+v = g_new0(StringOutputVisitor, 1);
 
 v->string = g_string_new(NULL);
 v->human = human;
-- 
2.14.2




[Qemu-devel] [PATCH 33/88] qom: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 qom/object.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 6a7bd9257b..3273f9c1f0 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -940,7 +940,7 @@ object_property_add(Object *obj, const char *name, const 
char *type,
 return NULL;
 }
 
-prop = g_malloc0(sizeof(*prop));
+prop = g_new0(ObjectProperty, 1);
 
 prop->name = g_strdup(name);
 prop->type = g_strdup(type);
@@ -973,7 +973,7 @@ object_class_property_add(ObjectClass *klass,
 return NULL;
 }
 
-prop = g_malloc0(sizeof(*prop));
+prop = g_new0(ObjectProperty, 1);
 
 prop->name = g_strdup(name);
 prop->type = g_strdup(type);
@@ -2281,7 +2281,7 @@ void object_property_add_alias(Object *obj, const char 
*name,
 prop_type = g_strdup(target_prop->type);
 }
 
-prop = g_malloc(sizeof(*prop));
+prop = g_new(AliasProperty, 1);
 prop->target_obj = target_obj;
 prop->target_name = g_strdup(target_name);
 
-- 
2.14.2




[Qemu-devel] [PATCH 42/88] XTFPGA: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 hw/xtensa/xtfpga.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index a19ccebdba..c54a09df83 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -115,7 +115,7 @@ static const MemoryRegionOps lx60_fpga_ops = {
 static Lx60FpgaState *lx60_fpga_init(MemoryRegion *address_space,
 hwaddr base)
 {
-Lx60FpgaState *s = g_malloc(sizeof(Lx60FpgaState));
+Lx60FpgaState *s = g_new(Lx60FpgaState, 1);
 
 memory_region_init_io(>iomem, NULL, _fpga_ops, s,
 "lx60.fpga", 0x1);
-- 
2.14.2




[Qemu-devel] [PATCH 41/88] target/i386: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added more changes and hax]
---
 target/i386/cpu.c | 6 +++---
 target/i386/hax-all.c | 4 ++--
 target/i386/hax-mem.c | 2 +-
 target/i386/hyperv.c  | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 98732cd65f..236a4115cd 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2344,7 +2344,7 @@ static void x86_cpu_definition_entry(gpointer data, 
gpointer user_data)
 CpuDefinitionInfoList *entry;
 CpuDefinitionInfo *info;
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(CpuDefinitionInfo, 1);
 info->name = x86_cpu_class_get_model_name(cc);
 x86_cpu_class_check_missing_features(cc, >unavailable_features);
 info->has_unavailable_features = true;
@@ -2353,7 +2353,7 @@ static void x86_cpu_definition_entry(gpointer data, 
gpointer user_data)
 info->has_migration_safe = true;
 info->q_static = cc->static_model;
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(CpuDefinitionInfoList, 1);
 entry->value = info;
 entry->next = *cpu_list;
 *cpu_list = entry;
@@ -3933,7 +3933,7 @@ static GuestPanicInformation 
*x86_cpu_get_crash_info(CPUState *cs)
 GuestPanicInformation *panic_info = NULL;
 
 if (env->features[FEAT_HYPERV_EDX] & HV_GUEST_CRASH_MSR_AVAILABLE) {
-panic_info = g_malloc0(sizeof(GuestPanicInformation));
+panic_info = g_new0(GuestPanicInformation, 1);
 
 panic_info->type = GUEST_PANIC_INFORMATION_TYPE_HYPER_V;
 
diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c
index 3ce6950296..8f4368fe01 100644
--- a/target/i386/hax-all.c
+++ b/target/i386/hax-all.c
@@ -155,7 +155,7 @@ int hax_vcpu_create(int id)
 return 0;
 }
 
-vcpu = g_malloc(sizeof(struct hax_vcpu_state));
+vcpu = g_new(struct hax_vcpu_state, 1);
 if (!vcpu) {
 fprintf(stderr, "Failed to alloc vcpu state\n");
 return -ENOMEM;
@@ -251,7 +251,7 @@ struct hax_vm *hax_vm_create(struct hax_state *hax)
 return hax->vm;
 }
 
-vm = g_malloc(sizeof(struct hax_vm));
+vm = g_new(struct hax_vm, 1);
 if (!vm) {
 return NULL;
 }
diff --git a/target/i386/hax-mem.c b/target/i386/hax-mem.c
index 27a0d214f2..826f7ca501 100644
--- a/target/i386/hax-mem.c
+++ b/target/i386/hax-mem.c
@@ -82,7 +82,7 @@ static void hax_insert_mapping_before(HAXMapping *next, 
uint64_t start_pa,
 {
 HAXMapping *entry;
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(HAXMapping, 1);
 entry->start_pa = start_pa;
 entry->size = size;
 entry->host_va = host_va;
diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index a050c9d2d1..a427602e58 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -78,7 +78,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vcpu_id, 
uint32_t sint,
 HvSintRoute *sint_route;
 int r, gsi;
 
-sint_route = g_malloc0(sizeof(*sint_route));
+sint_route = g_new0(HvSintRoute, 1);
 r = event_notifier_init(_route->sint_set_notifier, false);
 if (r) {
 goto err;
-- 
2.14.2




[Qemu-devel] [PATCH 32/88] QObject: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added qbool.c, qdict.c, qlist.c, qstring.c and tests/]
---
 qobject/json-parser.c   | 2 +-
 qobject/qbool.c | 2 +-
 qobject/qdict.c | 4 ++--
 qobject/qlist.c | 4 ++--
 qobject/qstring.c   | 2 +-
 tests/test-qobject-output-visitor.c | 4 ++--
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 724ca240e4..37dda9bc3f 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -247,7 +247,7 @@ static JSONParserContext *parser_context_new(GQueue *tokens)
 return NULL;
 }
 
-ctxt = g_malloc0(sizeof(JSONParserContext));
+ctxt = g_new0(JSONParserContext, 1);
 ctxt->buf = tokens;
 
 return ctxt;
diff --git a/qobject/qbool.c b/qobject/qbool.c
index 0606bbd2a3..5ad7f6d98f 100644
--- a/qobject/qbool.c
+++ b/qobject/qbool.c
@@ -25,7 +25,7 @@ QBool *qbool_from_bool(bool value)
 {
 QBool *qb;
 
-qb = g_malloc(sizeof(*qb));
+qb = g_new(QBool, 1);
 qobject_init(QOBJECT(qb), QTYPE_QBOOL);
 qb->value = value;
 
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 576018e531..857e71c7a1 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -30,7 +30,7 @@ QDict *qdict_new(void)
 {
 QDict *qdict;
 
-qdict = g_malloc0(sizeof(*qdict));
+qdict = g_new0(QDict, 1);
 qobject_init(QOBJECT(qdict), QTYPE_QDICT);
 
 return qdict;
@@ -70,7 +70,7 @@ static QDictEntry *alloc_entry(const char *key, QObject 
*value)
 {
 QDictEntry *entry;
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(QDictEntry, 1);
 entry->key = g_strdup(key);
 entry->value = value;
 
diff --git a/qobject/qlist.c b/qobject/qlist.c
index 86b60cb88c..8afc594d0d 100644
--- a/qobject/qlist.c
+++ b/qobject/qlist.c
@@ -25,7 +25,7 @@ QList *qlist_new(void)
 {
 QList *qlist;
 
-qlist = g_malloc(sizeof(*qlist));
+qlist = g_new(QList, 1);
 qobject_init(QOBJECT(qlist), QTYPE_QLIST);
 QTAILQ_INIT(>head);
 
@@ -58,7 +58,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(>head, entry, next);
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 5da7b5f37c..806c0306a2 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -42,7 +42,7 @@ QString *qstring_from_substr(const char *str, int start, int 
end)
 {
 QString *qstring;
 
-qstring = g_malloc(sizeof(*qstring));
+qstring = g_new(QString, 1);
 qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
 
 qstring->length = end - start + 1;
diff --git a/tests/test-qobject-output-visitor.c 
b/tests/test-qobject-output-visitor.c
index d375100a52..d0a66a5dca 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -182,7 +182,7 @@ static void 
test_visitor_out_struct_nested(TestOutputVisitorData *data,
 const char *strings[] = { "forty two", "forty three", "forty four",
   "forty five" };
 
-ud2 = g_malloc0(sizeof(*ud2));
+ud2 = g_new0(UserDefTwo, 1);
 ud2->string0 = g_strdup(strings[0]);
 
 ud2->dict1 = g_malloc0(sizeof(*ud2->dict1));
@@ -372,7 +372,7 @@ static void 
test_visitor_out_union_flat(TestOutputVisitorData *data,
 {
 QDict *qdict;
 
-UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
+UserDefFlatUnion *tmp = g_new0(UserDefFlatUnion, 1);
 tmp->enum1 = ENUM_ONE_VALUE1;
 tmp->string = g_strdup("str");
 tmp->integer = 41;
-- 
2.14.2




[Qemu-devel] [PATCH 31/88] QMP: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes]
---
 monitor.c | 14 +++---
 qmp.c | 14 +++---
 tests/test-qmp-commands.c | 14 +++---
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/monitor.c b/monitor.c
index fe0d1bdbb4..ea6a485f11 100644
--- a/monitor.c
+++ b/monitor.c
@@ -906,7 +906,7 @@ static void query_commands_cb(QmpCommand *cmd, void *opaque)
 return;
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(CommandInfoList, 1);
 info->value = g_malloc0(sizeof(*info->value));
 info->value->name = g_strdup(cmd->name);
 info->next = *list;
@@ -1799,7 +1799,7 @@ static void hmp_wavcapture(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;
@@ -1947,7 +1947,7 @@ void qmp_getfd(const char *fdname, Error **errp)
 return;
 }
 
-monfd = g_malloc0(sizeof(mon_fd_t));
+monfd = g_new0(mon_fd_t, 1);
 monfd->name = g_strdup(fdname);
 monfd->fd = fd;
 
@@ -2110,7 +2110,7 @@ FdsetInfoList *qmp_query_fdsets(Error **errp)
 QLIST_FOREACH(mon_fdset_fd, _fdset->fds, next) {
 FdsetFdInfoList *fdsetfd_info;
 
-fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
+fdsetfd_info = g_new0(FdsetFdInfoList, 1);
 fdsetfd_info->value = g_malloc0(sizeof(*fdsetfd_info->value));
 fdsetfd_info->value->fd = mon_fdset_fd->fd;
 if (mon_fdset_fd->opaque) {
@@ -2199,7 +2199,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool 
has_fdset_id, int64_t fdset_id,
 }
 }
 
-mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
+mon_fdset_fd = g_new0(MonFdsetFd, 1);
 mon_fdset_fd->fd = fd;
 mon_fdset_fd->removed = false;
 if (has_opaque) {
@@ -2207,7 +2207,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool 
has_fdset_id, int64_t fdset_id,
 }
 QLIST_INSERT_HEAD(_fdset->fds, mon_fdset_fd, next);
 
-fdinfo = g_malloc0(sizeof(*fdinfo));
+fdinfo = g_new0(AddfdInfo, 1);
 fdinfo->fdset_id = mon_fdset->id;
 fdinfo->fd = mon_fdset_fd->fd;
 
@@ -4102,7 +4102,7 @@ void monitor_init(Chardev *chr, int flags)
 is_first_init = 0;
 }
 
-mon = g_malloc(sizeof(*mon));
+mon = g_new(Monitor, 1);
 monitor_data_init(mon);
 
 qemu_chr_fe_init(>chr, chr, _abort);
diff --git a/qmp.c b/qmp.c
index e8c303116a..e965020e37 100644
--- a/qmp.c
+++ b/qmp.c
@@ -232,7 +232,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, 
Error **errp)
 while ((prop = object_property_iter_next())) {
 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
 
-entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+entry->value = g_new0(ObjectPropertyInfo, 1);
 entry->next = props;
 props = entry;
 
@@ -432,7 +432,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void 
*data)
 ObjectTypeInfo *info;
 ObjectClass *parent = object_class_get_parent(klass);
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(ObjectTypeInfo, 1);
 info->name = g_strdup(object_class_get_name(klass));
 info->has_abstract = info->abstract = object_class_is_abstract(klass);
 if (parent) {
@@ -440,7 +440,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void 
*data)
 info->parent = g_strdup(object_class_get_name(parent));
 }
 
-e = g_malloc0(sizeof(*e));
+e = g_new0(ObjectTypeInfoList, 1);
 e->value = info;
 e->next = *pret;
 *pret = e;
@@ -490,7 +490,7 @@ static DevicePropertyInfo 
*make_device_property_info(ObjectClass *klass,
 return NULL;   /* no way to set it, don't show */
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(DevicePropertyInfo, 1);
 info->name = g_strdup(prop->name);
 info->type = default_type ? g_strdup(default_type)
   : g_strdup(prop->info->name);
@@ -502,7 +502,7 @@ static DevicePropertyInfo 
*make_device_property_info(ObjectClass *klass,
 } while (klass != object_class_by_name(TYPE_DEVICE));
 
 /* Not a qdev property, use the default type */
-info = g_malloc0(sizeof(*info));
+info = g_new0(DevicePropertyInfo, 1);
 info->name = g_strdup(name);
 info->type = g_strdup(default_type);
 info->has_description = !!description;
@@ -568,7 +568,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const 
char *typename,
 continue;
 }
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(DevicePropertyInfoList, 1);
 entry->value = info;
 entry->next = 

[Qemu-devel] [PATCH 37/88] TCG: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: avoid use of g_malloc0() in cpus.c]
---
 cpus.c| 18 +-
 tcg/tcg.c |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/cpus.c b/cpus.c
index c9a624003a..6dea1c7041 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1666,8 +1666,8 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)
 static QemuThread *single_tcg_cpu_thread;
 
 if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) {
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+cpu->thread = g_new0(QemuThread, 1);
+cpu->halt_cond = g_new0(QemuCond, 1);
 qemu_cond_init(cpu->halt_cond);
 
 if (qemu_tcg_mttcg_enabled()) {
@@ -1706,8 +1706,8 @@ static void qemu_hax_start_vcpu(CPUState *cpu)
 {
 char thread_name[VCPU_THREAD_NAME_SIZE];
 
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+cpu->thread = g_new0(QemuThread, 1);
+cpu->halt_cond = g_new0(QemuCond, 1);
 qemu_cond_init(cpu->halt_cond);
 
 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX",
@@ -1726,8 +1726,8 @@ static void qemu_kvm_start_vcpu(CPUState *cpu)
 {
 char thread_name[VCPU_THREAD_NAME_SIZE];
 
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+cpu->thread = g_new0(QemuThread, 1);
+cpu->halt_cond = g_new0(QemuCond, 1);
 qemu_cond_init(cpu->halt_cond);
 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM",
  cpu->cpu_index);
@@ -1742,8 +1742,8 @@ static void qemu_dummy_start_vcpu(CPUState *cpu)
 {
 char thread_name[VCPU_THREAD_NAME_SIZE];
 
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+cpu->thread = g_new0(QemuThread, 1);
+cpu->halt_cond = g_new0(QemuCond, 1);
 qemu_cond_init(cpu->halt_cond);
 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
  cpu->cpu_index);
@@ -1931,7 +1931,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 info->value->has_props = !!mc->cpu_index_to_instance_props;
 if (info->value->has_props) {
 CpuInstanceProperties *props;
-props = g_malloc0(sizeof(*props));
+props = g_malloc(sizeof(*props));
 *props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
 info->value->props = props;
 }
diff --git a/tcg/tcg.c b/tcg/tcg.c
index dffbc6..d5c1c75aa7 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -342,8 +342,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 = _op_defs[op];
-- 
2.14.2




[Qemu-devel] [PATCH 36/88] SLIRP: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added net/slirp.c]
---
 net/slirp.c| 4 ++--
 slirp/slirp.c  | 2 +-
 slirp/socket.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index 318a26e892..c42e1fd0d0 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -869,7 +869,7 @@ net_init_slirp_configs(const StringList *fwd, int flags)
 while (fwd) {
 struct slirp_config_str *config;
 
-config = g_malloc0(sizeof(*config));
+config = g_new0(struct slirp_config_str, 1);
 pstrcpy(config->str, sizeof(config->str), fwd->value->str);
 config->flags = flags;
 config->next = slirp_configs;
@@ -973,7 +973,7 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const 
char *optarg, int *ret
 if (QTAILQ_EMPTY(_stacks)) {
 struct slirp_config_str *config;
 
-config = g_malloc(sizeof(*config));
+config = g_new(struct slirp_config_str, 1);
 pstrcpy(config->str, sizeof(config->str), optarg);
 config->flags = SLIRP_CFG_LEGACY;
 config->next = slirp_configs;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 1cb6b07004..9af9179afa 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -288,7 +288,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct 
in_addr vnetwork,
   struct in6_addr vnameserver6, const char **vdnssearch,
   void *opaque)
 {
-Slirp *slirp = g_malloc0(sizeof(Slirp));
+Slirp *slirp = g_new0(Slirp, 1);
 
 slirp_init_once();
 
diff --git a/slirp/socket.c b/slirp/socket.c
index cb7b5b608d..2eccb68c2e 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -48,7 +48,7 @@ socreate(Slirp *slirp)
 {
   struct socket *so;
 
-  so = (struct socket *)malloc(sizeof(struct socket));
+  so = g_new(struct socket, 1);
   if(so) {
 memset(so, 0, sizeof(struct socket));
 so->so_state = SS_NOFDREF;
-- 
2.14.2




[Qemu-devel] [PATCH 30/88] QEMU Guest Agent: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: added qga/commands-posix.c and qga/commands-win32.c]
---
 qga/commands-posix.c | 20 ++--
 qga/commands-win32.c | 12 ++--
 qga/commands.c   |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index ab0c63d931..3a4deb6ae0 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -906,16 +906,16 @@ static void build_guest_fsinfo_for_real_device(char const 
*syspath,
 }
 }
 
-pciaddr = g_malloc0(sizeof(*pciaddr));
+pciaddr = g_new0(GuestPCIAddress, 1);
 pciaddr->domain = pci[0];
 pciaddr->bus = pci[1];
 pciaddr->slot = pci[2];
 pciaddr->function = pci[3];
 
-disk = g_malloc0(sizeof(*disk));
+disk = g_new0(GuestDiskAddress, 1);
 disk->pci_controller = pciaddr;
 
-list = g_malloc0(sizeof(*list));
+list = g_new0(GuestDiskAddressList, 1);
 list->value = disk;
 
 if (strcmp(driver, "ata_piix") == 0) {
@@ -1380,7 +1380,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error 
**errp)
 return NULL;
 }
 
-response = g_malloc0(sizeof(*response));
+response = g_new0(GuestFilesystemTrimResponse, 1);
 
 QTAILQ_FOREACH(mount, , next) {
 result = g_malloc0(sizeof(*result));
@@ -1897,12 +1897,12 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error 
**errp)
 GuestLogicalProcessor *vcpu;
 GuestLogicalProcessorList *entry;
 
-vcpu = g_malloc0(sizeof *vcpu);
+vcpu = g_new0(GuestLogicalProcessor, 1);
 vcpu->logical_id = current++;
 vcpu->has_can_offline = true; /* lolspeak ftw */
 transfer_vcpu(vcpu, true, _err);
 
-entry = g_malloc0(sizeof *entry);
+entry = g_new0(GuestLogicalProcessorList, 1);
 entry->value = vcpu;
 
 *link = entry;
@@ -2267,13 +2267,13 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error 
**errp)
 continue;
 }
 
-mem_blk = g_malloc0(sizeof *mem_blk);
+mem_blk = g_new0(GuestMemoryBlock, 1);
 /* The d_name is "memoryXXX",  phys_index is block id, same as XXX */
 mem_blk->phys_index = strtoul(>d_name[6], NULL, 10);
 mem_blk->has_can_offline = true; /* lolspeak ftw */
 transfer_memory_block(mem_blk, true, NULL, _err);
 
-entry = g_malloc0(sizeof *entry);
+entry = g_new0(GuestMemoryBlockList, 1);
 entry->value = mem_blk;
 
 *link = entry;
@@ -2308,13 +2308,13 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList 
*mem_blks, Error **errp)
 GuestMemoryBlockResponseList *entry;
 GuestMemoryBlock *current_mem_blk = mem_blks->value;
 
-result = g_malloc0(sizeof(*result));
+result = g_new0(GuestMemoryBlockResponse, 1);
 result->phys_index = current_mem_blk->phys_index;
 transfer_memory_block(current_mem_blk, false, result, _err);
 if (local_err) { /* should never happen */
 goto err;
 }
-entry = g_malloc0(sizeof *entry);
+entry = g_new0(GuestMemoryBlockResponseList, 1);
 entry->value = result;
 
 *link = entry;
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 619dbd2bc2..908f110b8b 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -617,7 +617,7 @@ static GuestDiskAddressList *build_guest_disk_info(char 
*guid, Error **errp)
 goto out_close;
 }
 
-disk = g_malloc0(sizeof(*disk));
+disk = g_new0(GuestDiskAddress, 1);
 disk->bus_type = find_bus_type(bus);
 if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID
 #if (_WIN32_WINNT >= 0x0600)
@@ -641,7 +641,7 @@ static GuestDiskAddressList *build_guest_disk_info(char 
*guid, Error **errp)
  disk->pci_controller = NULL;
 }
 
-list = g_malloc0(sizeof(*list));
+list = g_new0(GuestDiskAddressList, 1);
 list->value = disk;
 list->next = NULL;
 out_close:
@@ -694,7 +694,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, 
Error **errp)
 }
 
 fs_name[sizeof(fs_name) - 1] = 0;
-fs = g_malloc(sizeof(*fs));
+fs = g_new(GuestFilesystemInfo, 1);
 fs->name = g_strdup(guid);
 if (len == 0) {
 fs->mountpoint = g_strdup("System Reserved");
@@ -877,7 +877,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error 
**errp)
 continue;
 }
 
-uc_path = g_malloc(sizeof(WCHAR) * char_count);
+uc_path = g_new(WCHAR, char_count);
 if (!GetVolumePathNamesForVolumeNameW(guid, uc_path, char_count,
   _count) || !*uc_path) {
 /* strange, but this condition could be faced even with size == 2 
*/
@@ -1348,12 +1348,12 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error 
**errp)

[Qemu-devel] [PATCH 35/88] Record/replay: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 replay/replay-char.c   |  4 ++--
 replay/replay-events.c | 10 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/replay/replay-char.c b/replay/replay-char.c
index cbf7c04a9f..b8ed5c51d1 100755
--- a/replay/replay-char.c
+++ b/replay/replay-char.c
@@ -51,7 +51,7 @@ void replay_register_char_driver(Chardev *chr)
 
 void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
 {
-CharEvent *event = g_malloc0(sizeof(CharEvent));
+CharEvent *event = g_new0(CharEvent, 1);
 
 event->id = find_char_driver(s);
 if (event->id < 0) {
@@ -86,7 +86,7 @@ void replay_event_char_read_save(void *opaque)
 
 void *replay_event_char_read_load(void)
 {
-CharEvent *event = g_malloc0(sizeof(CharEvent));
+CharEvent *event = g_new0(CharEvent, 1);
 
 event->id = replay_get_byte();
 replay_get_array_alloc(>buf, >len);
diff --git a/replay/replay-events.c b/replay/replay-events.c
index 94a6dcccfc..c72dcaa708 100644
--- a/replay/replay-events.c
+++ b/replay/replay-events.c
@@ -128,7 +128,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind,
 return;
 }
 
-Event *event = g_malloc0(sizeof(Event));
+Event *event = g_new0(Event, 1);
 event->event_kind = event_kind;
 event->opaque = opaque;
 event->opaque2 = opaque2;
@@ -239,17 +239,17 @@ static Event *replay_read_event(int checkpoint)
 }
 break;
 case REPLAY_ASYNC_EVENT_INPUT:
-event = g_malloc0(sizeof(Event));
+event = g_new0(Event, 1);
 event->event_kind = read_event_kind;
 event->opaque = replay_read_input_event();
 return event;
 case REPLAY_ASYNC_EVENT_INPUT_SYNC:
-event = g_malloc0(sizeof(Event));
+event = g_new0(Event, 1);
 event->event_kind = read_event_kind;
 event->opaque = 0;
 return event;
 case REPLAY_ASYNC_EVENT_CHAR_READ:
-event = g_malloc0(sizeof(Event));
+event = g_new0(Event, 1);
 event->event_kind = read_event_kind;
 event->opaque = replay_event_char_read_load();
 return event;
@@ -259,7 +259,7 @@ static Event *replay_read_event(int checkpoint)
 }
 break;
 case REPLAY_ASYNC_EVENT_NET:
-event = g_malloc0(sizeof(Event));
+event = g_new0(Event, 1);
 event->event_kind = read_event_kind;
 event->opaque = replay_event_net_load();
 return event;
-- 
2.14.2




[Qemu-devel] [PATCH 28/88] disas: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: fixed const cast, squashed M68K + NiosII + SPARC, renamed subject "disas"]
---
 disas/m68k.c  | 3 +--
 disas/nios2.c | 3 +--
 disas/sparc.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/disas/m68k.c b/disas/m68k.c
index 61b689ef3e..31cf6ea5f9 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -1886,8 +1886,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
 
   /* Then create a sorted table of pointers
 that point into the unsorted table.  */
-  opc_pointer[0] = malloc (sizeof (struct m68k_opcode *)
-   * m68k_numopcodes);
+  opc_pointer[0] = g_new(const struct m68k_opcode *, m68k_numopcodes);
   opcodes[0] = opc_pointer[0];
 
   for (i = 1; i < 16; i++)
diff --git a/disas/nios2.c b/disas/nios2.c
index b342936d21..9e6e1e6a1f 100644
--- a/disas/nios2.c
+++ b/disas/nios2.c
@@ -2625,8 +2625,7 @@ nios2_init_opcode_hash (nios2_disassembler_state *state)
 
if (bucket)
  {
-   new_hash =
- (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
+   new_hash = g_new(nios2_opcode_hash, 1);
if (new_hash == NULL)
  {
fprintf (stderr,
diff --git a/disas/sparc.c b/disas/sparc.c
index f120f4e86d..6d0adab8a7 100644
--- a/disas/sparc.c
+++ b/disas/sparc.c
@@ -2684,8 +2684,7 @@ print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
   current_arch_mask = compute_arch_mask (info->mach);
 
   if (!opcodes_initialized)
-sorted_opcodes =
-  malloc (sparc_num_opcodes * sizeof (sparc_opcode *));
+sorted_opcodes = g_new(const sparc_opcode *, sparc_num_opcodes);
   /* Reset the sorted table so we can resort it.  */
   for (i = 0; i < sparc_num_opcodes; ++i)
 sorted_opcodes[i] = _opcodes[i];
-- 
2.14.2




[Qemu-devel] [PATCH 29/88] SPARC: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: split of disas/sparc.c change]
---
 hw/sparc/leon3.c | 2 +-
 hw/sparc64/sparc64.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index ec2816bf94..05e7adefb8 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -132,7 +132,7 @@ static void leon3_generic_hw_init(MachineState *machine)
 cpu_sparc_set_id(env, 0);
 
 /* Reset data */
-reset_info= g_malloc0(sizeof(ResetData));
+reset_info= g_new0(ResetData, 1);
 reset_info->cpu   = cpu;
 reset_info->sp= 0x4000 + ram_size;
 qemu_register_reset(main_cpu_reset, reset_info);
diff --git a/hw/sparc64/sparc64.c b/hw/sparc64/sparc64.c
index 097d529ff1..6f2197fc13 100644
--- a/hw/sparc64/sparc64.c
+++ b/hw/sparc64/sparc64.c
@@ -160,7 +160,7 @@ static CPUTimer *cpu_timer_create(const char *name, 
SPARCCPU *cpu,
   QEMUBHFunc *cb, uint32_t frequency,
   uint64_t disabled_mask, uint64_t npt_mask)
 {
-CPUTimer *timer = g_malloc0(sizeof(CPUTimer));
+CPUTimer *timer = g_new0(CPUTimer, 1);
 
 timer->name = name;
 timer->frequency = frequency;
@@ -368,7 +368,7 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
 hstick_frequency, TICK_INT_DIS,
 TICK_NPT_MASK);
 
-reset_info = g_malloc0(sizeof(ResetData));
+reset_info = g_new0(ResetData, 1);
 reset_info->cpu = cpu;
 reset_info->prom_addr = prom_addr;
 qemu_register_reset(main_cpu_reset, reset_info);
-- 
2.14.2




[Qemu-devel] [PATCH 21/88] NBD: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 nbd/server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 993ade30bb..b74cc6ab7e 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1047,7 +1047,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
dev_offset, off_t size,
 {
 AioContext *ctx;
 BlockBackend *blk;
-NBDExport *exp = g_malloc0(sizeof(NBDExport));
+NBDExport *exp = g_new0(NBDExport, 1);
 uint64_t perm;
 int ret;
 
@@ -1539,7 +1539,7 @@ void nbd_client_new(NBDExport *exp,
 NBDClient *client;
 Coroutine *co;
 
-client = g_malloc0(sizeof(NBDClient));
+client = g_new0(NBDClient, 1);
 client->refcount = 1;
 client->exp = exp;
 client->tlscreds = tlscreds;
-- 
2.14.2




[Qemu-devel] [PATCH 24/88] MIPS: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed malta + mipssim + r4k]
---
 hw/mips/mips_malta.c | 2 +-
 hw/mips/mips_mipssim.c   | 2 +-
 hw/mips/mips_r4k.c   | 2 +-
 target/mips/translate_init.c | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 2adb9bcf89..0eda20e120 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -555,7 +555,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion 
*address_space,
 MaltaFPGAState *s;
 Chardev *chr;
 
-s = (MaltaFPGAState *)g_malloc0(sizeof(MaltaFPGAState));
+s = g_new0(MaltaFPGAState, 1);
 
 memory_region_init_io(>iomem, NULL, _fpga_ops, s,
   "malta-fpga", 0x10);
diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
index a092072e2a..b2696faba1 100644
--- a/hw/mips/mips_mipssim.c
+++ b/hw/mips/mips_mipssim.c
@@ -166,7 +166,7 @@ mips_mipssim_init(MachineState *machine)
 cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
 env = >env;
 
-reset_info = g_malloc0(sizeof(ResetData));
+reset_info = g_new0(ResetData, 1);
 reset_info->cpu = cpu;
 reset_info->vector = env->active_tc.PC;
 qemu_register_reset(main_cpu_reset, reset_info);
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index 1272d4ef9d..233455d6e7 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -196,7 +196,7 @@ void mips_r4k_init(MachineState *machine)
 cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
 env = >env;
 
-reset_info = g_malloc0(sizeof(ResetData));
+reset_info = g_new0(ResetData, 1);
 reset_info->cpu = cpu;
 reset_info->vector = env->active_tc.PC;
 qemu_register_reset(main_cpu_reset, reset_info);
diff --git a/target/mips/translate_init.c b/target/mips/translate_init.c
index 8bbded46c4..9778776677 100644
--- a/target/mips/translate_init.c
+++ b/target/mips/translate_init.c
@@ -806,7 +806,7 @@ static void mmu_init (CPUMIPSState *env, const mips_def_t 
*def)
 {
 MIPSCPU *cpu = mips_env_get_cpu(env);
 
-env->tlb = g_malloc0(sizeof(CPUMIPSTLBContext));
+env->tlb = g_new0(CPUMIPSTLBContext, 1);
 
 switch (def->mmu_type) {
 case MMU_TYPE_NONE:
@@ -839,7 +839,7 @@ static void fpu_init (CPUMIPSState *env, const mips_def_t 
*def)
 
 static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
 {
-env->mvp = g_malloc0(sizeof(CPUMIPSMVPContext));
+env->mvp = g_new0(CPUMIPSMVPContext, 1);
 
 /* MVPConf1 implemented, TLB sharable, no gating storage support,
programmable cache partitioning implemented, number of allocatable
-- 
2.14.2




[Qemu-devel] [PATCH 27/88] SH4: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed R2D]
---
 hw/sh4/r2d.c| 4 ++--
 hw/sh4/sh7750.c | 2 +-
 hw/timer/sh_timer.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 16b9ed2db2..92d1fb99d7 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -186,7 +186,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
 {
 r2d_fpga_t *s;
 
-s = g_malloc0(sizeof(r2d_fpga_t));
+s = g_new0(r2d_fpga_t, 1);
 
 s->irl = irl;
 
@@ -249,7 +249,7 @@ static void r2d_init(MachineState *machine)
 cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
 env = >env;
 
-reset_info = g_malloc0(sizeof(ResetData));
+reset_info = g_new0(ResetData, 1);
 reset_info->cpu = cpu;
 reset_info->vector = env->pc;
 qemu_register_reset(main_cpu_reset, reset_info);
diff --git a/hw/sh4/sh7750.c b/hw/sh4/sh7750.c
index 166e4bd947..49c49c110b 100644
--- a/hw/sh4/sh7750.c
+++ b/hw/sh4/sh7750.c
@@ -728,7 +728,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion 
*sysmem)
 {
 SH7750State *s;
 
-s = g_malloc0(sizeof(SH7750State));
+s = g_new0(SH7750State, 1);
 s->cpu = cpu;
 s->periph_freq = 6000; /* 60MHz */
 memory_region_init_io(>iomem, NULL, _mem_ops, s,
diff --git a/hw/timer/sh_timer.c b/hw/timer/sh_timer.c
index 9afb2d048c..46f3eb9647 100644
--- a/hw/timer/sh_timer.c
+++ b/hw/timer/sh_timer.c
@@ -192,7 +192,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 = 0x;
@@ -313,7 +313,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base,
 tmu012_state *s;
 int timer_feat = (feat & TMU012_FEAT_EXTCLK) ? TIMER_FEAT_EXTCLK : 0;
 
-s = (tmu012_state *)g_malloc0(sizeof(tmu012_state));
+s = g_new0(tmu012_state, 1);
 s->feat = feat;
 s->timer[0] = sh_timer_init(freq, timer_feat, ch0_irq);
 s->timer[1] = sh_timer_init(freq, timer_feat, ch1_irq);
-- 
2.14.2




[Qemu-devel] [PATCH 26/88] S390: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: more changes in hw/s390x/css.c, added target/s390x/cpu_models.c]
---
 hw/s390x/css.c| 10 +-
 hw/s390x/s390-pci-bus.c   |  4 ++--
 target/s390x/cpu_models.c | 12 ++--
 target/s390x/diag.c   |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 35683d7954..b6d4fcaf06 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -488,7 +488,7 @@ int css_create_css_image(uint8_t cssid, bool default_image)
 if (channel_subsys.css[cssid]) {
 return -EBUSY;
 }
-channel_subsys.css[cssid] = g_malloc0(sizeof(CssImage));
+channel_subsys.css[cssid] = g_new0(CssImage, 1);
 if (default_image) {
 channel_subsys.default_cssid = cssid;
 }
@@ -1778,7 +1778,7 @@ void css_undo_stcrw(CRW *crw)
 {
 CrwContainer *crw_cont;
 
-crw_cont = g_try_malloc0(sizeof(CrwContainer));
+crw_cont = g_try_new0(CrwContainer, 1);
 if (!crw_cont) {
 channel_subsys.crws_lost = true;
 return;
@@ -2185,7 +2185,7 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, 
uint16_t schid,
 css = channel_subsys.css[cssid];
 
 if (!css->sch_set[ssid]) {
-css->sch_set[ssid] = g_malloc0(sizeof(SubchSet));
+css->sch_set[ssid] = g_new0(SubchSet, 1);
 }
 s_set = css->sch_set[ssid];
 
@@ -2206,7 +2206,7 @@ void css_queue_crw(uint8_t rsc, uint8_t erc, int 
solicited,
 
 trace_css_crw(rsc, erc, rsid, chain ? "(chained)" : "");
 /* TODO: Maybe use a static crw pool? */
-crw_cont = g_try_malloc0(sizeof(CrwContainer));
+crw_cont = g_try_new0(CrwContainer, 1);
 if (!crw_cont) {
 channel_subsys.crws_lost = true;
 return;
@@ -2498,7 +2498,7 @@ SubchDev *css_create_sch(CssDevId bus_id, bool 
is_virtual, bool squash_mcss,
 }
 }
 
-sch = g_malloc0(sizeof(*sch));
+sch = g_new0(SubchDev, 1);
 sch->cssid = bus_id.cssid;
 sch->ssid = bus_id.ssid;
 sch->devno = bus_id.devid;
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 96116b7d1e..e7a58e81f7 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -240,7 +240,7 @@ static void s390_pci_generate_event(uint8_t cc, uint16_t 
pec, uint32_t fh,
 SeiContainer *sei_cont;
 S390pciState *s = s390_get_phb();
 
-sei_cont = g_malloc0(sizeof(SeiContainer));
+sei_cont = g_new0(SeiContainer, 1);
 sei_cont->fh = fh;
 sei_cont->fid = fid;
 sei_cont->cc = cc;
@@ -416,7 +416,7 @@ static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, 
PCIBus *bus,
 S390PCIIOMMU *iommu;
 
 if (!table) {
-table = g_malloc0(sizeof(S390PCIIOMMUTable));
+table = g_new0(S390PCIIOMMUTable, 1);
 table->key = key;
 g_hash_table_insert(s->iommu_table, >key, table);
 }
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 07ef8a3b6e..8c2d8851ae 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -392,7 +392,7 @@ static void create_cpu_model_list(ObjectClass *klass, void 
*opaque)
 
 /* strip off the -s390-cpu */
 g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
-info = g_malloc0(sizeof(*info));
+info = g_new0(CpuDefinitionInfo, 1);
 info->name = name;
 info->has_migration_safe = true;
 info->migration_safe = scc->is_migration_safe;
@@ -412,7 +412,7 @@ static void create_cpu_model_list(ObjectClass *klass, void 
*opaque)
 object_unref(obj);
 }
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(CpuDefinitionInfoList, 1);
 entry->value = info;
 entry->next = *cpu_list;
 *cpu_list = entry;
@@ -574,7 +574,7 @@ CpuModelExpansionInfo 
*arch_query_cpu_model_expansion(CpuModelExpansionType type
 }
 
 /* convert it back to a static representation */
-expansion_info = g_malloc0(sizeof(*expansion_info));
+expansion_info = g_new0(CpuModelExpansionInfo, 1);
 expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
 cpu_info_from_model(expansion_info->model, _model, delta_changes);
 return expansion_info;
@@ -585,7 +585,7 @@ static void list_add_feat(const char *name, void *opaque)
 strList **last = (strList **) opaque;
 strList *entry;
 
-entry = g_malloc0(sizeof(*entry));
+entry = g_new0(strList, 1);
 entry->value = g_strdup(name);
 entry->next = *last;
 *last = entry;
@@ -609,7 +609,7 @@ CpuModelCompareInfo 
*arch_query_cpu_model_comparison(CpuModelInfo *infoa,
 if (*errp) {
 return NULL;
 }
-compare_info = g_malloc0(sizeof(*compare_info));
+compare_info = g_new0(CpuModelCompareInfo, 1);
 
 /* check the cpu generation and ga level */
 if (modela.def->gen == modelb.def->gen) {
@@ -713,7 +713,7 @@ CpuModelBaselineInfo 
*arch_query_cpu_model_baseline(CpuModelInfo 

[Qemu-devel] [PATCH 14/88] ui/vnc: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: renamed 'Graphics' -> ui/vnc, added ui/vnc.c and ui/vnc-palette.c]
---
 ui/vnc-enc-tight.c | 2 +-
 ui/vnc-palette.c   | 2 +-
 ui/vnc.c   | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index f38aceb4da..48ec584098 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -1475,7 +1475,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int 
w, int h)
 #endif
 
 if (!color_count_palette) {
-color_count_palette = g_malloc(sizeof(VncPalette));
+color_count_palette = g_new(VncPalette, 1);
 vnc_tight_cleanup_notifier.notify = vnc_tight_cleanup;
 qemu_thread_atexit_add(_tight_cleanup_notifier);
 }
diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index dc7c0ba997..284e118715 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -56,7 +56,7 @@ VncPalette *palette_new(size_t max, int bpp)
 {
 VncPalette *palette;
 
-palette = g_malloc0(sizeof(*palette));
+palette = g_new0(VncPalette, 1);
 palette_init(palette, max, bpp);
 return palette;
 }
diff --git a/ui/vnc.c b/ui/vnc.c
index 9f8d5a1b1f..b021fb398b 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -231,7 +231,7 @@ static VncServerInfo *vnc_server_info_get(VncDisplay *vd)
 return NULL;
 }
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(VncServerInfo, 1);
 vnc_init_basic_info_from_server_addr(vd->lsock[0],
  qapi_VncServerInfo_base(info), );
 info->has_auth = true;
@@ -316,7 +316,7 @@ static VncClientInfo *qmp_query_vnc_client(const VncState 
*client)
 VncClientInfo *info;
 Error *err = NULL;
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(VncClientInfo, 1);
 
 vnc_init_basic_info_from_remote_addr(client->sioc,
  qapi_VncClientInfo_base(info),
@@ -3047,7 +3047,7 @@ void vnc_display_init(const char *id)
 if (vnc_display_find(id) != NULL) {
 return;
 }
-vd = g_malloc0(sizeof(*vd));
+vd = g_new0(VncDisplay, 1);
 
 vd->id = strdup(id);
 QTAILQ_INSERT_TAIL(_displays, vd, next);
-- 
2.14.2




[Qemu-devel] [PATCH 23/88] M68K: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed commits]
---
 hw/m68k/mcf5206.c | 4 ++--
 hw/m68k/mcf5208.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
index b81901fdfd..df45e99547 100644
--- a/hw/m68k/mcf5206.c
+++ b/hw/m68k/mcf5206.c
@@ -137,7 +137,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, PTIMER_POLICY_DEFAULT);
 s->irq = irq;
@@ -533,7 +533,7 @@ qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, 
M68kCPU *cpu)
 m5206_mbar_state *s;
 qemu_irq *pic;
 
-s = (m5206_mbar_state *)g_malloc0(sizeof(m5206_mbar_state));
+s = g_new0(m5206_mbar_state, 1);
 
 memory_region_init_io(>iomem, NULL, _mbar_ops, s,
   "mbar", 0x1000);
diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index b9dde75106..9b93af5fbd 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -183,7 +183,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, PTIMER_POLICY_DEFAULT);
 memory_region_init_io(>iomem, NULL, _timer_ops, s,
-- 
2.14.2




[Qemu-devel] [PATCH 20/88] Migration: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: indented, added migration/migration.c and migration/page_cache.c]
---
 migration/migration.c| 2 +-
 migration/page_cache.c   | 2 +-
 migration/postcopy-ram.c | 2 +-
 migration/ram.c  | 3 +--
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 98429dc843..4899182b32 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -485,7 +485,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error 
**errp)
 MigrationState *s = migrate_get_current();
 
 /* TODO use QAPI_CLONE() instead of duplicating it inline */
-params = g_malloc0(sizeof(*params));
+params = g_new0(MigrationParameters, 1);
 params->has_compress_level = true;
 params->compress_level = s->parameters.compress_level;
 params->has_compress_threads = true;
diff --git a/migration/page_cache.c b/migration/page_cache.c
index ba984c4858..30169a1dd3 100644
--- a/migration/page_cache.c
+++ b/migration/page_cache.c
@@ -57,7 +57,7 @@ PageCache *cache_init(int64_t num_pages, unsigned int 
page_size)
 }
 
 /* We prefer not to abort if there is no memory */
-cache = g_try_malloc(sizeof(*cache));
+cache = g_try_new(PageCache, 1);
 if (!cache) {
 DPRINTF("Failed to allocate cache\n");
 return NULL;
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 0de68e8b25..d51684ce30 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -811,7 +811,7 @@ void *postcopy_get_tmp_page(MigrationIncomingState *mis)
 PostcopyDiscardState *postcopy_discard_send_init(MigrationState *ms,
  const char *name)
 {
-PostcopyDiscardState *res = g_malloc0(sizeof(PostcopyDiscardState));
+PostcopyDiscardState *res = g_new0(PostcopyDiscardState, 1);
 
 if (res) {
 res->ramblock_name = name;
diff --git a/migration/ram.c b/migration/ram.c
index b83f8977c5..3f5407ee43 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1376,8 +1376,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t 
start, ram_addr_t len)
 goto err;
 }
 
-struct RAMSrcPageRequest *new_entry =
-g_malloc0(sizeof(struct RAMSrcPageRequest));
+struct RAMSrcPageRequest *new_entry = g_new0(struct RAMSrcPageRequest, 1);
 new_entry->rb = ramblock;
 new_entry->offset = start;
 new_entry->len = len;
-- 
2.14.2




[Qemu-devel] [PATCH 11/88] Cryptodev Backends: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 backends/cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 67edfa5328..44f693f58b 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -42,7 +42,7 @@ cryptodev_backend_new_client(const char *model,
 {
 CryptoDevBackendClient *cc;
 
-cc = g_malloc0(sizeof(CryptoDevBackendClient));
+cc = g_new0(CryptoDevBackendClient, 1);
 cc->model = g_strdup(model);
 if (name) {
 cc->name = g_strdup(name);
-- 
2.14.2




[Qemu-devel] [PATCH 25/88] OpenRISC: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed openrisc_sim.c]
---
 hw/openrisc/openrisc_sim.c | 2 +-
 target/openrisc/mmu.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
index 86bf2849c4..1eb381549c 100644
--- a/hw/openrisc/openrisc_sim.c
+++ b/hw/openrisc/openrisc_sim.c
@@ -114,7 +114,7 @@ static void openrisc_sim_init(MachineState *machine)
 main_cpu_reset(cpu);
 }
 
-ram = g_malloc(sizeof(*ram));
+ram = g_new(MemoryRegion, 1);
 memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, _fatal);
 memory_region_add_subregion(get_system_memory(), 0, ram);
 
diff --git a/target/openrisc/mmu.c b/target/openrisc/mmu.c
index ce2a29dd1a..4789a35b67 100644
--- a/target/openrisc/mmu.c
+++ b/target/openrisc/mmu.c
@@ -247,7 +247,7 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr 
addr)
 
 void cpu_openrisc_mmu_init(OpenRISCCPU *cpu)
 {
-cpu->env.tlb = g_malloc0(sizeof(CPUOpenRISCTLBContext));
+cpu->env.tlb = g_new0(CPUOpenRISCTLBContext, 1);
 
 cpu->env.tlb->cpu_openrisc_map_address_code = _openrisc_get_phys_nommu;
 cpu->env.tlb->cpu_openrisc_map_address_data = _openrisc_get_phys_nommu;
-- 
2.14.2




[Qemu-devel] [PATCH 22/88] LM32: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed milkymist]
---
 hw/lm32/lm32_hwsetup.h | 2 +-
 hw/lm32/lm32_boards.c  | 4 ++--
 hw/lm32/milkymist.c| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
index a01f6bc5df..38ade3db0e 100644
--- a/hw/lm32/lm32_hwsetup.h
+++ b/hw/lm32/lm32_hwsetup.h
@@ -58,7 +58,7 @@ static inline HWSetup *hwsetup_init(void)
 {
 HWSetup *hw;
 
-hw = g_malloc(sizeof(HWSetup));
+hw = g_new(HWSetup, 1);
 hw->data = g_malloc0(TARGET_PAGE_SIZE);
 hw->ptr = hw->data;
 
diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index b0bb3ef58a..a9c74e90d4 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -99,7 +99,7 @@ static void lm32_evr_init(MachineState *machine)
 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";
@@ -196,7 +196,7 @@ static void lm32_uclinux_init(MachineState *machine)
 hwaddr initrd_base  = 0x0840;
 size_t initrd_max   = 0x0100;
 
-reset_info = g_malloc0(sizeof(ResetInfo));
+reset_info = g_new0(ResetInfo, 1);
 
 if (cpu_model == NULL) {
 cpu_model = "lm32-full";
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 4db4d2d533..0335f0b322 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -106,7 +106,7 @@ milkymist_init(MachineState *machine)
 hwaddr cmdline_base = sdram_base + 0x100;
 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";
-- 
2.14.2




[Qemu-devel] [PATCH 15/88] ui/spice: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 ui/spice-core.c| 10 +-
 ui/spice-display.c |  4 ++--
 ui/spice-input.c   |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index ea04dc69b5..e76a3f46eb 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -63,7 +63,7 @@ static SpiceTimer *timer_add(SpiceTimerFunc func, void 
*opaque)
 {
 SpiceTimer *timer;
 
-timer = g_malloc0(sizeof(*timer));
+timer = g_new0(SpiceTimer, 1);
 timer->timer = timer_new_ms(QEMU_CLOCK_REALTIME, func, opaque);
 QTAILQ_INSERT_TAIL(, timer, next);
 return timer;
@@ -127,7 +127,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;
@@ -155,7 +155,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(_list, item, link);
 }
@@ -380,7 +380,7 @@ static SpiceChannelList *qmp_query_spice_channels(void)
 
 assert(item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT);
 
-chan = g_malloc0(sizeof(*chan));
+chan = g_new0(SpiceChannelList, 1);
 chan->value = g_malloc0(sizeof(*chan->value));
 
 paddr = (struct sockaddr *)>info->paddr_ext;
@@ -525,7 +525,7 @@ SpiceInfo *qmp_query_spice(Error **errp)
 unsigned int minor;
 unsigned int micro;
 
-info = g_malloc0(sizeof(*info));
+info = g_new0(SpiceInfo, 1);
 
 if (!spice_server || !opts) {
 info->enabled = false;
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 0963c7825f..5b9f6f0bb0 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -66,7 +66,7 @@ QXLCookie *qxl_cookie_new(int type, uint64_t io)
 {
 QXLCookie *cookie;
 
-cookie = g_malloc0(sizeof(*cookie));
+cookie = g_new0(QXLCookie, 1);
 cookie->type = type;
 cookie->io = io;
 return cookie;
@@ -142,7 +142,7 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay 
*ssd,
rect->left, rect->right,
rect->top, rect->bottom);
 
-update   = g_malloc0(sizeof(*update));
+update = g_new0(SimpleSpiceUpdate, 1);
 drawable = >drawable;
 image= >image;
 cmd  = >ext.cmd;
diff --git a/ui/spice-input.c b/ui/spice-input.c
index 3d41aa1831..e47ca7a051 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -243,12 +243,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 = _interface.base;
 qemu_spice_add_interface(>sin.base);
 qemu_add_led_event_handler(kbd_leds, kbd);
 
-pointer = g_malloc0(sizeof(*pointer));
+pointer = g_new0(QemuSpicePointer, 1);
 pointer->mouse.base.sif  = _interface.base;
 pointer->tablet.base.sif = _interface.base;
 qemu_spice_add_interface(>mouse.base);
-- 
2.14.2




[Qemu-devel] [PATCH 10/88] Character devices: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed PC Chipsets: parallel + serial]
---
 hw/char/parallel.c  | 2 +-
 hw/char/serial.c| 4 ++--
 hw/char/sh_serial.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/char/parallel.c b/hw/char/parallel.c
index f79dc76543..da8566538e 100644
--- a/hw/char/parallel.c
+++ b/hw/char/parallel.c
@@ -614,7 +614,7 @@ bool parallel_mm_init(MemoryRegion *address_space,
 {
 ParallelState *s;
 
-s = g_malloc0(sizeof(ParallelState));
+s = g_new0(ParallelState, 1);
 s->irq = irq;
 qemu_chr_fe_init(>chr, chr, _abort);
 s->it_shift = it_shift;
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 376bd2f240..dcc25d649f 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -978,7 +978,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;
@@ -1034,7 +1034,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
 {
 SerialState *s;
 
-s = g_malloc0(sizeof(SerialState));
+s = g_new0(SerialState, 1);
 
 s->it_shift = it_shift;
 s->irq = irq;
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c
index 835b5378a0..0d1a67d450 100644
--- a/hw/char/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -365,7 +365,7 @@ void sh_serial_init(MemoryRegion *sysmem,
 {
 sh_serial_state *s;
 
-s = g_malloc0(sizeof(sh_serial_state));
+s = g_new0(sh_serial_state, 1);
 
 s->feat = feat;
 s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE;
-- 
2.14.2




[Qemu-devel] [PATCH 18/88] memory: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
does this file belong to the Memory API subsystem in MAINTAINERS?

 memory_mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/memory_mapping.c b/memory_mapping.c
index a5d38552a6..9c78b41363 100644
--- a/memory_mapping.c
+++ b/memory_mapping.c
@@ -43,7 +43,7 @@ static void create_new_memory_mapping(MemoryMappingList *list,
 {
 MemoryMapping *memory_mapping;
 
-memory_mapping = g_malloc(sizeof(MemoryMapping));
+memory_mapping = g_new(MemoryMapping, 1);
 memory_mapping->phys_addr = phys_addr;
 memory_mapping->virt_addr = virt_addr;
 memory_mapping->length = length;
-- 
2.14.2




[Qemu-devel] [PATCH 19/88] exec: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 exec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index 7a80460725..e060c6fea7 100644
--- a/exec.c
+++ b/exec.c
@@ -836,7 +836,7 @@ int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr 
len,
  VADDR_PRIx ", len=%" VADDR_PRIu, addr, len);
 return -EINVAL;
 }
-wp = g_malloc(sizeof(*wp));
+wp = g_new(CPUWatchpoint, 1);
 
 wp->vaddr = addr;
 wp->len = len;
@@ -922,7 +922,7 @@ int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int 
flags,
 {
 CPUBreakpoint *bp;
 
-bp = g_malloc(sizeof(*bp));
+bp = g_new(CPUBreakpoint, 1);
 
 bp->pc = pc;
 bp->flags = flags;
@@ -1975,7 +1975,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, 
MemoryRegion *mr,
 return NULL;
 }
 
-new_block = g_malloc0(sizeof(*new_block));
+new_block = g_new0(RAMBlock, 1);
 new_block->mr = mr;
 new_block->used_length = size;
 new_block->max_length = size;
@@ -2036,7 +2036,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, 
ram_addr_t max_size,
 
 size = HOST_PAGE_ALIGN(size);
 max_size = HOST_PAGE_ALIGN(max_size);
-new_block = g_malloc0(sizeof(*new_block));
+new_block = g_new0(RAMBlock, 1);
 new_block->mr = mr;
 new_block->resized = resized;
 new_block->used_length = size;
-- 
2.14.2




[Qemu-devel] [PATCH 13/88] Dirty Bitmaps: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: squashed tests/test-hbitmap.c changes]
---
 tests/test-hbitmap.c | 2 +-
 util/hbitmap.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
index af41642346..fea3a64712 100644
--- a/tests/test-hbitmap.c
+++ b/tests/test-hbitmap.c
@@ -122,7 +122,7 @@ static void hbitmap_test_truncate_impl(TestHBitmapData 
*data,
 
 n = hbitmap_test_array_size(size);
 m = hbitmap_test_array_size(data->old_size);
-data->bits = g_realloc(data->bits, sizeof(unsigned long) * n);
+data->bits = g_renew(unsigned long, data->bits, n);
 if (n > m) {
 memset(>bits[m], 0x00, sizeof(unsigned long) * (n - m));
 }
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 2f9d0fdbd0..4eb0188836 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -668,7 +668,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
 }
 old = hb->sizes[i];
 hb->sizes[i] = size;
-hb->levels[i] = g_realloc(hb->levels[i], size * sizeof(unsigned long));
+hb->levels[i] = g_renew(unsigned long, hb->levels[i], size);
 if (!shrink) {
 memset(>levels[i][old], 0x00,
(size - old) * sizeof(*hb->levels[i]));
-- 
2.14.2




[Qemu-devel] [PATCH 08/88] BT: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Signed-off-by: Philippe Mathieu-Daudé 
[PMD: another use in hw/bt/l2cap.c]
---
 bt-host.c | 2 +-
 bt-vhci.c | 2 +-
 hw/bt/core.c  | 4 ++--
 hw/bt/hci.c   | 4 ++--
 hw/bt/l2cap.c | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/bt-host.c b/bt-host.c
index 2f8f631c25..ad9e45ea43 100644
--- a/bt-host.c
+++ b/bt-host.c
@@ -177,7 +177,7 @@ struct HCIInfo *bt_host_hci(const char *id)
 }
 # endif
 
-s = g_malloc0(sizeof(struct bt_host_hci_s));
+s = g_new0(struct bt_host_hci_s, 1);
 s->fd = fd;
 s->hci.cmd_send = bt_host_cmd;
 s->hci.sco_send = bt_host_sco;
diff --git a/bt-vhci.c b/bt-vhci.c
index 9d277c32bf..a885e2b8b9 100644
--- a/bt-vhci.c
+++ b/bt-vhci.c
@@ -157,7 +157,7 @@ void bt_vhci_init(struct HCIInfo *info)
 exit(-1);
 }
 
-s = g_malloc0(sizeof(struct bt_vhci_s));
+s = g_new0(struct bt_vhci_s, 1);
 s->fd = fd;
 s->info = info ?: qemu_next_hci();
 s->info->opaque = s;
diff --git a/hw/bt/core.c b/hw/bt/core.c
index 615f0af073..281bb40501 100644
--- a/hw/bt/core.c
+++ b/hw/bt/core.c
@@ -55,7 +55,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;
@@ -135,7 +135,7 @@ struct bt_scatternet_s *qemu_find_bt_vlan(int id)
 if (vlan->id == id)
 return >net;
 }
-vlan = g_malloc0(sizeof(struct bt_vlan_s));
+vlan = g_new0(struct bt_vlan_s, 1);
 vlan->id = id;
 pvlan = _bt_vlan;
 while (*pvlan != NULL)
diff --git a/hw/bt/hci.c b/hw/bt/hci.c
index 476ebec0ab..08e65eb62e 100644
--- a/hw/bt/hci.c
+++ b/hw/bt/hci.c
@@ -742,7 +742,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;
@@ -2158,7 +2158,7 @@ static void bt_hci_destroy(struct bt_device_s *dev)
 
 struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
 {
-struct bt_hci_s *s = g_malloc0(sizeof(struct bt_hci_s));
+struct bt_hci_s *s = g_new0(struct bt_hci_s, 1);
 
 s->lm.inquiry_done = timer_new_ns(QEMU_CLOCK_VIRTUAL, bt_hci_inquiry_done, 
s);
 s->lm.inquiry_next = timer_new_ns(QEMU_CLOCK_VIRTUAL, bt_hci_inquiry_next, 
s);
diff --git a/hw/bt/l2cap.c b/hw/bt/l2cap.c
index e342045140..94f5067d6e 100644
--- a/hw/bt/l2cap.c
+++ b/hw/bt/l2cap.c
@@ -1241,7 +1241,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 = >device;
 l2cap->link.host = link->host;
 l2cap_init(>l2cap, >link, 0);
@@ -1262,7 +1262,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;
@@ -1358,7 +1358,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;
-- 
2.14.2




[Qemu-devel] [PATCH 17/88] Memory API: use g_new() family of functions

2017-10-06 Thread Philippe Mathieu-Daudé
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index 5e6351a6c1..40d30640eb 100644
--- a/memory.c
+++ b/memory.c
@@ -2762,7 +2762,7 @@ void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, 
hwaddr offset,
 }
 
 if (!invalidate_data) {
-invalidate_data = g_malloc0(sizeof(MMIOPtrInvalidate));
+invalidate_data = g_new0(MMIOPtrInvalidate, 1);
 invalidate_data->allocated = 1;
 }
 
-- 
2.14.2




  1   2   3   4   5   >