[PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation

From: Sergey Matsievskiy

Date: Thu Nov 05 2026 - 08:18:31 EST


When chan->max_length has a value of 0xffffffff (which is a possible IP
configuration), DIV_ROUND_UP returns 0, resulting in incorrect number of
segments calculation. Fix this by using DIV_ROUND_UP_ULL division
function.

Signed-off-by: Sergey Matsievskiy <matsievskiysv@xxxxxxxxx>
---
drivers/dma/dma-axi-dmac.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index 02acde918117..0a308630e542 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -707,7 +707,7 @@ static struct axi_dmac_sg *axi_dmac_fill_linear_sg(struct axi_dmac_chan *chan,
unsigned int len;

/* Split into multiple equally sized segments if necessary */
- num_segments = DIV_ROUND_UP(period_len, chan->max_length);
+ num_segments = DIV_ROUND_UP_ULL(period_len, chan->max_length);
segment_size = DIV_ROUND_UP(period_len, num_segments);
/* Take care of alignment */
segment_size = ((segment_size - 1) | chan->length_align_mask) + 1;
@@ -753,7 +753,7 @@ axi_dmac_prep_peripheral_dma_vec(struct dma_chan *c, const struct dma_vec *vecs,
return NULL;

for (i = 0; i < nb; i++)
- num_sgs += DIV_ROUND_UP(vecs[i].len, chan->max_length);
+ num_sgs += DIV_ROUND_UP_ULL(vecs[i].len, chan->max_length);

desc = axi_dmac_alloc_desc(chan, num_sgs);
if (!desc)
@@ -840,7 +840,7 @@ static struct dma_async_tx_descriptor *axi_dmac_prep_dma_cyclic(
return NULL;

num_periods = buf_len / period_len;
- num_segments = DIV_ROUND_UP(period_len, chan->max_length);
+ num_segments = DIV_ROUND_UP_ULL(period_len, chan->max_length);
num_sgs = num_periods * num_segments;

desc = axi_dmac_alloc_desc(chan, num_sgs);
--
2.47.3