diff mbox

[v2] audio: ac97: add exit function

Message ID 5850b689.68219d0a.9be2d.9b07@mx.google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Li Qiang Dec. 14, 2016, 3:03 a.m. UTC
From: Li Qiang <liqiang6-s@360.cn>

Currently the ac97 device emulation doesn't have a exit function,
hot unplug this device will leak some memory. Add a exit function to
avoid this.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---

Changes since the v1:
close the streams

 hw/audio/ac97.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox

Patch

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index cbd959e..efa20b5 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1387,6 +1387,23 @@  static void ac97_realize(PCIDevice *dev, Error **errp)
     ac97_on_reset (&s->dev.qdev);
 }
 
+static void ac97_exit(PCIDevice *dev)
+{
+    AC97LinkState *s = DO_UPCAST(AC97LinkState, dev, dev);
+
+    if (s->voice_pi) {
+        AUD_close_in (&s->card, s->voice_pi);
+    }
+    if (s->voice_po) {
+        AUD_close_out (&s->card, s->voice_po);
+    }
+    if (s->voice_mc) {
+        AUD_close_in (&s->card, s->voice_mc);
+    }
+
+    AUD_remove_card (&s->card);
+}
+
 static int ac97_init (PCIBus *bus)
 {
     pci_create_simple (bus, -1, "AC97");
@@ -1404,6 +1421,7 @@  static void ac97_class_init (ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS (klass);
 
     k->realize = ac97_realize;
+    k->exit = ac97_exit;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
     k->revision = 0x01;