Patchwork [v2,2/3] pci: option rom clean up.

login
register
mail settings
Submitter Isaku Yamahata
Date June 22, 2010, 2:55 a.m.
Message ID <cc4d1d989fcacaae56cdd820e6b1830bbda87052.1277174072.git.yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/56391/
State New
Headers show

Comments

Isaku Yamahata - June 22, 2010, 2:55 a.m.
When pci deivce is freed, the option rom isn't freed.
Although qemu_ram_free() is nop right now in fact, pci layer should
be prepared for it.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 7e5c539..75acbd3 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -74,6 +74,7 @@  static struct BusInfo pci_bus_info = {
 static void pci_update_mappings(PCIDevice *d);
 static void pci_set_irq(void *opaque, int irq_num, int level);
 static int pci_add_option_rom(PCIDevice *pdev);
+static void pci_del_option_rom(PCIDevice *pdev);
 
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
 static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
@@ -708,6 +709,7 @@  static int pci_unregister_device(DeviceState *dev)
         return ret;
 
     pci_unregister_io_regions(pci_dev);
+    pci_del_option_rom(pci_dev);
     do_pci_unregister_device(pci_dev);
     return 0;
 }
@@ -1759,6 +1761,14 @@  static int pci_add_option_rom(PCIDevice *pdev)
     return 0;
 }
 
+static void pci_del_option_rom(PCIDevice *pdev)
+{
+    if (pdev->rom_offset) {
+        qemu_ram_free(pdev->rom_offset);
+        pdev->rom_offset = 0;
+    }
+}
+
 /* Reserve space and add capability to the linked list in pci config space */
 int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id,
                                  uint8_t offset, uint8_t size)