Skip to contentSkip to conversation

infinite loop in src/pcm/pcm_params.c function snd_pcm_sw_params_default()

DISCUSSION [email protected] 2 participants 2 messages Feb 25, 2023

lore
Share & tools
lore
#0 lore raw

I found this infinite loop while playing with the test/latency.c function. When I specify too small of a minimum latency (in my case -m 256 or smaller) it winds up:

at line line 2337:

	params->boundary = pcm->buffer_size;
	while (params->boundary * 2 <= LONG_MAX - pcm->buffer_size)
		params->boundary *= 2;
	return 0;

but when pcm->buffer_size is zero this is an infinite loop. It does this *after* setting the scheduling to round-robin which makes the infinite loop so much more painful.

The return value from this function is ignored where it's called so I'm not sure what the best fix is. I'm guessing it's a rare case since it's not been previously reported but it deserves fixing anyway.

#1 lore raw
Quoted 9 lines · On 25. 02. 23 17:44, [email protected] wrote:

I found this infinite loop while playing with the test/latency.c function. When I specify too small of a minimum latency (in my case -m 256 or smaller) it winds up:

at line line 2337:

	params->boundary = pcm->buffer_size;
	while (params->boundary * 2 <= LONG_MAX - pcm->buffer_size)
		params->boundary *= 2;
	return 0;

but when pcm->buffer_size is zero this is an infinite loop. It does this *after* setting the scheduling to round-robin which makes the infinite loop so much more painful.

The buffer_size should not be zero after pcm->ops->hw_params() call - an error should be returned there, so something bad is in the driver or used plugin in the chain.

Which driver do you test? Or do you have a special alsa-lib configuration?

The loop fix in alsa-lib: https://github.com/alsa-project/alsa-lib/commit/a8afb0449c6a898180982369f543b50393bb90b6 . But as I noted, it's not a fix for the broken code.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.