mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation
@ 2026-11-05 13:15 Sergey Matsievskiy
  2026-11-05 17:16 ` Frank Li
  0 siblings, 1 reply; 2+ messages in thread
From: Sergey Matsievskiy @ 2026-11-05 13:15 UTC (permalink / raw)
  To: dmaengine; +Cc: lars, vkoul, Frank.Li, linux-kernel, Sergey Matsievskiy

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@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation
  2026-11-05 13:15 [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation Sergey Matsievskiy
@ 2026-11-05 17:16 ` Frank Li
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-11-05 17:16 UTC (permalink / raw)
  To: Sergey Matsievskiy; +Cc: dmaengine, lars, vkoul, Frank.Li, linux-kernel

On Thu, Nov 05, 2026 at 04:15:47PM +0300, Sergey Matsievskiy wrote:
> [You don't often get email from matsievskiysv@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> 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@gmail.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-05 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 13:15 [PATCH] dmaengine: axi-dmac: fix incorrect segment size calculation Sergey Matsievskiy
2026-11-05 17:16 ` Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®