mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
Make qdev_init() destroy the device on failure
Before, every caller had to do this. Only two actually did. Patchworks-ID: 35170 Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
05a9169929
commit
18cfeb52d1
2 changed files with 6 additions and 4 deletions
|
@ -127,7 +127,6 @@ ISADevice *isa_create_simple(const char *name)
|
||||||
|
|
||||||
dev = isa_create(name);
|
dev = isa_create(name);
|
||||||
if (qdev_init(&dev->qdev) != 0) {
|
if (qdev_init(&dev->qdev) != 0) {
|
||||||
qdev_free(&dev->qdev);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return dev;
|
return dev;
|
||||||
|
|
|
@ -216,7 +216,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
}
|
}
|
||||||
if (qdev_init(qdev) != 0) {
|
if (qdev_init(qdev) != 0) {
|
||||||
qemu_error("Error initializing device %s\n", driver);
|
qemu_error("Error initializing device %s\n", driver);
|
||||||
qdev_free(qdev);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
qdev->opts = opts;
|
qdev->opts = opts;
|
||||||
|
@ -232,15 +231,19 @@ static void qdev_reset(void *opaque)
|
||||||
|
|
||||||
/* Initialize a device. Device properties should be set before calling
|
/* Initialize a device. Device properties should be set before calling
|
||||||
this function. IRQs and MMIO regions should be connected/mapped after
|
this function. IRQs and MMIO regions should be connected/mapped after
|
||||||
calling this function. */
|
calling this function.
|
||||||
|
On failure, destroy the device and return negative value.
|
||||||
|
Return 0 on success. */
|
||||||
int qdev_init(DeviceState *dev)
|
int qdev_init(DeviceState *dev)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
assert(dev->state == DEV_STATE_CREATED);
|
assert(dev->state == DEV_STATE_CREATED);
|
||||||
rc = dev->info->init(dev, dev->info);
|
rc = dev->info->init(dev, dev->info);
|
||||||
if (rc < 0)
|
if (rc < 0) {
|
||||||
|
qdev_free(dev);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
qemu_register_reset(qdev_reset, dev);
|
qemu_register_reset(qdev_reset, dev);
|
||||||
if (dev->info->vmsd)
|
if (dev->info->vmsd)
|
||||||
vmstate_register(-1, dev->info->vmsd, dev);
|
vmstate_register(-1, dev->info->vmsd, dev);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue