From 50f9aa23453ff0e04be40a69e8b16329ce1d8c16 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Thu, 20 Mar 2025 16:41:14 +0000
Subject: [PATCH] dmaengine: dw-axi-dmac: Fix alignment checks

Remove a bogus memory alignment check - transfers will be run bytewise
if needed - and add a check that the overall length is multiple of the
register size, otherwise there is residue.

See: https://github.com/raspberrypi/linux/issues/6733

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -748,11 +748,6 @@ static int dw_axi_dma_set_hw_desc(struct
 
 	mem_width = __ffs(data_width | mem_addr | len);
 
-	if (!IS_ALIGNED(mem_addr, 4)) {
-		dev_err(chan->chip->dev, "invalid buffer alignment\n");
-		return -EINVAL;
-	}
-
 	/* Use a reasonable upper limit otherwise residue reporting granularity grows large */
 	mem_burst_msize = axi_dma_encode_msize(16);
 
@@ -797,6 +792,11 @@ static int dw_axi_dma_set_hw_desc(struct
 		return -EINVAL;
 	}
 
+	if (len % (1 << reg_width)) {
+		dev_err_ratelimited(chan->chip->dev, "length %ld not aligned to device width %d\n", len, 1 << reg_width);
+		return -EINVAL;
+	}
+
 	if (block_ts > axi_block_ts)
 		return -EINVAL;
 
