diff mbox series

hw/audio/hda: avoid unnecessary re-open stream on reconfiguration

Message ID 20241105083203.2230983-1-marcandre.lureau@redhat.com (mailing list archive)
State New
Headers show
Series hw/audio/hda: avoid unnecessary re-open stream on reconfiguration | expand

Commit Message

Marc-André Lureau Nov. 5, 2024, 8:32 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Closing and opening a stream too quickly during reconfiguration create
issues with Spice.

Note: the issue with Spice has been there before and still is. When the
audio stream is recreated, for example when using
`out.mixing-engine=false`.

Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2639
Fixes: 6d6e23361f ("hw/audio/hda: fix memory leak on audio setup")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/audio/hda-codec.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index bc661504cf..b734a5c718 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -502,7 +502,15 @@  static void hda_audio_setup(HDAAudioStream *st)
     trace_hda_audio_format(st->node->name, st->as.nchannels,
                            fmt2name[st->as.fmt], st->as.freq);
 
-    hda_close_stream(st->state, st);
+    /*
+     * Do not hda_close_stream(st->state, st), AUD_open_() handles the logic for
+     * fixed_settings, and same format. This helps prevent race issues in Spice
+     * server & client code too. (see #2639)
+     */
+    if (use_timer) {
+        timer_free(st->buft);
+        st->buft = NULL;
+    }
     if (st->output) {
         if (use_timer) {
             cb = hda_audio_output_cb;