From: Stian Halseth <stian@itx.no>
To: Takashi Iwai <tiwai@suse.com>
Cc: Jaroslav Kysela <perex@perex.cz>,
linux-sound@vger.kernel.org, sparclinux@vger.kernel.org,
linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>,
stable@vger.kernel.org
Subject: [PATCH] ALSA: sparc: cs4231: Require an integer number of periods
Date: Tue, 1 Dec 2026 22:15:14 +0100 [thread overview]
Message-ID: <20261201211514.1063429-1-stian@itx.no> (raw)
The DMA engine is fed one period at a time. snd_cs4231_advance_dma()
wraps after runtime->periods periods. Nothing requires the buffer to
be a whole number of periods. When it is not, the DMA ring ends before
the buffer does. The frames in the tail are never played. On capture,
the tail is never filled.
Any application that sets its own buffer and period sizes can hit
this. Buffer and period times can also round to such sizes. A minimal
case:
aplay -D hw:0 -t raw -f S16_BE -c 2 -r 48000 \
--buffer-size=8192 --period-size=2016 /dev/zero
The DMA wraps after 8064 frames, but ALSA counts each wrap as a full
pass of 8192 frames. On a Sun Ultra 5, hw_ptr in the substream's proc
status advances 48781 frames/s, against 48020 with 2048-frame periods.
With music the skipped frames are heard as distortion. This was found
with Audacious, which picks such sizes by default on this card.
Add the integer periods constraint, as other drivers that program DMA
per period do.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://github.com/sparclinux/issues/issues/134
Cc: stable@vger.kernel.org
Signed-off-by: Stian Halseth <stian@itx.no>
---
sound/sparc/cs4231.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 0489eac16..a2b414318 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -1094,6 +1094,10 @@ static int snd_cs4231_playback_open(struct snd_pcm_substream *substream)
runtime->hw = snd_cs4231_playback;
+ err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0)
+ return err;
+
err = snd_cs4231_open(chip, CS4231_MODE_PLAY);
if (err < 0)
return err;
@@ -1113,6 +1117,10 @@ static int snd_cs4231_capture_open(struct snd_pcm_substream *substream)
runtime->hw = snd_cs4231_capture;
+ err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0)
+ return err;
+
err = snd_cs4231_open(chip, CS4231_MODE_RECORD);
if (err < 0)
return err;
--
2.43.0
next reply other threads:[~2026-12-01 21:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 21:15 Stian Halseth [this message]
2026-12-02 8:32 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201211514.1063429-1-stian@itx.no \
--to=stian@itx.no \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=sparclinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®