From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2F0649BD7D; Tue, 22 Sep 2026 23:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790119884; cv=none; b=TqKBDtKg4KSOzX4C9p7oW8aASd1X2v9ROURWwT0Xe5m0wboGGq0FcsPm5eUY64eumKqXlAeto6GoqFkfgWdwP2RDkwwUpg51xA8c9tpEy3e2MdpcfhhiW3F0dsykCbJjQazJ5++Bl1G1Ejt8rhnX5T/gKsSBZDFfrX7JxuAvjIU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790119884; c=relaxed/simple; bh=jX/7WfkhdwUeYgr9fmoPhFAd72OpSBYdPLvXVnfgDa0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p3gONqFY6klQdDM96nzCJhYzZcY13Vpo22dCehavyWDuUpePtFMhvLvOiIthNWGv6sWzXJgGqydngD441FOn924uTWp53jzM1ElzHScGNBRG8tbqrGVftXdnRx2xDrwg7ksJVjam+4h37s+bKJMbX53IyAISygfsxOkwZ0M0F5Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mHirwlrn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mHirwlrn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 889561F00899; Tue, 22 Sep 2026 23:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790119882; bh=P7V1lR+W4kNa7Gmkk8R+lOi+DZZway5JNi1b9iGhNp4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mHirwlrnShxk2peI3h/52N8lxmW/AnladOIBLzpzeSmJZvcuqkUnsmcIlhzfPzzn6 4hwpf1Xr18iv4ftnkM4rqb6NGxB572JiP0M6ptGP8KRi6yraCZny5cjV3RsQ1/VjUG XkYgFvr5UhXvSKetDhH0U6HZ+Buw0ItG/7pE6NKipyflvNppgnjwCB8iUwb9iKjaMH NyGAHe1ER1+/90YeqBuKiGB+hxPO6zU3rrqkOyPR/W3ZQN/XdxAWWT5O3ut0WlKfJx g+76i71H7eG41r2nj26Wnl/GHsIRIDiD7pd0UOb3cSfd11hQOOY0nist/E650npBz/ FiKrWVAu6zMpA== From: Linus Walleij Date: Wed, 23 Sep 2026 01:31:03 +0200 Subject: [PATCH v5 18/23] dmaengine: ste_dma40: Reject direction changes after allocation Precedence: bulk X-Mailing-List: phone-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260923-dma40-fixes-v5-18-709d160cde76@kernel.org> References: <20260923-dma40-fixes-v5-0-709d160cde76@kernel.org> In-Reply-To: <20260923-dma40-fixes-v5-0-709d160cde76@kernel.org> To: Vinod Koul , Frank Li Cc: dmaengine@vger.kernel.org, phone-devel@vger.kernel.org, Linus Walleij , sashiko-bot@kernel.org X-Mailer: b4 0.14.3 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 Signed-off-by: Linus Walleij --- 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 31053d31a584..787567bed12f 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -2418,7 +2418,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); @@ -2894,6 +2900,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; @@ -2902,13 +2915,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; @@ -2918,13 +2924,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.55.0