summary refs log tree commit diff stats
path: root/hw/pci.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2010-05-17 12:41:39 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2010-05-17 12:41:39 -0500
commitf7ce72878c05dacc5f52374b69e61d00556a185b (patch)
treee4cd437d7a3a4f1908bcfa750303c0a3818065c5 /hw/pci.c
parent21ffd18163d9ff8e965f91dd96433f37fa99f204 (diff)
parent57c3229ba1c5cecae277301b8b16577fbf2de98b (diff)
downloadfocaccia-qemu-f7ce72878c05dacc5f52374b69e61d00556a185b.tar.gz
focaccia-qemu-f7ce72878c05dacc5f52374b69e61d00556a185b.zip
Merge remote branch 'mst/for_anthony' into staging
Diffstat (limited to 'hw/pci.c')
-rw-r--r--hw/pci.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 679f06737f..8d84651f19 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -324,7 +324,7 @@ static VMStateInfo vmstate_info_pci_config = {
 
 static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size)
 {
-    PCIDevice *s = container_of(pv, PCIDevice, config);
+    PCIDevice *s = container_of(pv, PCIDevice, irq_state);
     uint32_t irq_state[PCI_NUM_PINS];
     int i;
     for (i = 0; i < PCI_NUM_PINS; ++i) {
@@ -346,7 +346,7 @@ static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size)
 static void put_pci_irq_state(QEMUFile *f, void *pv, size_t size)
 {
     int i;
-    PCIDevice *s = container_of(pv, PCIDevice, config);
+    PCIDevice *s = container_of(pv, PCIDevice, irq_state);
 
     for (i = 0; i < PCI_NUM_PINS; ++i) {
         qemu_put_be32(f, pci_irq_state(s, i));
@@ -627,6 +627,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     return pci_dev;
 }
 
+static void do_pci_unregister_device(PCIDevice *pci_dev)
+{
+    qemu_free_irqs(pci_dev->irq);
+    pci_dev->bus->devices[pci_dev->devfn] = NULL;
+    pci_config_free(pci_dev);
+}
+
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
                                int instance_size, int devfn,
                                PCIConfigReadFunc *config_read,
@@ -682,10 +689,7 @@ static int pci_unregister_device(DeviceState *dev)
         return ret;
 
     pci_unregister_io_regions(pci_dev);
-
-    qemu_free_irqs(pci_dev->irq);
-    pci_dev->bus->devices[pci_dev->devfn] = NULL;
-    pci_config_free(pci_dev);
+    do_pci_unregister_device(pci_dev);
     return 0;
 }
 
@@ -1654,8 +1658,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     if (pci_dev == NULL)
         return -1;
     rc = info->init(pci_dev);
-    if (rc != 0)
+    if (rc != 0) {
+        do_pci_unregister_device(pci_dev);
         return rc;
+    }
 
     /* rom loading */
     if (pci_dev->romfile == NULL && info->romfile != NULL)