All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Takashi Iwai" <tiwai@suse.de>, linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 1/4] ALSA: pcm: Avoid forcibly changing to OPEN state at hw_params errors
Date: Thu, 03 Dec 2026 09:09:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-247430@kernel.org> (raw)
In-Reply-To: <20261203084041.914026-2-tiwai@suse.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ALSA: pcm: keeping SETUP state on mmapped hw_params() error
  breaks prepare()
--

commit 2f6fa4226b678a6d8b5f71debbc0c801c44f35a7
Author: Takashi Iwai <tiwai@suse.de>

ALSA: pcm: Avoid forcibly changing to OPEN state at hw_params errors

This commit skips transitioning the stream to SNDRV_PCM_STATE_OPEN, calling
hw_free, and freeing pages on snd_pcm_hw_params() errors when
substream->mmap_count is non-zero.

Link: https://lore.kernel.org/20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com

> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 897975e43a9bd..6d17be7f9beb8 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -893,7 +893,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
>  
>  	err = 0;
>   _error:
> -	if (err) {
> +	if (err && !atomic_read(&substream->mmap_count)) {
>  		/* hardware might be unusable from this time,
>  		 * so we force application to retry to set
>  		 * the correct hardware parameter settings

[Severity: High]
Can skipping the transition to SNDRV_PCM_STATE_OPEN here allow
ops->prepare() to run on hardware state torn down by a failed
ops->hw_params()?

On a mapped OSS stream, snd_pcm_oss_make_ready() checks runtime->oss.params
and runtime->oss.prepare without holding runtime->oss.params_lock, then
acquires the lock and calls snd_pcm_oss_prepare() without rechecking
runtime->oss.params:

CPU0                              CPU1
snd_pcm_oss_post()
  snd_pcm_oss_make_ready()
    check oss.params (0)
    check oss.prepare (1)
                                  snd_pcm_oss_set_rate()
                                    snd_pcm_oss_change_params_locked()
                                      snd_pcm_hw_params()
                                        ops->hw_params() fails
                                        (state stays SETUP)
    lock(&oss.params_lock)
    snd_pcm_oss_prepare()
      ops->prepare()              <-- runs on torn-down hardware

Previously, snd_pcm_hw_params() moved the stream to SNDRV_PCM_STATE_OPEN on
error, so snd_pcm_pre_prepare() rejected the call with -EBADFD.  With the
stream left in SNDRV_PCM_STATE_SETUP, snd_pcm_pre_prepare() succeeds and
invokes ops->prepare() after the driver already released its resources.

For example, when snd_emu10k1_playback_hw_params() fails in
snd_emu10k1_pcm_channel_alloc() after freeing voices, the subsequent
snd_emu10k1_playback_prepare() dereferences NULL epcm->voices[0] in
snd_emu10k1_pcm_init_voice().

Should snd_pcm_oss_make_ready() check runtime->oss.params under
runtime->oss.params_lock and the PCM core still prevent ops->prepare() after
a failed ops->hw_params() when mmap_count is non-zero?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203084041.914026-1-tiwai@suse.de?part=1

  reply	other threads:[~2026-12-03  9:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  8:40 [PATCH v2 0/4] ALSA: pcm: Workarounds for OSS mmap issues Takashi Iwai
2026-12-03  8:40 ` [PATCH v2 1/4] ALSA: pcm: Avoid forcibly changing to OPEN state at hw_params errors Takashi Iwai
2026-12-03  9:09   ` sashiko-bot [this message]
2026-12-03 10:44     ` Takashi Iwai
2026-12-03  8:40 ` [PATCH v2 2/4] ALSA: pcm: Reject hw_params with buffer size changes while mmapped Takashi Iwai
2026-12-03  9:23   ` sashiko-bot
2026-12-03  8:40 ` [PATCH v2 3/4] ALSA: pcm: Prohibit buffer (re-)allocation/free during mmap Takashi Iwai
2026-12-03  9:10   ` sashiko-bot
2026-12-03  8:40 ` [PATCH v2 4/4] ALSA: pcm: Don't reallocate for the same sized buffers Takashi Iwai
2026-12-03  9:09   ` sashiko-bot
2026-12-03 10:47     ` 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=sashiko-outbox-247430@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.