From: sashiko-bot@kernel.org
To: "Li Ximo" <lixicaicai@gmail.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v2] dmaengine: xilinx: dpdma: fix crash on zero-length cyclic transfer
Date: Tue, 03 Nov 2026 08:42:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-194855@kernel.org> (raw)
In-Reply-To: <20261103083132.1122990-1-lixicaicai@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dmaengine: xilinx: dpdma: misplaced and incomplete zero-length check
--
commit 9ce2097539c963154302835e8e5bdaba12caffe7
Author: Wang Haoran <haoranwangsec@gmail.com>
dmaengine: xilinx: dpdma: fix crash on zero-length cyclic transfer
This commit checks whether the descriptor list is empty after the loop in
xilinx_dpdma_chan_prep_cyclic() to avoid a crash when buf_len is zero.
> diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c
> index d9a3542c4531c..bdfa85b80c6a8 100644
> --- a/drivers/dma/xilinx/xilinx_dpdma.c
> +++ b/drivers/dma/xilinx/xilinx_dpdma.c
> @@ -730,6 +730,9 @@ xilinx_dpdma_chan_prep_cyclic(struct xilinx_dpdma_chan *chan,
> last = sw_desc;
> }
>
> + if (list_empty(&tx_desc->descriptors))
> + goto error;
[Severity: Medium]
In xilinx_dpdma_chan_prep_cyclic(), every iteration of the loop either
jumps to error or appends a descriptor via list_add_tail():
drivers/dma/xilinx/xilinx_dpdma.c:xilinx_dpdma_chan_prep_cyclic() {
unsigned int periods = buf_len / period_len;
unsigned int i;
tx_desc = xilinx_dpdma_chan_alloc_tx_desc(chan);
if (!tx_desc)
return NULL;
for (i = 0; i < periods; i++) {
...
list_add_tail(&sw_desc->node, &tx_desc->descriptors);
buf_addr += period_len;
last = sw_desc;
}
}
Because of this, list_empty(&tx_desc->descriptors) can only be true when
periods is 0, so checking after the loop allocates tx_desc with
xilinx_dpdma_chan_alloc_tx_desc() only to immediately free it under the
error label.
Also, in the caller xilinx_dpdma_prep_dma_cyclic(), buf_len % period_len
is evaluated without checking whether period_len is zero:
drivers/dma/xilinx/xilinx_dpdma.c:xilinx_dpdma_prep_dma_cyclic() {
if (direction != DMA_MEM_TO_DEV)
return NULL;
if (buf_len % period_len)
return NULL;
return xilinx_dpdma_chan_prep_cyclic(chan, buf_addr, buf_len,
period_len, flags);
}
If period_len is 0 (for example, when both buf_len and period_len are 0),
won't this still trigger a divide-by-zero crash before reaching
list_empty()?
Would it be cleaner to validate if (!buf_len || !period_len) upfront in
xilinx_dpdma_prep_dma_cyclic(), matching how
xilinx_dpdma_prep_interleaved_dma() checks if (!xt->numf || !xt->sgl[0].size)
before allocating a descriptor?
Additionally, the commit message states:
The following list_first_entry() on the empty list returns a bad pointer
and causes a kernel oops.
When the list is empty, list_first_entry() computes an offset from
&tx_desc->descriptors and reads sw_desc->dma_addr relative to tx_desc,
whereas the NULL pointer dereference happens on the next statement
(last->hw.next_desc = ...) because last is initialized to NULL and never
updated when periods is 0. Could the commit message be updated to reflect
this?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103083132.1122990-1-lixicaicai@gmail.com?part=1
next prev parent reply other threads:[~2026-11-03 8:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:31 [PATCH v2] dmaengine: xilinx: dpdma: fix crash on zero-length cyclic transfer Li Ximo
2026-11-03 8:42 ` sashiko-bot [this message]
2026-11-03 15:17 ` Frank Li
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-194855@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=lixicaicai@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