From: Peter Maydell Date: Fri, 7 Nov 2025 15:41:16 +0000 (+0000) Subject: hw/audio/lm4549: Don't try to open a zero-frequency audio voice X-Git-Tag: v10.2.0-rc1~7^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=522444744eb79dd01e377ad2ed15544f10bcc70c;p=thirdparty%2Fqemu.git 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 4000 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 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20251107154116.1396769-1-peter.maydell@linaro.org --- diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c index 745441bd79..bf711c49c0 100644 --- a/hw/audio/lm4549.c +++ b/hw/audio/lm4549.c @@ -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;