aboutsummaryrefslogtreecommitdiff
path: root/hw/misc
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2016-03-15 19:34:32 +0100
committerMarkus Armbruster <armbru@redhat.com>2016-03-21 21:29:00 +0100
commitd855e2756554583b2b041c9e0a8381bdd202cbc3 (patch)
tree22ba6784d3247766be3bb1fd836fe39476c7f5c8 /hw/misc
parent9cf70c52253ccadc137d40eb0de2c0f25a127334 (diff)
ivshmem: Failed realize() can leave migration blocker behind
If pci_ivshmem_realize() fails after it created its migration blocker, the blocker is left in place. Fix that by creating it last. Likewise, if it fails after it called fifo8_create(), it leaks fifo memory. Fix that the same way. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <1458066895-20632-18-git-send-email-armbru@redhat.com>
Diffstat (limited to 'hw/misc')
-rw-r--r--hw/misc/ivshmem.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 299cf5bda2..51ad255857 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -825,6 +825,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,
static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
{
IVShmemState *s = IVSHMEM(dev);
+ Error *err = NULL;
uint8_t *pci_conf;
uint8_t attr = PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_PREFETCH;
@@ -856,8 +857,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
s->ivshmem_size = size;
}
- fifo8_create(&s->incoming_fifo, sizeof(int64_t));
-
/* IRQFD requires MSI */
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
!ivshmem_has_feature(s, IVSHMEM_MSI)) {
@@ -879,12 +878,6 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
s->role_val = IVSHMEM_MASTER; /* default */
}
- if (s->role_val == IVSHMEM_PEER) {
- error_setg(&s->migration_blocker,
- "Migration is disabled when using feature 'peer mode' in device 'ivshmem'");
- migrate_add_blocker(s->migration_blocker);
- }
-
pci_conf = dev->config;
pci_conf[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
@@ -963,7 +956,19 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
return;
}
- create_shared_memory_BAR(s, fd, attr, errp);
+ create_shared_memory_BAR(s, fd, attr, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+ }
+
+ fifo8_create(&s->incoming_fifo, sizeof(int64_t));
+
+ if (s->role_val == IVSHMEM_PEER) {
+ error_setg(&s->migration_blocker,
+ "Migration is disabled when using feature 'peer mode' in device 'ivshmem'");
+ migrate_add_blocker(s->migration_blocker);
}
}