lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260114-dma_common_config-v1-5-64feb836ff04@nxp.com>
Date: Wed, 14 Jan 2026 12:12:46 -0500
From: Frank Li <Frank.Li@....com>
To: Vinod Koul <vkoul@...nel.org>, Shawn Guo <shawnguo@...nel.org>, 
 Sascha Hauer <s.hauer@...gutronix.de>, 
 Pengutronix Kernel Team <kernel@...gutronix.de>, 
 Fabio Estevam <festevam@...il.com>
Cc: dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org, 
 imx@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org, 
 Frank Li <Frank.Li@....com>
Subject: [PATCH 5/6] dmaengine: Add union and dma_slave_get_config() helper
 for dma_slave_config

Previously, src_ and dst_ prefixes were used to distinguish address,
addr_width, maxburst, and port_window_size fields. This required drivers
to add conditional logic based on transfer direction.

Introduce struct dma_slave_cfg to group these fields and add the
dma_slave_get_config() helper to retrieve the source or destination
configuration based on the DMA transfer direction. This reduces
direction-based branching in drivers and improves readability.

Use a union to preserve the old field naming and maintain compatibility.

Signed-off-by: Frank Li <Frank.Li@....com>
---
 include/linux/dmaengine.h | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 362a43c3e36e232b5a65ff78ba0b692c0401e50c..03632bccc7ccb3c0c4a9c78f15865f35a375836a 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -384,21 +384,47 @@ enum dma_slave_buswidth {
  * If not: if it is fixed so that it be sent in static from the platform
  * data, then prefer to do that.
  */
+struct dma_slave_cfg { /* order must be align below dma_slave_config union */
+	phys_addr_t addr;
+	enum dma_slave_buswidth addr_width;
+	u32 maxburst;
+	u32 port_window_size;
+};
+
 struct dma_slave_config {
 	enum dma_transfer_direction direction;
-	phys_addr_t src_addr;
-	phys_addr_t dst_addr;
-	enum dma_slave_buswidth src_addr_width;
-	enum dma_slave_buswidth dst_addr_width;
-	u32 src_maxburst;
-	u32 dst_maxburst;
-	u32 src_port_window_size;
-	u32 dst_port_window_size;
+	union {
+		struct {
+			phys_addr_t src_addr;
+			enum dma_slave_buswidth src_addr_width;
+			u32 src_maxburst;
+			u32 src_port_window_size;
+			phys_addr_t dst_addr;
+			enum dma_slave_buswidth dst_addr_width;
+			u32 dst_maxburst;
+			u32 dst_port_window_size;
+		};
+
+		struct {
+			struct dma_slave_cfg src;
+			struct dma_slave_cfg dst;
+		};
+	};
 	bool device_fc;
 	void *peripheral_config;
 	size_t peripheral_size;
 };
 
+static inline struct dma_slave_cfg *
+dma_slave_get_cfg(struct dma_slave_config *config,
+		  enum dma_transfer_direction dir)
+{
+	if (dir == DMA_MEM_TO_DEV)
+		return &config->dst;
+
+	return &config->src;
+}
+
 /**
  * struct dma_chan - devices supply DMA channels, clients use them
  * @device: ptr to the dma device who supplies this channel, always !%NULL

-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ