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=1796387674; b=nARa462nuONW/0X4i/GajdhmQWukaQZVMIjsvu2SFHWdRTzkzznPOVc65wT7Q3SCyPje ha3su5sxQNLXEbry2dDpkmTUeLSUsRpQxeGD8tDXMINPj5+gcpSf2tU4yYLvi+UgLDc9O DdHczquz+IGf4cMOdek3R6P9cCoumVnxGB5WJkldW2p1GnhZaU2vpkA12rLaAMLoRk0vl u1M5+VJQ1ehwVPrQP5GVEofjw9kuUBxVcVEZd/dWEDSVEXeN7vz1P/AxKh5bFmI9ZLMQM F/e56pryY9kDaaBUYzEOD2/EwtNl6jvmjg0/pVgXO8F7Y32XYIGeJb3WgXVX1FIIx6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387674; 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=g1Ay/RFwChqN3fl7zM9mRJD4oA5pw7zcojkHC4syW6c=; b=jvUL+oMk3fvbTtYkLcods8H9gZMO1ATraBRvB/ywXs3d0zazC9NSVwQ4HVvvsEtfGXNM ZZR5ghmvFWL4LMI2juMGkTo7eTRN0H2x4wC7u97n0cDn5CSa4LdD4a7h0zIjwmW5UjgIF zPcUdO+rLS76SjtFKdSuDt/lL+PhDIycJ4Co2GSmsXvWqoruL4Pr7o/S0XkYilxbc2gPw pW5qNVAmLos0XyU3BHxrSviPZsBvqTsLbPHtA/Y71PHPQqmFb4r5C7fKuMdQz2KiTaaIm MtoUxhV+for+tTdnMyqusImnu68DjXFOLZZwlQyxgRCzI1Y0tit2A9z16zIiP3gd5/Q== 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=KxJg4Deg; 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 C891F606A322; Fri, 4 Dec 2026 12:34:34 +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=KxJg4Deg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43C431F000C2; Fri, 4 Dec 2026 12:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387674; bh=g1Ay/RFwChqN3fl7zM9mRJD4oA5pw7zcojkHC4syW6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KxJg4DegxL1kNGRmt2ltG1XsUcyrHGlL2L9zPBGG+T/JXIMS27FmQPvziazTosE7h zrc509nQQAAYFkWUj14yfouhN2d/hRkKcSJrUsEyk++Adbow/wosHeQuGnu5gLi7VB ioZz68o4anL0OlRjFE5NkcffrCQvY3DSzwZDnQSE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot@kernel.org, Frank Li , Linus Walleij , Vinod Koul , Sasha Levin Subject: [PATCH 6.1 0343/1059] dmaengine: ste_dma40: Reject direction changes after allocation Date: Fri, 4 Dec 2026 18:57:54 +0900 Message-ID: <20261204100653.152899065@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Walleij [ Upstream commit 77ebc64f40717b8501793b5f5ee717a141e62e8e ] Logical channel allocation uses the configured direction to select the source or destination allocation mask, derive the logical channel number, and choose the LCPA location. d40_set_runtime_config_write() nevertheless overwrites the configured direction when a transfer is prepared for the opposite direction. d40_free_dma() then clears the wrong allocation mask, leaking the original resource and potentially releasing one used by another client. Reject directions that differ from the direction used during allocation and propagate runtime configuration errors to callers. Skip slave runtime configuration for memcpy transfers, which also use d40_prep_sg() but do not require it. Fixes: 95e1400fa131 ("DMAENGINE: add runtime slave config to DMA40 v3") Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/dmaengine/20260618051539.15E201F000E9@smtp.kernel.org/ Assisted-by: LLM Reviewed-by: Frank Li Signed-off-by: Linus Walleij Link: https://patch.msgid.link/20260927-dma40-fixes-v7-18-89f595e8851d@kernel.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/ste_dma40.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index 3ec960b6a16d2..15f55802e8036 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -2372,7 +2372,13 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src, return NULL; } - d40_set_runtime_config_write(dchan, &chan->slave_config, direction); + if (direction != DMA_MEM_TO_MEM) { + ret = d40_set_runtime_config_write(dchan, + &chan->slave_config, + direction); + if (ret) + return NULL; + } spin_lock_irqsave(&chan->lock, flags); @@ -2843,6 +2849,13 @@ static int d40_set_runtime_config_write(struct dma_chan *chan, return -EINVAL; } + if (direction != cfg->dir) { + chan_err(d40c, + "transfer direction %d differs from allocated direction %d\n", + direction, cfg->dir); + return -EINVAL; + } + src_addr_width = config->src_addr_width; src_maxburst = config->src_maxburst; dst_addr_width = config->dst_addr_width; @@ -2851,13 +2864,6 @@ static int d40_set_runtime_config_write(struct dma_chan *chan, if (direction == DMA_DEV_TO_MEM) { config_addr = config->src_addr; - if (cfg->dir != DMA_DEV_TO_MEM) - dev_dbg(d40c->base->dev, - "channel was not configured for peripheral " - "to memory transfer (%d) overriding\n", - cfg->dir); - cfg->dir = DMA_DEV_TO_MEM; - /* Configure the memory side */ if (dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) dst_addr_width = src_addr_width; @@ -2867,13 +2873,6 @@ static int d40_set_runtime_config_write(struct dma_chan *chan, } else if (direction == DMA_MEM_TO_DEV) { config_addr = config->dst_addr; - if (cfg->dir != DMA_MEM_TO_DEV) - dev_dbg(d40c->base->dev, - "channel was not configured for memory " - "to peripheral transfer (%d) overriding\n", - cfg->dir); - cfg->dir = DMA_MEM_TO_DEV; - /* Configure the memory side */ if (src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) src_addr_width = dst_addr_width; -- 2.53.0