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=1796386485; b=nWwkOuRvgFf08G5x7FL6BD/FbJzNdpQMO9spx/f33v0veHRappEa94QygqaLYpDqU3KV PN8aSqYKQSuwgKF4NttzI/TSXsUC3l73YKmq96VhoftSwp/D9A3R+IWBEQaXvXMyeOXRZ +1sERDp1wrsRyppeL1JknFBnRnr7B7wxGGPtzswL5iyU6BwehlVRP77JguryGHQm1NHAA DadhDBNSCITf0kMgBMojsGpR65Dyv2RQKIJaPZpSDGRh5rOwh+apS5/oiik/rjb0XopCn Z9RwI0YVSaEzUdSLy7Xtq8QL95NrbypgpUpt3ZCn9UjR6IPp0N+ovSATlt1CoE3qRgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386485; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=moxCfaYldc9npNJv1wGaJ5/cFGNQIPPxxOPFGNLfqx8=; b=i3IeZmjW5aBb6Zw4NkEEyRRubTSGyglkcUQ2XVj2ORSjpDRzHARvLFpuQBHz6YDb8+GU i+pS/cz1Yu1pGSCxPd6PFXrCeu51CRnEroAuaTw1OR6y12WhjJG4ebc9qS7Vn2TYt10cU 4awcoMee3C6c8TUv6JegJbPPwuXow/M9TJuDzEg9S7tkwJRYAW0DKT1DILZJbxSjcLjjG mDKE6blH5kMOUs6Y6K+HRvqx9dB47nBvJNoWLLu9qOu5Ts/LI7fID5jrQeXKpu2nrP544 5rP7+W9MwB/SKgf91JB+iPgFw7VSf83+RpVoLaOm32bqbL4yE2UhNFxPHVDWNsZjmtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gnlK5SlP; 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 16BEA606A322; Fri, 4 Dec 2026 12:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gnlK5SlP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8591C1F00935; Fri, 4 Dec 2026 12:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386484; bh=moxCfaYldc9npNJv1wGaJ5/cFGNQIPPxxOPFGNLfqx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gnlK5SlPoarCsJvTSV7hxfobn9lXdrdWq61G8oN/SPRzdR1CrvkRmtkSLqC0Cl93q MxBihRzggQpyPC356pzUb1bVjvEzdb5MokJDJNKT2hWVdi+qNaLk1ybFhWnFoL+gun n4JsunW6wro8qYPkEUk5tM5fJfsLua2KabekV4Jg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stefan Ghetu , Shengjiu Wang , Mark Brown , Sasha Levin Subject: [PATCH 6.6 0942/1167] ASoC: fsl_asrc: fix pair ownership on repeated or failed hw_params Date: Fri, 4 Dec 2026 19:06:09 +0900 Message-ID: <20261204100726.728082369@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stefan Ghetu [ Upstream commit fbeac9352de6584bd5eb7c23d2f224339772c992 ] hw_params() can be called again without hw_free() in between, and hw_free() is also called after a failed hw_params(). fsl_asrc_request_pair() always takes a new pair, so a second hw_params() leaves the stream in two asrc->pair[] entries. Only one is released, and after close the other points to freed memory, which is dereferenced by fsl_asrc_isr() and fsl_asrc_m2m_suspend(). After a failed hw_params(), fsl_asrc_release_pair() releases a stale index that may belong to another running stream. Keep the owned pair and only update its channels when it is requested again, and ignore a pair the stream does not own on release. Fixes: 3117bb3109dc ("ASoC: fsl_asrc: Add ASRC ASoC CPU DAI and platform drivers") Signed-off-by: Stefan Ghetu Reviewed-by: Shengjiu Wang Link: https://patch.msgid.link/20261116093751.138455-3-stefan.ghetu@nxp.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/fsl/fsl_asrc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index c6fc03e364a61..01e3bab9a5d88 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -210,6 +210,8 @@ static void fsl_asrc_sel_proc(int inrate, int outrate, * It assigns pair by the order of A->C->B because allocation of pair B, * within range [ANCA, ANCA+ANCB-1], depends on the channels of pair A * while pair A and pair C are comparatively independent. + * + * If @pair already owns a pair, it is kept and only its channels are updated. */ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) { @@ -221,6 +223,19 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) spin_lock_irqsave(&asrc->lock, lock_flags); + if (asrc->pair[pair->index] == pair) { + if (asrc->channel_avail + pair->channels < channels) { + dev_err(dev, "can't afford required channels: %d\n", channels); + return -EINVAL; + } + + asrc->channel_avail += pair->channels; + asrc->channel_avail -= channels; + pair->channels = channels; + + return 0; + } + for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) { if (asrc->pair[i] != NULL) continue; @@ -254,6 +269,7 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) * @pair: pair to release * * It clears the resource from asrc and releases the occupied channels. + * Nothing is done if @pair does not own a pair. */ static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair) { @@ -261,6 +277,12 @@ static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair) enum asrc_pair_index index = pair->index; unsigned long lock_flags; + /* Only the owner clears its entry, so it cannot change after this check */ + scoped_guard(spinlock_irqsave, &asrc->lock) { + if (asrc->pair[index] != pair) + return; + } + /* Make sure the pair is disabled */ regmap_update_bits(asrc->regmap, REG_ASRCTR, ASRCTR_ASRCEi_MASK(index), 0); -- 2.53.0