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=1796383506; b=lWW/6V31BmRgA/QzHzzodh+iffV8Vg9t+wEB6XPjVejzo1rAIJjgNw49JOP9Rjipbbkk 13U/AEfBa7FBtCyR3x3YkGYIw1FslfA1wObZawfpkO1vFDxgTWGnVyGcMVAjZw8Tb8aM3 VXK0t10M6M1olIoB8Be0fXRfKOMi2VTA+I15Md2FZ+tIA2cddjR9VyTz5kxa8Fo37C+zr 0FlG0e5bDOlmrssm02CUBBUWfxtsMEx8ULPyD0YW2a9FESxEw/UFnL4Az4rDlui/4dAKR BAMCOx2wMyeyQJz8K55twYkaTY8uAm0bW+YSCYdccfPuzDT5s4mXVO5ZkhApMamvlnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383506; 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=05ooYwB12mNtvWbtor45YSWdOdipqElewd7V7Bf2QXI=; b=MCCHacpEx1Ex1X8T9lXNoBGEodq8vsqGerRHPugoohtNERwem94aR59cvc3+c98MXNeA klNg6pH+c28R3yIpjQFD4AIEDn1n4nOdqNv7t7LwGFrb4G0mr7m/Eef48RO5SuwBIeors 3yAgXqEnu7r5EA1EPL42Rw/DN/F+ukBqCgvk+EqEIWClW9bDs26Q6CtMSiu3G6IrhRdfM pYqPaBQZF7EGrP4ksXQv0YZM8VNKf+wvqW+q/zoYhDnLwv0Pmw56XQllS8GQ+ihr++R7T hHk/+Gr3wFE5qBqhdtwv+FdaCOdiOd0/XyCpCL+vbhcQ8jC6rS5bsT1wYmu626XpDZw== 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=jT0vGVzN; 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 54A4A606A322; Fri, 4 Dec 2026 11:25:06 +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=jT0vGVzN Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBD021F000CE; Fri, 4 Dec 2026 11:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383506; bh=05ooYwB12mNtvWbtor45YSWdOdipqElewd7V7Bf2QXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jT0vGVzNPpMmqwYmGmGpBkk3IHL+0uLS1E+yLO1lt9tc5PH8ebV5ZJJxiH9HN9RgE 9OwOeAi2curTqAaOg0FFs0UtStF1EmNsi6p11BQ6/G0SE2l7iYjw7N9aN50xOlU7Vz 6hwf4HbT8+XKNjIYtlXNpXtwXLaJZf5z7xg/1Lqs= 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.12 251/555] ASoC: fsl_asrc: fix pair ownership on repeated or failed hw_params Date: Fri, 4 Dec 2026 19:04:54 +0900 Message-ID: <20261204100618.714879621@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 f68b53ba17dd7..73eee0f43ba99 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