qdev: Convert uses of qdev_create() with Coccinelle
commit3e80f6902c13f6edb6675c0f33edcbbf0163ec32
authorMarkus Armbruster <armbru@redhat.com>
Wed, 10 Jun 2020 05:31:58 +0000 (10 07:31 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 15 Jun 2020 20:00:10 +0000 (15 22:00 +0200)
treec96a01def8de48a3fc1721bfe6344b9993bfaecf
parentdc3edf8d8a544dbf21e1cb63339e42806470d5d9
qdev: Convert uses of qdev_create() with Coccinelle

This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion.  More to come in
this series.

Coccinelle script:

    @ depends on !(file in "hw/arm/highbank.c")@
    expression bus, type_name, dev, expr;
    @@
    -    dev = qdev_create(bus, type_name);
    +    dev = qdev_new(type_name);
         ... when != dev = expr
    -    qdev_init_nofail(dev);
    +    qdev_realize_and_unref(dev, bus, &error_fatal);

    @@
    expression bus, type_name, dev, expr;
    identifier DOWN;
    @@
    -    dev = DOWN(qdev_create(bus, type_name));
    +    dev = DOWN(qdev_new(type_name));
         ... when != dev = expr
    -    qdev_init_nofail(DEVICE(dev));
    +    qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);

    @@
    expression bus, type_name, expr;
    identifier dev;
    @@
    -    DeviceState *dev = qdev_create(bus, type_name);
    +    DeviceState *dev = qdev_new(type_name);
         ... when != dev = expr
    -    qdev_init_nofail(dev);
    +    qdev_realize_and_unref(dev, bus, &error_fatal);

    @@
    expression bus, type_name, dev, expr, errp;
    symbol true;
    @@
    -    dev = qdev_create(bus, type_name);
    +    dev = qdev_new(type_name);
         ... when != dev = expr
    -    object_property_set_bool(OBJECT(dev), true, "realized", errp);
    +    qdev_realize_and_unref(dev, bus, errp);

    @@
    expression bus, type_name, expr, errp;
    identifier dev;
    symbol true;
    @@
    -    DeviceState *dev = qdev_create(bus, type_name);
    +    DeviceState *dev = qdev_new(type_name);
         ... when != dev = expr
    -    object_property_set_bool(OBJECT(dev), true, "realized", errp);
    +    qdev_realize_and_unref(dev, bus, errp);

The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name.  Covered by the
next commit's manual conversions.

Missing #include "qapi/error.h" added manually.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
127 files changed:
hw/alpha/typhoon.c
hw/arm/aspeed.c
hw/arm/cubieboard.c
hw/arm/exynos4210.c
hw/arm/exynos4_boards.c
hw/arm/imx25_pdk.c
hw/arm/integratorcp.c
hw/arm/mcimx6ul-evk.c
hw/arm/mcimx7d-sabre.c
hw/arm/mps2-tz.c
hw/arm/msf2-som.c
hw/arm/musicpal.c
hw/arm/netduino2.c
hw/arm/netduinoplus2.c
hw/arm/nseries.c
hw/arm/omap1.c
hw/arm/omap2.c
hw/arm/orangepi.c
hw/arm/pxa2xx.c
hw/arm/pxa2xx_gpio.c
hw/arm/pxa2xx_pic.c
hw/arm/raspi.c
hw/arm/realview.c
hw/arm/sbsa-ref.c
hw/arm/spitz.c
hw/arm/stellaris.c
hw/arm/strongarm.c
hw/arm/versatilepb.c
hw/arm/vexpress.c
hw/arm/virt.c
hw/arm/xilinx_zynq.c
hw/arm/xlnx-versal-virt.c
hw/arm/xlnx-versal.c
hw/arm/xlnx-zcu102.c
hw/audio/intel-hda.c
hw/block/fdc.c
hw/block/pflash_cfi01.c
hw/block/pflash_cfi02.c
hw/char/exynos4210_uart.c
hw/char/mcf_uart.c
hw/char/spapr_vty.c
hw/core/sysbus.c
hw/cris/axis_dev88.c
hw/display/milkymist-tmu2.c
hw/display/sm501.c
hw/dma/pxa2xx_dma.c
hw/dma/rc4030.c
hw/dma/sparc32_dma.c
hw/hppa/dino.c
hw/hppa/lasi.c
hw/hppa/machine.c
hw/i2c/core.c
hw/i2c/smbus_eeprom.c
hw/i386/pc_q35.c
hw/i386/x86.c
hw/ide/qdev.c
hw/intc/exynos4210_gic.c
hw/intc/s390_flic.c
hw/isa/isa-bus.c
hw/lm32/lm32.h
hw/lm32/milkymist-hw.h
hw/m68k/mcf5208.c
hw/m68k/mcf_intc.c
hw/m68k/next-cube.c
hw/m68k/q800.c
hw/microblaze/petalogix_ml605_mmu.c
hw/microblaze/petalogix_s3adsp1800_mmu.c
hw/mips/boston.c
hw/mips/gt64xxx_pci.c
hw/mips/jazz.c
hw/mips/malta.c
hw/mips/mipssim.c
hw/misc/empty_slot.c
hw/net/etraxfs_eth.c
hw/net/fsl_etsec/etsec.c
hw/net/lan9118.c
hw/net/lasi_i82596.c
hw/net/smc91c111.c
hw/net/spapr_llan.c
hw/nios2/10m50_devboard.c
hw/nvram/fw_cfg.c
hw/openrisc/openrisc_sim.c
hw/pci-bridge/pci_expander_bridge.c
hw/pci-host/bonito.c
hw/pci-host/i440fx.c
hw/pcmcia/pxa2xx.c
hw/ppc/e500.c
hw/ppc/mac_newworld.c
hw/ppc/mac_oldworld.c
hw/ppc/pnv.c
hw/ppc/ppc440_uc.c
hw/ppc/prep.c
hw/ppc/sam460ex.c
hw/ppc/spapr.c
hw/ppc/spapr_irq.c
hw/ppc/spapr_vio.c
hw/ppc/virtex_ml507.c
hw/riscv/sifive_clint.c
hw/riscv/sifive_e_prci.c
hw/riscv/sifive_plic.c
hw/riscv/sifive_test.c
hw/riscv/virt.c
hw/rtc/m48t59.c
hw/rtc/sun4v-rtc.c
hw/s390x/ap-bridge.c
hw/s390x/css-bridge.c
hw/s390x/s390-virtio-ccw.c
hw/scsi/scsi-bus.c
hw/scsi/spapr_vscsi.c
hw/sd/milkymist-memcard.c
hw/sd/pxa2xx_mmci.c
hw/sd/ssi-sd.c
hw/sh4/r2d.c
hw/sparc/leon3.c
hw/sparc/sun4m.c
hw/sparc64/sun4u.c
hw/xen/xen-bus.c
hw/xen/xen-legacy-backend.c
hw/xtensa/virt.c
hw/xtensa/xtfpga.c
include/hw/char/cadence_uart.h
include/hw/char/cmsdk-apb-uart.h
include/hw/char/pl011.h
include/hw/char/xilinx_uartlite.h
include/hw/cris/etraxfs.h
include/hw/misc/unimp.h
include/hw/timer/cmsdk-apb-timer.h