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=1796221009; b=wuVzhQej1ir+fpr7YI++0SfL3gSKcaB6E4nKotIFSkkAzMhJPR7SmDhupTMEaP2hh6K/ tJjJCwRpzaIS0Zje7FYLNVZvA7EUm/GaNaIrVRl3TLJUVhqaUmjA+ojRYSAFCYgla4Vfq 8Pz/D0Q99AU+ab2XQBYzM2OY9AmxYPD6xld9XknvZBaYYscczasHQPIMB1h7k8BhscydR T0B4m8drSFt5FbqIOe6+So9AbswdHl1XG9zF3vRqvLcmPWwAO3nrNS6FDYOsWBcrqVAee 7GVgRlrOrWQ10KtBwX5PbWX7lhS/1Mvx/hKwgeiqSu5+4Uv/PTqNXMHxHKd48pmdG0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221009; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jIhUaNoRw3A4wfi8jH05EQFbYx39BCLDBF7dDB3ALoU=; b=bvd9BpIpKSVUBkxaq4gAhezUI18prrU3E5RQE5lJc6oOdqX2w4ozWgoxlv3Olvt7ZzrO IHajzfRsH4ceY7F1HL4Rf07LI2YHuYemGEFZjATBy0kHPVE1kIyQiA3wS8w1X+oDQ3ivH 6gA7T3H3jUm5NVwoNvp3HxAJfFlgOWLoBo41aTvgUGq39+j6lRkLnRLajMVE5m2k5DoU4 GB7rOrD2kStwN3DQiUcAGa1Ci1QFfg9+HsrMlO9bTqO2q6oaQD0X4ZYBrtuAK9Sl8mjwE rxrorbsLSYUCD0Tv4P3rOqJkfmeCbzYvGzrpJWASpNVzKz88fvZ4DuXQII9GOjF1+9w== 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=J5lXBr8E; 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 2E8C7606A31A for ; Wed, 2 Dec 2026 14:16:49 +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=J5lXBr8E Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9FB91F00A1D; Wed, 2 Dec 2026 14:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796221008; bh=jIhUaNoRw3A4wfi8jH05EQFbYx39BCLDBF7dDB3ALoU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=J5lXBr8EE9HdzKVvKuiw4x+r2dzDusRDWmOU2vg3voDUUaHxP/whE3nXHn/HeNzPS yH1+ZoEwc3JhU3VHtSPz3ja66woZrkAzagFoDDCKMnKGsIHhJ4QdHwmhfOv2FRzYG0 XfddJxqiUy0rsd4yyOxDABlfN4bOcqBlD+Agt8e7xGuJEZxi5ZKjBTMvrMu0xsMCu4 JdR+xZbyyU+CZmQTSIBBTHz5ylc9VxgvuHaNyhJZ1n+aOF1oYABmADEcm6R+mS+x1n z5q+MXOKdLj5gDHNoEa6cP8VPXpsH3vhpX1ENxvw2o6/yiQXfxgQVJmfDFIEa/T6bC tfvFNGd9RVZcg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/3] ALSA: pcm: Check mmap_count before freeing buffer in error path Reply-To: sashiko-reviews@lists.linux.dev To: "Ahmed Abdelmoemen" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202140117.1164633-3-ahmedabdelmoumen05@gmail.com> References: <20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com> <20261202140117.1164633-3-ahmedabdelmoumen05@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 14:16:48 +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: - [Medium] ALSA: pcm: DMA buffer leak and incomplete mmap guard in snd_pcm_hw_params() -- commit 5fc3b38b4810c777d9255a21426c3dfa8b6fc8a1 Author: Ahmed Abdelmoemen ALSA: pcm: Check mmap_count before freeing buffer in error path This commit checks substream->mmap_count before calling snd_pcm_lib_free_pages() in the error path of snd_pcm_hw_params(). > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index d77045aba17b6..f8d9d145bc352 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c > @@ -900,7 +900,8 @@ static int snd_pcm_hw_params(struct snd_pcm_substream= *substream, > snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); > if (substream->ops->hw_free !=3D NULL) > substream->ops->hw_free(substream); > - if (substream->managed_buffer_alloc) > + if (substream->managed_buffer_alloc && > + !atomic_read(&substream->mmap_count)) > snd_pcm_lib_free_pages(substream); > } [Severity: Medium] Does skipping snd_pcm_lib_free_pages() here leak runtime->dma_buffer_p and its backing DMA pages? The error path resets runtime->state to SNDRV_PCM_STATE_OPEN before checking mmap_count, and snd_pcm_release_substream() only calls do_hw_free() when the state is not SNDRV_PCM_STATE_OPEN: sound/core/pcm_native.c:snd_pcm_release_substream() { ... if (substream->runtime->state !=3D SNDRV_PCM_STATE_OPEN) do_hw_free(substream); ... } When the substream is later closed without another successful snd_pcm_hw_params() call, do_hw_free() is skipped and snd_pcm_detach_substream() frees runtime without releasing the dynamically allocated buffer. Also, if snd_pcm_hw_params() is ever entered with mmap_count > 0, guarding only the error path does not prevent snd_pcm_lib_malloc_pages() from freeing an existing smaller mapped buffer before reallocating, or prevent substream->ops->hw_free() from running in _error. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202140117.1164= 633-1-ahmedabdelmoumen05@gmail.com?part=3D2