* [PATCH] ALSA: pcm: oss: Refine slave hw_params after setting format
@ 2026-11-25 18:10 Hengyu Liang
0 siblings, 0 replies; only message in thread
From: Hengyu Liang @ 2026-11-25 18:10 UTC (permalink / raw)
To: Takashi Iwai, Jaroslav Kysela
Cc: Pavel Hofman, linux-sound, linux-kernel, stable
Commit 93d7d38fa61d ("ALSA: aloop: add DSD formats") added DSD_U8 to
the formats of snd-aloop. Before that, its narrowest format had 16 bits.
However, snd_pcm_oss_change_params_locked() sets the slave format with
_snd_pcm_hw_param_set(), which does not refine the parameters, while
the access, rate and channels before it are set with refining helpers.
snd_pcm_oss_period_size() then reads a buffer size maximum that is
still computed for the narrowest format, now DSD_U8, so the OSS period
doubles. With the default U8 client format, the doubled period no
longer fits in the format plugin, and snd_pcm_plugin_alloc() returns
-ENOMEM. As of now, an OSS program that asks snd-aloop for 8 channels
at 192 kHz gets ENOMEM from SNDCTL_DSP_SPEED and from every later
ioctl on the same file.
The issue can be reproduced with this program, where card 1 is
snd-aloop:
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
int main(void)
{
int fd = open("/dev/dsp1", O_WRONLY | O_NONBLOCK);
int ch = 8, rate = 192000, blk = 0;
ioctl(fd, SNDCTL_DSP_CHANNELS, &ch);
if (ioctl(fd, SNDCTL_DSP_SPEED, &rate) < 0)
perror("SNDCTL_DSP_SPEED");
if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blk) < 0)
perror("SNDCTL_DSP_GETBLKSIZE");
printf("block size %d\n", blk);
return 0;
}
Before that commit, it prints "block size 65536". After that commit,
the result is:
SNDCTL_DSP_SPEED: Cannot allocate memory
SNDCTL_DSP_GETBLKSIZE: Cannot allocate memory
block size 0
This patch will set the format with snd_pcm_hw_param_set(), which
refines the parameters, as is done for the channels just before.
Fixes: 93d7d38fa61d ("ALSA: aloop: add DSD formats")
Cc: <stable@vger.kernel.org>
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
I found this while comparing the behavior of different kernel versions.
I used an LLM to analyze the problem and to draft the patch and this
message, and I analyzed the result myself.
The missing refine is older than that commit, so the patch also halves
the default fragment size on other cards that offer a format narrower
than the one in use. On snd-dummy (U8 and S16_LE) with S16_LE, one
channel at 48 kHz now gets 4096 bytes instead of 8192.
With "ALSA: pcm: oss: Compare max buffer size in bytes" in for-next,
the program above no longer fails, but it prints "block size 131072"
until this patch is applied.
Tested on for-linus (5a6fcabe156e) and for-next (486060b97284) with
KASAN and lockdep. On snd-aloop, a grid of 1 to 128 channels at 8 to
192 kHz gives the same results as before that commit, and SETFRAGMENT,
mmap and a playback and capture pair work as before.
sound/core/oss/pcm_oss.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 66162caa45d4..3c2ac8966d5e 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -921,7 +921,8 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
goto failure;
}
format_found:
- err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, sformat, 0);
+ err = snd_pcm_hw_param_set(substream, sparams,
+ SNDRV_PCM_HW_PARAM_FORMAT, sformat, 0);
if (err < 0)
goto failure;
base-commit: 5a6fcabe156e91c6ef2435a74f2d16e6dd39f7c7
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 18:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 18:10 [PATCH] ALSA: pcm: oss: Refine slave hw_params after setting format Hengyu Liang
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®