From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.189.121.228 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796159752; b=eG/GHU8N/6VDYlyKK9yjDSymWYkMD/88YF2bfY7RWlS763IgTGKSVdgwqVIJAX5oWHpT MmzLCZAW3r1kVz6uqtHnGtP+hxG+QDnP2rc9TBpIT31R0qpCllZLO2cj6RFXHijl7Q4XL BtXdZM7Y8487JxWIJD5vnPri3VZCk0OynjwIg9XVWM32GKjgs6Q4WX4rT9O3o14MTC/zk iyqF4nn/pbq+vEApZW92D5PpglnIBSFCQm8cTplRlVsOkBiT95bO4gqM7FaD45JydleqF LY/a7YhDdj+nPeNNHkG9VeNfs47VRITz+UVX3e+uNK17X3tItMocvqc7BCi34gFHorQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796159752; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Transfer-Encoding; bh=hHUhpJq1N5HCZ1W0pJqaUh43KzaE/moVU1I7F4K4KuE=; b=gpzS+cHuCEGqepCh69/eWQvFqm8Ix4mwG9Uc1JlQKgUZqvXQieaNWsnHe93KEyVmtWUb /v0lKH/wWQEgIKTy05qHRKioRCzwFTRMEVVqUyNDj6It500xaZdNBNEgnRE5ri+8THBYm +xOjjvQ3VwjuU6vapmD99x4vRcuOOxN96nAJiJD3aE3vYJVEmxT/+RZi1sBnxhki6Ym6h 9xfN7mxcAnyHcMZ0ACzDRi2JLqly5JdVJAX5WeNjm7YlOM3lLT6tBxpqqU9FpbjHPB9rS PtN/x6ZWZSi8XlVLV0tDjt7u1kF2n8Zpy6jBbUGyEK5z5/zI+ph2is0BW9PXJWvHZnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=itx.no; spf=pass smtp.mailfrom=itx.no; dkim=pass header.d=itx.no header.i=@itx.no header.a=rsa-sha256 header.s=mx.itx.no header.b=hLLYLdeG; arc=none smtp.remote-ip=91.189.121.228 Received: from mx.itxnorge.no (itx-kvm-14.itxnorge.no [91.189.121.228]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4E3E606A320; Tue, 1 Dec 2026 21:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4E3E606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=itx.no Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=itx.no Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=itx.no header.i=@itx.no header.a=rsa-sha256 header.s=mx.itx.no header.b=hLLYLdeG From: Stian Halseth DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itx.no; s=mx.itx.no; t=1796159744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hHUhpJq1N5HCZ1W0pJqaUh43KzaE/moVU1I7F4K4KuE=; b=hLLYLdeGo2l9z9vp9E6Q0QMvLkpWaN6Sdeo4Ul11ERLUrVhD7/I3SS+MlGfkLAcuJwu6V2 fP4BftA4dJ6HEH6OZOOTHB/OY/dNZrVhFxEjjP+ogpZ+jp1zNve4Wy7t6BORHET5YTzt+S ZAqqp+R3LGC7wNMLsVi9IWuypxtLdCY= To: Takashi Iwai Cc: Jaroslav Kysela , linux-sound@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, Stian Halseth , stable@vger.kernel.org Subject: [PATCH] ALSA: sparc: cs4231: Require an integer number of periods Date: Tue, 1 Dec 2026 22:15:14 +0100 Message-ID: <20261201211514.1063429-1-stian@itx.no> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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