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=1796380290; b=SPcktwo8N1JBBFY4Ug8LfjNhGGP/Txh0uG6hLVoMtFlCIZEDmP/cNt8qvB55YiOeKKBS osvYBqS+XqVxgH3rx9os8ykY9ExK6omZfeueEj53sGcXUQevITwta2SnZLZfNZefD/Zy+ YUZkOorGs6qhdNhFliXd3dF4PfbnKFx2Jb+BUUbIBifhgIzXBu3tW9PsgrZeIuIpHVlWq 6heZbzL6nmDJM82zkQjQi0nTtVB6Q1gUyc4FnA72G9Qtx7aAH/u9b0/2M1QIIMGJsX+TW vyLT/5UPNMFnLZrFt09acVo4ml4dvBz3A/+GmkarFeu66JGPjBnSCGMK9jQE/uTmeVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380290; 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=eTSufKMUVj+McL21bM9yEw3KEKw+xtWubBeuITHj4bg=; b=36dmaNve90NAeWM8v1Fitq9tymY92qdlMz8scKXS3XW6qSOH7OOX+SzXpUC1+q2WND0K 6jI9cCXNZZDTmrYPK+sLPY1qkw2vpcTMx8S1gkCDm6c5PeOnTVilj7Tvg9Pg1/B4/PkBb G0J1OJTbKiOMciKpVNBZvEgvhWJrcckVT95X/be9ijpjp2TuKTapf6acfxngp7k/sBMiA PwHiaejJaO8zVp3S0m9jaGzD/eUhr9oBSIEM7+dMgHdNG+agjyte6lpl5U5nwpKyW7Mml ibDrRbWQkiTUxURzTJAVP6LQq0cWIIgGP/O1fC9RiykZBaNjCi/VXbUBeN+bbRbiAhw== 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=hszzPgA5; 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 E1BDE606A322; Fri, 4 Dec 2026 10:31:29 +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=hszzPgA5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27B901F00931; Fri, 4 Dec 2026 10:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380289; bh=eTSufKMUVj+McL21bM9yEw3KEKw+xtWubBeuITHj4bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hszzPgA5Jj5jOxYGLfIEonH0jhiSacD+DBbuVrcxvkamiT/LOhO8adwMS+kYAjZPr fV31T+AMa+h3oOW9zD8Vu4mSdMArAwZMYq4rwGTrtDHgl+o/uKpxsbQxhxvZZoWdJw hhquzJa1iLdXZv2UzqR5wAfPUoQTE2oUWXwIBAkE= 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 7.3 208/742] ASoC: fsl_asrc: fix pair ownership on repeated or failed hw_params Date: Fri, 4 Dec 2026 19:01:12 +0900 Message-ID: <20261204100640.608307919@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 d80afe1bf4be3..c40c26b5cedc3 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -216,6 +216,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) { @@ -226,6 +228,19 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) guard(spinlock_irqsave)(&asrc->lock); + 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; @@ -257,12 +272,19 @@ 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) { struct fsl_asrc *asrc = pair->asrc; enum asrc_pair_index index = pair->index; + /* 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