* [PATCH 1/1] sound: avoid endless loop
@ 2022-12-04 13:05 Heinrich Schuchardt
2022-12-04 21:17 ` Simon Glass
0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2022-12-04 13:05 UTC (permalink / raw)
To: Tom Rini
Cc: Simon Glass, u-boot, R . Chandrasekar, Minkyu Kang,
Rajeshwari Shinde, Andrew Scull, Heinrich Schuchardt
'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>
---
drivers/sound/sound.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c
index 041dfdccfe..c0fc50c99d 100644
--- a/drivers/sound/sound.c
+++ b/drivers/sound/sound.c
@@ -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)
--
2.37.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] sound: avoid endless loop
2022-12-04 13:05 [PATCH 1/1] sound: avoid endless loop Heinrich Schuchardt
@ 2022-12-04 21:17 ` Simon Glass
2022-12-04 21:45 ` Heinrich Schuchardt
0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2022-12-04 21:17 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: Tom Rini, u-boot, R . Chandrasekar, Minkyu Kang,
Rajeshwari Shinde, Andrew Scull
On Mon, 5 Dec 2022 at 02:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> '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>
> ---
> drivers/sound/sound.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
(nit below)
>
> diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c
> index 041dfdccfe..c0fc50c99d 100644
> --- a/drivers/sound/sound.c
> +++ b/drivers/sound/sound.c
> @@ -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);
'\0'
> + return;
> + }
>
> /* Make sure we don't overflow our buffer */
> if (size % 2)
> --
> 2.37.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] sound: avoid endless loop
2022-12-04 21:17 ` Simon Glass
@ 2022-12-04 21:45 ` Heinrich Schuchardt
0 siblings, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2022-12-04 21:45 UTC (permalink / raw)
To: Simon Glass
Cc: Tom Rini, u-boot, R . Chandrasekar, Minkyu Kang,
Rajeshwari Shinde, Andrew Scull
On 12/4/22 22:17, Simon Glass wrote:
> On Mon, 5 Dec 2022 at 02:05, Heinrich Schuchardt
> <heinrich.schuchardt@canonical.com> wrote:
>>
>> '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>
>> ---
>> drivers/sound/sound.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> (nit below)
>
>>
>> diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c
>> index 041dfdccfe..c0fc50c99d 100644
>> --- a/drivers/sound/sound.c
>> +++ b/drivers/sound/sound.c
>> @@ -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);
>
> '\0'
Please, have a look at the function definition:
include/malloc.h:366:
void* memset(void*, int, size_t);
Best regards
Heinrich
>
>
>> + return;
>> + }
>>
>> /* Make sure we don't overflow our buffer */
>> if (size % 2)
>> --
>> 2.37.2
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-04 21:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 13:05 [PATCH 1/1] sound: avoid endless loop Heinrich Schuchardt
2022-12-04 21:17 ` Simon Glass
2022-12-04 21:45 ` Heinrich Schuchardt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.