Re: XDMA crashes on zero-length sg entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Martin,

Based on the dmaengine document

https://kernel.org/doc/html/v6.3-rc2/driver-api/dmaengine/client.html

The sg_len used for dmaengine_prep_slave_sg should be returned by dma_map_sg.

This implies there should not be zero segment for the first sg_len segments.

I think that is why we need to provide 'sg_len' for dmaengine_prep_slave_sg().

With 'sg_len', we do not need to worry about zero length sg in the driver callback.


Thanks,

Lizhi

On 3/16/23 10:03, Martin Tůma wrote:
Hi,
The Xilinx XDMA driver crashes when the scatterlist provided to
xdma_prep_device_sg() contains an empty entry, i.e. sg_dma_len()
returns zero. As I do get such sgl from v4l2 I suppose that this
is a valid scenario and not a bug in our parent mgb4 driver. Also
the documentation for sg_dma_len() suggests that there may be
zero-length entries.

The following trivial patch fixes the crash:

diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c
index 462109c61653..cd5fcd911c50 100644
--- a/drivers/dma/xilinx/xdma.c
+++ b/drivers/dma/xilinx/xdma.c
@@ -487,6 +487,8 @@ xdma_prep_device_sg(struct dma_chan *chan, struct scatterlist *sgl,
        for_each_sg(sgl, sg, sg_len, i) {
                addr = sg_dma_address(sg);
                rest = sg_dma_len(sg);
+               if (!rest)
+                       break;

                do {
                        len = min_t(u32, rest, XDMA_DESC_BLEN_MAX);

M.



[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux PCI]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux