From: sashiko-bot@kernel.org
To: "Sergey Matsievskiy" <matsievskiysv@gmail.com>,
dmaengine@vger.kernel.org
Cc: vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v2 1/1] dmaengine: axi-dmac: fix incorrect segment size calculation
Date: Tue, 17 Nov 2026 06:02:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-218236@kernel.org> (raw)
In-Reply-To: <20261117054054.22409-2-matsievskiysv@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] dmaengine: axi-dmac: 32-bit overflow in
axi_dmac_prep_slave_sg()
- [Medium] dmaengine: axi-dmac: 32-bit overflow in
axi_dmac_fill_linear_sg()
- [Low] dmaengine: axi-dmac: missing Fixes trailers in commit message
--
commit f72f25e5b5e585f311e3609163b81e15ebf9fa27
Author: Sergey Matsievskiy <matsievskiysv@gmail.com>
> dmaengine: axi-dmac: fix incorrect segment size calculation
>
> 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.
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Signed-off-by: Sergey Matsievskiy <matsievskiysv@gmail.com>
[Severity: Low]
Should this bug fix include Fixes tags for the commits that introduced
these calculations?
Fixes: 921234e0c5d7 ("dmaengine: axi-dmac: Split too large segments")
Fixes: 74609e568670 ("dmaengine: dma-axi-dmac: Implement device_prep_peripheral_dma_vec")
> diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
> index dbc31b185c4d4..30ea905840fe2 100644
> --- a/drivers/dma/dma-axi-dmac.c
> +++ b/drivers/dma/dma-axi-dmac.c
> @@ -706,7 +706,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;
[Severity: Medium]
Can segment_size still overflow 32-bit unsigned arithmetic here when
chan->max_length is smaller than UINT_MAX (for example, 0x01000000 for a
24-bit X_LENGTH configuration) and period_len is within num_segments - 1
of UINT_MAX?
In that case, period_len + num_segments - 1 wraps around in 32-bit
DIV_ROUND_UP(), making segment_size evaluate to 0 before and after the
alignment adjustment. The loop below then subtracts 0 from len on each
iteration and advances sg past the end of desc->sg[]. Using
DIV_ROUND_UP_ULL(period_len, num_segments) avoids the overflow.
> @@ -752,7 +752,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)
> @@ -839,7 +839,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);
[Severity: High]
Does axi_dmac_prep_slave_sg() still hit the same 32-bit overflow on
32-bit architectures when chan->max_length is 0xffffffff?
drivers/dma/dma-axi-dmac.c:axi_dmac_prep_slave_sg() {
...
num_sgs = sg_nents_for_dma(sgl, sg_len, chan->max_length);
desc = axi_dmac_alloc_desc(chan, num_sgs);
...
for_each_sg(sgl, sg, sg_len, i) {
...
dsg = axi_dmac_fill_linear_sg(chan, direction, sg_dma_address(sg), 1,
sg_dma_len(sg), dsg);
}
}
sg_nents_for_dma() computes DIV_ROUND_UP(sg_dma_len(sg), len) with an
unsigned int dividend and a size_t divisor. On 32-bit platforms with
chan->max_length == 0xffffffff, that addition wraps and counts 0 segments
for every scatterlist entry with length >= 2, causing
axi_dmac_alloc_desc() to index desc->sg[num_sgs - 1] out of bounds when
num_sgs is 0 or axi_dmac_fill_linear_sg() to write past the end of
desc->sg[].
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117054054.22409-1-matsievskiysv@gmail.com?part=1
prev parent reply other threads:[~2026-11-17 6:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 5:40 [PATCH v2 0/1] dmaengine: axi-dmac: fix incorrect segment size calculation Sergey Matsievskiy
2026-11-17 5:40 ` [PATCH v2 1/1] " Sergey Matsievskiy
2026-11-17 6:02 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-218236@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=matsievskiysv@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox