diff mbox series

[v2,05/11] hw/audio/virtio-sound: free all stream buffers on reset

Message ID 20240218083351.8524-5-vr_qemu@t-online.de (mailing list archive)
State New, archived
Headers show
Series virtio-sound migration part 1 | expand

Commit Message

Volker RĂ¼melin Feb. 18, 2024, 8:33 a.m. UTC
All remaining stream buffers in the stream queues must
be freed after a reset. This is the initial state of the
virtio-sound device.

Signed-off-by: Volker RĂ¼melin <vr_qemu@t-online.de>
---
 hw/audio/virtio-snd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index e5497b6bf6..2b630ada82 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -1318,12 +1318,23 @@  static void virtio_snd_reset(VirtIODevice *vdev)
 {
     VirtIOSound *s = VIRTIO_SND(vdev);
     virtio_snd_ctrl_command *cmd;
+    uint32_t i;
 
     while (!QTAILQ_EMPTY(&s->cmdq)) {
         cmd = QTAILQ_FIRST(&s->cmdq);
         QTAILQ_REMOVE(&s->cmdq, cmd, next);
         virtio_snd_ctrl_cmd_free(cmd);
     }
+
+    for (i = 0; i < s->snd_conf.streams; i++) {
+        VirtIOSoundPCMStream *stream = &s->streams[i];
+        VirtIOSoundPCMBuffer *buffer;
+
+        while ((buffer = QSIMPLEQ_FIRST(&stream->queue))) {
+            QSIMPLEQ_REMOVE_HEAD(&stream->queue, entry);
+            virtio_snd_pcm_buffer_free(buffer);
+        }
+    }
 }
 
 static void virtio_snd_class_init(ObjectClass *klass, void *data)