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=1796381955; b=1DNQK/x5hjEOy0+tL1sofbA/NT7U6hZ33g397ai+tRe14QhXxSUSUSpaO/7uSyBNeEhw s3kG/KUdnz1+8vfTJO4lbPTA7tvDw4Ta8yx5UplfxLrLovWKXjFQCd5euc7rJUp3U4Tjb sb9Ud8P5EFk+b9tzyhM9eXxYUJ3kq00RpZiTNpTmRbIjbv7rCXv+mIEYy1vOsrCk64rrm gWbjU9G1+nrbQmLpSh6twoc3ATJhRfCKo/jyRggcueBRz2RgmbBs7wRwlsoLFEtIenVPC 9YsIhAqT9RzMp3zA6Apw3nWVKPhltZDFRfspFpG0oYwRB9lPfe9DG7OMjf8QPLe6PEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381955; 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=1jMZJ+fUnOYY709mRi9s4qCt8Hl/RuRGUob+y0OIM10=; b=nHZbhwdoTUAbkMMiRqvPy3kEO1VVnTpB0n74MePADdLsBzotK9iHUNVpy0yCGRq7Bvc1 ngRQCjAdBmsh9srdxYYPHr5cvDucYU/5GMEmDImR5130ceqSQ3WXPeEVgOBbkFFRNAqDL bqDmM4Yvjo97srFACiZ7KMGNaKPp2DNM93qU1xLAJUC9EP0wfdcGB89VdcKS0zSctw+oa NbPUexLVqRTNB5hN4HEQnsIqBpu7JoEJxkuuXAhFCoaOQ0xApfQ3cBE+TZ4t6XoiKA/Jt SPVPMg1LHUzVUGzeiwAIQFHg8W5nBWCWrg98M4MSdgNeoPiocEwox7QRZih+flzwMyw== 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=jn76NAnG; 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 1A6BD606A32C; Fri, 4 Dec 2026 10:59:15 +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=jn76NAnG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A33F1F000C2; Fri, 4 Dec 2026 10:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381954; bh=1jMZJ+fUnOYY709mRi9s4qCt8Hl/RuRGUob+y0OIM10=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jn76NAnGr7wk/zwnF2iZLEzVjdItiO3xYV4SiO9aviv/3Ug2mCH5ACgYSFXPby0JA RImYbz9VYRDOdw+LjGs6cGyQJO1+zRb3H8dSXrsm2JLdCHr4DKApKlWhx7KHg5WAqO MVyfMr8sCVpc7uG9p//Ishdf54HyJ2O4Kav8Sf2A= 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.18 246/703] ASoC: fsl_asrc: fix pair ownership on repeated or failed hw_params Date: Fri, 4 Dec 2026 19:02:25 +0900 Message-ID: <20261204100634.344416351@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 be55182071a28..22e49eeb0abbb 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