[PATCH v5 05/10] hw/audio/virtio-sound: free all stream buffers on reset

Alexander Mikhalitsyn <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
From: Volker Rümelin <[email protected]>

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 <[email protected]>
[AM: trivial variable rename s -> vsnd]
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Manos Pitsidianakis <[email protected]>
---
v4:
	- reduced a scope of loop counter variable in virtio_snd_reset
	  (as suggested by Manos Pitsidianakis)
---
 hw/audio/virtio-snd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 84083be8825..f9822fc609a 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -1364,6 +1364,16 @@ static void virtio_snd_reset(VirtIODevice *vdev)
         QTAILQ_REMOVE(&vsnd->cmdq, cmd, next);
         virtio_snd_ctrl_cmd_free(cmd);
     }
+
+    for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
+        VirtIOSoundPCMStream *stream = &vsnd->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, const void *data)
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.