Skip to content

Commit

Permalink
hw: Remove unnecessary DEVICE() cast
Browse files Browse the repository at this point in the history
The DEVICE() macro is defined as:

  #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)

which expands to:

  ((DeviceState *)object_dynamic_cast_assert((Object *)(obj), (name),
                                             __FILE__, __LINE__,
                                             __func__))

This assertion can only fail when @obj points to something other
than its stated type, i.e. when we're in undefined behavior country.

Remove the unnecessary DEVICE() casts when we already know the
pointer is of DeviceState type.

Patch created mechanically using spatch with this script:

  @@
  typedef DeviceState;
  DeviceState *s;
  @@
  -   DEVICE(s)
  +   s

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Paul Durrant <paul@xen.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: John Snow <jsnow@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20200512070020.22782-4-f4bug@amsat.org>
  • Loading branch information
philmd authored and Markus Armbruster committed May 15, 2020
1 parent 688ffbb commit 8e5c952
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion hw/display/artist.c
Expand Up @@ -1353,7 +1353,7 @@ static void artist_realizefn(DeviceState *dev, Error **errp)
s->cursor_height = 32;
s->cursor_width = 32;

s->con = graphic_console_init(DEVICE(dev), 0, &artist_ops, s);
s->con = graphic_console_init(dev, 0, &artist_ops, s);
qemu_console_resize(s->con, s->width, s->height);
}

Expand Down
2 changes: 1 addition & 1 deletion hw/display/cg3.c
Expand Up @@ -321,7 +321,7 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)

sysbus_init_irq(sbd, &s->irq);

s->con = graphic_console_init(DEVICE(dev), 0, &cg3_ops, s);
s->con = graphic_console_init(dev, 0, &cg3_ops, s);
qemu_console_resize(s->con, s->width, s->height);
}

Expand Down
2 changes: 1 addition & 1 deletion hw/display/sm501.c
Expand Up @@ -1839,7 +1839,7 @@ static void sm501_init(SM501State *s, DeviceState *dev,
&s->twoD_engine_region);

/* create qemu graphic console */
s->con = graphic_console_init(DEVICE(dev), 0, &sm501_ops, s);
s->con = graphic_console_init(dev, 0, &sm501_ops, s);
}

static const VMStateDescription vmstate_sm501_state = {
Expand Down
4 changes: 2 additions & 2 deletions hw/display/tcx.c
Expand Up @@ -868,9 +868,9 @@ static void tcx_realizefn(DeviceState *dev, Error **errp)
sysbus_init_irq(sbd, &s->irq);

if (s->depth == 8) {
s->con = graphic_console_init(DEVICE(dev), 0, &tcx_ops, s);
s->con = graphic_console_init(dev, 0, &tcx_ops, s);
} else {
s->con = graphic_console_init(DEVICE(dev), 0, &tcx24_ops, s);
s->con = graphic_console_init(dev, 0, &tcx24_ops, s);
}
s->thcmisc = 0;

Expand Down
2 changes: 1 addition & 1 deletion hw/display/vga-isa.c
Expand Up @@ -74,7 +74,7 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp)
0x000a0000,
vga_io_memory, 1);
memory_region_set_coalescing(vga_io_memory);
s->con = graphic_console_init(DEVICE(dev), 0, s->hw_ops, s);
s->con = graphic_console_init(dev, 0, s->hw_ops, s);

memory_region_add_subregion(isa_address_space(isadev),
VBE_DISPI_LFB_PHYSICAL_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion hw/i2c/imx_i2c.c
Expand Up @@ -305,7 +305,7 @@ static void imx_i2c_realize(DeviceState *dev, Error **errp)
IMX_I2C_MEM_SIZE);
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
s->bus = i2c_init_bus(DEVICE(dev), NULL);
s->bus = i2c_init_bus(dev, NULL);
}

static void imx_i2c_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/i2c/mpc_i2c.c
Expand Up @@ -332,7 +332,7 @@ static void mpc_i2c_realize(DeviceState *dev, Error **errp)
memory_region_init_io(&i2c->iomem, OBJECT(i2c), &i2c_ops, i2c,
"mpc-i2c", 0x14);
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &i2c->iomem);
i2c->bus = i2c_init_bus(DEVICE(dev), "i2c");
i2c->bus = i2c_init_bus(dev, "i2c");
}

static void mpc_i2c_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/ide/piix.c
Expand Up @@ -193,7 +193,7 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux)
blk_unref(blk);
}
}
qdev_reset_all(DEVICE(dev));
qdev_reset_all(dev);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion hw/misc/macio/pmu.c
Expand Up @@ -758,7 +758,7 @@ static void pmu_realize(DeviceState *dev, Error **errp)

if (s->has_adb) {
qbus_create_inplace(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS,
DEVICE(dev), "adb.0");
dev, "adb.0");
s->adb_poll_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, pmu_adb_poll, s);
s->adb_poll_mask = 0xffff;
s->autopoll_rate_ms = 20;
Expand Down
3 changes: 1 addition & 2 deletions hw/net/ftgmac100.c
Expand Up @@ -1035,8 +1035,7 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
qemu_macaddr_default_if_unset(&s->conf.macaddr);

s->nic = qemu_new_nic(&net_ftgmac100_info, &s->conf,
object_get_typename(OBJECT(dev)), DEVICE(dev)->id,
s);
object_get_typename(OBJECT(dev)), dev->id, s);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
}

Expand Down
2 changes: 1 addition & 1 deletion hw/net/imx_fec.c
Expand Up @@ -1323,7 +1323,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)

s->nic = qemu_new_nic(&imx_eth_net_info, &s->conf,
object_get_typename(OBJECT(dev)),
DEVICE(dev)->id, s);
dev->id, s);

qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
}
Expand Down
2 changes: 1 addition & 1 deletion hw/nubus/nubus-device.c
Expand Up @@ -156,7 +156,7 @@ void nubus_register_rom(NubusDevice *dev, const uint8_t *rom, uint32_t size,

static void nubus_device_realize(DeviceState *dev, Error **errp)
{
NubusBus *nubus = NUBUS_BUS(qdev_get_parent_bus(DEVICE(dev)));
NubusBus *nubus = NUBUS_BUS(qdev_get_parent_bus(dev));
NubusDevice *nd = NUBUS_DEVICE(dev);
char *name;
hwaddr slot_offset;
Expand Down
2 changes: 1 addition & 1 deletion hw/pci-host/bonito.c
Expand Up @@ -606,7 +606,7 @@ static void bonito_pcihost_realize(DeviceState *dev, Error **errp)
BonitoState *bs = BONITO_PCI_HOST_BRIDGE(dev);

memory_region_init(&bs->pci_mem, OBJECT(dev), "pci.mem", BONITO_PCILO_SIZE);
phb->bus = pci_register_root_bus(DEVICE(dev), "pci",
phb->bus = pci_register_root_bus(dev, "pci",
pci_bonito_set_irq, pci_bonito_map_irq,
dev, &bs->pci_mem, get_system_io(),
0x28, 32, TYPE_PCI_BUS);
Expand Down
2 changes: 1 addition & 1 deletion hw/ppc/spapr.c
Expand Up @@ -4013,7 +4013,7 @@ static void spapr_phb_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
/* hotplug hooks should check it's enabled before getting this far */
assert(drc);

spapr_drc_attach(drc, DEVICE(dev), &local_err);
spapr_drc_attach(drc, dev, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
Expand Down
2 changes: 1 addition & 1 deletion hw/sh4/sh_pci.c
Expand Up @@ -129,7 +129,7 @@ static void sh_pci_device_realize(DeviceState *dev, Error **errp)
for (i = 0; i < 4; i++) {
sysbus_init_irq(sbd, &s->irq[i]);
}
phb->bus = pci_register_root_bus(DEVICE(dev), "pci",
phb->bus = pci_register_root_bus(dev, "pci",
sh_pci_set_irq, sh_pci_map_irq,
s->irq,
get_system_memory(),
Expand Down
2 changes: 1 addition & 1 deletion hw/xen/xen-legacy-backend.c
Expand Up @@ -705,7 +705,7 @@ int xen_be_init(void)

xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
qdev_init_nofail(xen_sysdev);
xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
xen_sysbus = qbus_create(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus");
qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);

return 0;
Expand Down

0 comments on commit 8e5c952

Please sign in to comment.