Add validation to reject zero-length DMA operations early
with -EINVAL, preventing queue disable.

Signed-off-by: Shijith Thotton <[email protected]>
---
 drivers/dma/odm/odm_dmadev.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/odm/odm_dmadev.c b/drivers/dma/odm/odm_dmadev.c
index 0211133bd4..7488b960fd 100644
--- a/drivers/dma/odm/odm_dmadev.c
+++ b/drivers/dma/odm/odm_dmadev.c
@@ -110,6 +110,9 @@ odm_dmadev_copy(void *dev_private, uint16_t vchan, 
rte_iova_t src, rte_iova_t ds
        vq = &odm->vq[vchan];
        hdr.s.xtype = vq->xtype;
 
+       if (unlikely(!length))
+               return -EINVAL;
+
        h = length;
        h |= ((uint64_t)length << 32);
 
@@ -262,14 +265,20 @@ odm_dmadev_copy_sg(void *dev_private, uint16_t vchan, 
const struct rte_dma_sge *
        pending_submit_len = vq->pending_submit_len;
        pending_submit_cnt = vq->pending_submit_cnt;
 
-       if (unlikely(nb_src > 4 || nb_dst > 4))
+       if (unlikely(!nb_src || nb_src > 4 || !nb_dst || nb_dst > 4))
                return -EINVAL;
 
-       for (i = 0; i < nb_src; i++)
+       for (i = 0; i < nb_src; i++) {
+               if (unlikely(!src[i].length))
+                       return -EINVAL;
                s_sz += src[i].length;
+       }
 
-       for (i = 0; i < nb_dst; i++)
+       for (i = 0; i < nb_dst; i++) {
+               if (unlikely(!dst[i].length))
+                       return -EINVAL;
                d_sz += dst[i].length;
+       }
 
        if (s_sz != d_sz)
                return -EINVAL;
@@ -342,6 +351,9 @@ odm_dmadev_fill(void *dev_private, uint16_t vchan, uint64_t 
pattern, rte_iova_t
                .s.nlst = 1,
        };
 
+       if (unlikely(!length))
+               return -EINVAL;
+
        h = (uint64_t)length;
 
        switch (pattern) {
-- 
2.25.1

Reply via email to