Skip to contentSkip to conversation

pcm: rate: fix last_commit_ptr boundary wrapping

PATCH In review Alan Young 2 participants 2 messages Dec 30, 2022

lore
Share & tools
lore

Alan Young

author
#0 lore raw

PATCH 1/1 pcm: rate: fix last_commit_ptr boundary wrapping

Wrap last_commit_ptr using boundary. Was just wrapped to 0, which is correct only if the buffer size, and hence the boundary, is an integer multiple of the period size.

Fixes 467d69c5bc1 ("Fix CPU hog with combination of rate plugin")
Fixes 29041c52207 ("fix infinite draining of the rate plugin in SND_PCM_NONBLOCK mode")
---
 src/pcm/pcm_rate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/pcm/pcm_rate.c +2 -2
index e5d8eddd..c8076859 100644
@@ -1018,7 +1018,7 @@ static int snd_pcm_rate_sync_playback_area(snd_pcm_t *pcm, snd_pcm_uframes_t app
 		slave_size -= rate->gen.slave->period_size;
 		rate->last_commit_ptr += pcm->period_size;
 		if (rate->last_commit_ptr >= pcm->boundary)
-			rate->last_commit_ptr = 0;
+			rate->last_commit_ptr -= pcm->boundary;
 	}
 	return 0;
 }
@@ -1163,7 +1163,7 @@ static int snd_pcm_rate_drain(snd_pcm_t *pcm)
 			if (commit_err == 1) {
 				rate->last_commit_ptr += psize;
 				if (rate->last_commit_ptr >= pcm->boundary)
-					rate->last_commit_ptr = 0;
+					rate->last_commit_ptr -= pcm->boundary;
 			} else if (commit_err == 0) {
 				if (pcm->mode & SND_PCM_NONBLOCK) {
 					commit_err = -EAGAIN;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 7 lines · Alan Young

Wrap last_commit_ptr using boundary. Was just wrapped to 0, which is correct only if the buffer size, and hence the boundary, is an integer multiple of the period size.

Fixes 467d69c5bc1 ("Fix CPU hog with combination of rate plugin")
Fixes 29041c52207 ("fix infinite draining of the rate plugin in SND_PCM_NONBLOCK mode")

Thanks for this fix. Applied to the alsa-lib's repository.

Jaroslav

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