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=1795055826; b=M5oJAbRcwh40cFpEgFT4C4Fw6DltdvA/xmgobR5pp1Q/8dKdizPFn1vWBzsL2WNNBcUD AClaeXNOWe13sSbN9tWV+tl4mBVmT7WCxPdjzJT1UicAlN6b4fZxjHGEycxOKtHoOKG9H KrHIn1WqyjsXwgJnnOZc728nJbjF/gqzm4KSbH+VlRdFz8xfaju84aC9oD0EEp4leM5AQ gfmUlIVOt9ABm5EPgqIWawjEvygolNSLfYf9im0cwQCzO2lnkscpuBKmyt3NNV0Du9pW+ YAgvQYPOYGIs07QCb97lCA5fZelE67iV2edYMAoR09dyxOVc7isdPNs7dVHWn6SgABQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795055826; 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=zQzHLwxwDDpA0u/QbSAvQ5dbVstTl0acHH/x6VyOwN0=; b=JuAS/PGk/9uu1hQypsB0BF891deyOySvMCTpuM8zzrko+IUwpMD4wSUAH+RbARMiN8Fv 54zWKLFNSR6O7ZEGDxJEAc2yIZnwn07baii0uJHjXArvkjbbwQlRxOXncE8HhUyDKTC3k l7l+jEDeP0kduy5bua0EQGiwDjCLezxERdArQum0e1um85jz8+MU6NbLMuGuImJU6izO0 YI9lrRBlKY0kckcf+vxNnwTYYKXoG60ANyOdbFuoUNzIVXbXZIJJouIYFptJGLN5Ejd0R 4OCKYzo6SiS9qnY3IUlbyP1uAHA0duX2AqvFuok5PEUmwK0HIocQ8m6hAlYoX2mw08A== 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=2TqQeVn3; 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 7D478606A31C; Thu, 19 Nov 2026 02:37: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=2TqQeVn3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4DE01F000C4; Thu, 19 Nov 2026 02:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795055826; bh=zQzHLwxwDDpA0u/QbSAvQ5dbVstTl0acHH/x6VyOwN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2TqQeVn3IQhYV07WJb5FDNB/ku0sKoXNFJhAeLLPUUy82j55Ggklr2kBw7uQjcQP+ XpWGIQZHxMgP9wZkV9CRWnKu1PJ+MZhtdtzgBlt+7hzqjFZ0h0rTv000Vcq1flMjw2 13Tto7hKPdXC1EE5GRjieSjmxK7ntISZZtgZS7uw= 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 5.15 1768/2214] dmaengine: ste_dma40: Reject direction changes after allocation Date: Wed, 18 Nov 2026 15:57:24 +0100 Message-ID: <20261118150122.255017456@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@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 5.15-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 9ac2d44285222..fe674afa05286 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -2256,7 +2256,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); @@ -2712,6 +2718,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; @@ -2720,13 +2733,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; @@ -2736,13 +2742,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