Skip to contentSkip to conversation

hw/audio/lm4549: Don't try to open a zero-frequency audio voice

PATCH In review Peter Maydell 3 participants 5 messages Nov 7, 2025 – Nov 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/audio/lm4549: Don't try to open a zero-frequency audio voice

If the guest incorrectly programs the lm4549 audio chip with a zero frequency, we will pass this to AUD_open_out(), which will complain:

A bug was just triggered in AUD_open_out
Save all your work and restart without audio
I am sorry
Context:
audio: frequency=0 nchannels=2 fmt=S16 endianness=little

The datasheet doesn't say what we should do here, only that the valid range for the freqency is 8000 to 48000 Hz; we choose to log the guest error and ignore an attempt to change the DAC rate to something outside the valid range.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/410

---
This bug has been around for so long and is a weird edge case whose only effect is to print a debug message, so it doesn't really seem worth cc'ing stable on.

---
 hw/audio/lm4549.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
hw/audio/lm4549.c +16 -1
index 745441bd790..bf711c49c04 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/hw.h"
+#include "qemu/log.h"
 #include "qemu/audio.h"
 #include "lm4549.h"
 #include "migration/vmstate.h"
@@ -179,9 +180,23 @@ void lm4549_write(lm4549_state *s,
         break;
 
     case LM4549_PCM_Front_DAC_Rate:
-        regfile[LM4549_PCM_Front_DAC_Rate] = value;
         DPRINTF("DAC rate change = %i\n", value);
 
+        /*
+         * Valid sample rates are 4kHz to 48kHz.
+         * The datasheet doesn't say what happens if you try to
+         * set the frequency to zero. AUD_open_out() will print
+         * a bug message if we pass it a zero frequency, so just
+         * ignore attempts to set the DAC frequency to zero.
+         */
+        if (value < 4000 || value > 48000) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: DAC sample rate %d Hz is invalid, ignoring it\n",
+                          __func__, value);
+            break;
+        }
+        regfile[LM4549_PCM_Front_DAC_Rate] = value;
+
         /* Re-open a voice with the new sample rate */
         struct audsettings as;
         as.freq = value;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 37 lines · Peter Maydell

If the guest incorrectly programs the lm4549 audio chip with a zero frequency, we will pass this to AUD_open_out(), which will complain:

A bug was just triggered in AUD_open_out
Save all your work and restart without audio
I am sorry
Context:
audio: frequency=0 nchannels=2 fmt=S16 endianness=little

The datasheet doesn't say what we should do here, only that the valid range for the freqency is 8000 to 48000 Hz; we choose to log the guest error and ignore an attempt to change the DAC rate to something outside the valid range.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/410

---
This bug has been around for so long and is a weird edge case whose only effect is to print a debug message, so it doesn't really seem worth cc'ing stable on.
---
hw/audio/lm4549.c | 17 ++++++++++++++++-

1 file changed, 16 insertions(+), 1 deletion(-)
hw/audio/lm4549.c +1 -0
index 745441bd790..bf711c49c04 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/hw.h"
+#include "qemu/log.h"
 #include "qemu/audio.h"
 #include "lm4549.h"
 #include "migration/vmstate.h"

hw/audio/lm4549.c void lm4549_write(lm4549_state *s, · line 186

Quoted 8 lines
hw/audio/lm4549.c +2 -1
@@ -179,9 +180,23 @@ void lm4549_write(lm4549_state *s,
        break;
 
    case LM4549_PCM_Front_DAC_Rate:
-        regfile[LM4549_PCM_Front_DAC_Rate] = value;
        DPRINTF("DAC rate change = %i\n", value);
 
+        /*
+         * Valid sample rates are 4kHz to 48kHz.

Commit message says minimum is 8kHz. One of these is likely incorrect. Maybe a typo in commit message?

Regards,
BALATON Zoltan

Quoted 17 lines
hw/audio/lm4549.c +13 -0
+         * The datasheet doesn't say what happens if you try to
+         * set the frequency to zero. AUD_open_out() will print
+         * a bug message if we pass it a zero frequency, so just
+         * ignore attempts to set the DAC frequency to zero.
+         */
+        if (value < 4000 || value > 48000) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "%s: DAC sample rate %d Hz is invalid, ignoring it\n",
+                          __func__, value);
+            break;
+        }
+        regfile[LM4549_PCM_Front_DAC_Rate] = value;
+
        /* Re-open a voice with the new sample rate */
        struct audsettings as;
        as.freq = value;
#2 lore raw
Quoted 45 lines · BALATON Zoltan
Quoted 43 lines · Peter Maydell

If the guest incorrectly programs the lm4549 audio chip with a zero frequency, we will pass this to AUD_open_out(), which will complain:

A bug was just triggered in AUD_open_out
Save all your work and restart without audio
I am sorry
Context:
audio: frequency=0 nchannels=2 fmt=S16 endianness=little

The datasheet doesn't say what we should do here, only that the valid range for the freqency is 8000 to 48000 Hz; we choose to log the guest error and ignore an attempt to change the DAC rate to something outside the valid range.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/410

---
This bug has been around for so long and is a weird edge case whose only effect is to print a debug message, so it doesn't really seem worth cc'ing stable on.
---
hw/audio/lm4549.c | 17 ++++++++++++++++-

1 file changed, 16 insertions(+), 1 deletion(-)
hw/audio/lm4549.c +1 -1
index 745441bd790..bf711c49c04 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/hw.h"
+#include "qemu/log.h"
 #include "qemu/audio.h"
 #include "lm4549.h"
 #include "migration/vmstate.h"
@@ -179,9 +180,23 @@ void lm4549_write(lm4549_state *s,
        break;
 
    case LM4549_PCM_Front_DAC_Rate:
-        regfile[LM4549_PCM_Front_DAC_Rate] = value;
        DPRINTF("DAC rate change = %i\n", value);
 
Quoted 5 lines

hw/audio/lm4549.c void lm4549_write(lm4549_state *s, · line 186

Quoted 2 lines
hw/audio/lm4549.c +2 -0
+        /*
+         * Valid sample rates are 4kHz to 48kHz.

Commit message says minimum is 8kHz. One of these is likely incorrect. Maybe a typo in commit message?

Whoops; yes, you're right, the commit message is the one that's wrong. The datasheet for this is at
https://www.ti.com/lit/ds/symlink/lm4549b.pdf
and it says 4kHz.

-- PMM

Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

If the guest incorrectly programs the lm4549 audio chip with a zero frequency, we will pass this to AUD_open_out(), which will complain:

A bug was just triggered in AUD_open_out
Save all your work and restart without audio
I am sorry
Context:
audio: frequency=0 nchannels=2 fmt=S16 endianness=little

The datasheet doesn't say what we should do here, only that the valid range for the freqency is 8000 to 48000 Hz; we choose to log the guest error and ignore an attempt to change the DAC rate to something outside the valid range.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/410

Quoted 8 lines

---
This bug has been around for so long and is a weird edge case whose only effect is to print a debug message, so it doesn't really seem worth cc'ing stable on.

---
  hw/audio/lm4549.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)

With s/8000/4000/ in description:

author Applied
#4 lore raw
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Peter Maydell

If the guest incorrectly programs the lm4549 audio chip with a zero frequency, we will pass this to AUD_open_out(), which will complain:

A bug was just triggered in AUD_open_out
Save all your work and restart without audio
I am sorry
Context:
audio: frequency=0 nchannels=2 fmt=S16 endianness=little

The datasheet doesn't say what we should do here, only that the valid range for the freqency is 8000 to 48000 Hz; we choose to log the guest error and ignore an attempt to change the DAC rate to something outside the valid range.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/410

Quoted 8 lines

---
This bug has been around for so long and is a weird edge case whose only effect is to print a debug message, so it doesn't really seem worth cc'ing stable on.

---
  hw/audio/lm4549.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
Quoted 2 lines

With s/8000/4000/ in description:

Applied to target-arm.next with that commit message fix, thanks.

-- PMM