mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: Lizhi Hou <lizhi.hou@amd.com>, <tumic@gpxsee.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH V1] dmaengine: xdma: Check zero length scatter list segment
Date: Fri, 17 Mar 2023 11:14:56 -0700	[thread overview]
Message-ID: <1679076896-4876-1-git-send-email-lizhi.hou@amd.com> (raw)

In callback function xdma_prep_device_sg(), it is nice to check if there
is zero length segment and skip it in the input scatter list.

Reported-by: Martin Tuma <tumic@gpxsee.org>
Link: https://lore.kernel.org/dmaengine/f6a0051f-acec-f661-55cb-8b2504bef79e@amd.com/T/#t
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/dma/xilinx/xdma.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c
index 462109c61653..5134757e88b1 100644
--- a/drivers/dma/xilinx/xdma.c
+++ b/drivers/dma/xilinx/xdma.c
@@ -465,6 +465,8 @@ xdma_prep_device_sg(struct dma_chan *chan, struct scatterlist *sgl,
 
 	for_each_sg(sgl, sg, sg_len, i)
 		desc_num += DIV_ROUND_UP(sg_dma_len(sg), XDMA_DESC_BLEN_MAX);
+	if (!desc_num)
+		return NULL;
 
 	sw_desc = xdma_alloc_desc(xdma_chan, desc_num);
 	if (!sw_desc)
@@ -488,7 +490,7 @@ xdma_prep_device_sg(struct dma_chan *chan, struct scatterlist *sgl,
 		addr = sg_dma_address(sg);
 		rest = sg_dma_len(sg);
 
-		do {
+		while (rest) {
 			len = min_t(u32, rest, XDMA_DESC_BLEN_MAX);
 			/* set hardware descriptor */
 			desc->bytes = cpu_to_le32(len);
@@ -506,7 +508,7 @@ xdma_prep_device_sg(struct dma_chan *chan, struct scatterlist *sgl,
 			dev_addr += len;
 			addr += len;
 			rest -= len;
-		} while (rest);
+		};
 	}
 
 	tx_desc = vchan_tx_prep(&xdma_chan->vchan, &sw_desc->vdesc, flags);
-- 
2.27.0


                 reply	other threads:[~2023-03-17 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1679076896-4876-1-git-send-email-lizhi.hou@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tumic@gpxsee.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

all inboxes | Powered by JetHome®