]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sound: avoid endless loop
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 4 Dec 2022 13:00:05 +0000 (14:00 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 5 Dec 2022 16:43:21 +0000 (17:43 +0100)
'sound play 1 100000' results in an endless loop on the sandbox.

If the frequency exceeds half the sampling rate, zero out the output
buffer.

Fixes: 511ed5fdd389 ("SOUND: SAMSUNG: Add I2S driver")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/sound/sound.c

index 041dfdccfebb3315ca04898b2aa056bf32540234..c0fc50c99dac5e6c7ec051a9b762415a0d3c6670 100644 (file)
@@ -15,7 +15,10 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
        const int period = freq ? sample_rate / freq : 0;
        const int half = period / 2;
 
-       assert(freq);
+       if (!half) {
+               memset(data, 0, size);
+               return;
+       }
 
        /* Make sure we don't overflow our buffer */
        if (size % 2)