From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288996; b=ajeLcqJ6EOK57oivi5dhhhqPY0hLsXuSi7kqDgTQyYdn/gYChgpztFiE3CLzgE4v/2OJ HfTkuo/kZ12GJfPgfxWRTNSsIGBA1aqd7yVWaxd6VkKAfrQi9aDEVOSp85AsgPrELvjdV ARafVIG3LX3Va2TRGxb+HbXmneN3h1XBnEmGEO8O4eyr/x17Fp+cB2BXBz3IRcGbD5Ycx 1FVsyHwlFl9DC6om4jNdfCIgZQwVSlyr6y8R7uEr5/DRBB039UjTbA94aLt8Ce6XhYTwU lmXH/9MNkTBgzabgunUyW3cKPy9QOxMPl6+vXtVfCx4NQ8x5eO+RGTcrMGaHwZPAaSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288996; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Uam5/3zFh7uvyzkPVluZDBNgSk0500fiP61tEQEZiK0=; b=HhfkZ9gN/MS4RwVyyiN2siKDzr+xC6g9CguT7GTDPH+yJIobYWOAZ48xIL9X/e0+nIc2 pf3ktQb9h5D0CZx03viV2uKwJnlVkKcSLC4c6rJot4qTijxedFWuueT0vE2qM4AJGB1Cg TU+koDIWs1b22g45qwGVPdMbr8fyjyc4FrWdpqLJyfVDheEq9W6UHfcNI7J1O5N/KMWXE 9rHAVMjIIU57bOYUPIDqdIRbXplh3zYQfktLzGAMmc8OwIj6VESIpAeWR1YDdcBti1fPD x9cJ2yhKBha7tH9q5kqtE+HsaosbjwYVIuQhTGFXk1yQOTvYm7VEcgNmHoV9EnzpvUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="la6W/FKu"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69504606A322 for ; Thu, 3 Dec 2026 09:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=la6W/FKu Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE68E1F000C1; Thu, 3 Dec 2026 09:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288996; bh=Uam5/3zFh7uvyzkPVluZDBNgSk0500fiP61tEQEZiK0=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=la6W/FKupxSbxs2EN15G1u9M5fihSF4muhql+muXsCHnbNTBFwdti8bRrvTwIB5Mz kAz48eGMOQa2fQRFRHueNtb3psWSqiByzehi8h99l+iP1BL9L1LdEw0J28t73gt87H 8/NO6IGEcgmHlBEv0c0hWRxdx0Ob2gz3uIoujz2+jTQLHRM894MD1NKUbky8npjzuU +uXtl0G3BF5GGLR4xcYrnwoydx1Hcj5RY5F7Bk2/argvisN/JmCdCNUk7qe70z8hvu 5JZ2HVYOmsTsG/9xRMTKx1nEylB8Byw6ZfYhf5bbbfMBQzn5AvMK+htGvHoi4Rbr4M s3RbOYi2s1QGA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 1/4] ALSA: pcm: Avoid forcibly changing to OPEN state at hw_params errors Reply-To: sashiko-reviews@lists.linux.dev To: "Takashi Iwai" , linux-sound@vger.kernel.org In-Reply-To: <20261203084041.914026-2-tiwai@suse.de> References: <20261203084041.914026-1-tiwai@suse.de> <20261203084041.914026-2-tiwai@suse.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 09:09:55 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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@g= mail.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, > =20 > err =3D 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? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203084041.9140= 26-1-tiwai@suse.de?part=3D1