Re: [PATCH] ALSA: pcm: oss: Refine slave hw_params after setting format

From: Takashi Iwai

Date: Thu Nov 26 2026 - 05:13:44 EST


On Wed, 25 Nov 2026 19:10:05 +0100,
Hengyu Liang wrote:
>
> 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@xxxxxxxxxxxxxxx>
> Signed-off-by: Hengyu Liang <hengyul@xxxxxxxxxx>

Applied now. Thanks.


Takashi