From: Jun Yang <[email protected]>

In dpaa2_qdma_dq_fd, passing a local uint16_t variable directly as a
pointer to qdma_cntx_idx_ring_eq caused a compiler array-bounds warning
because the function takes a pointer to an element of the ring array.

Add a per-queue scratch buffer idxs[DPAA2_QDMA_MAX_DESC] to
struct qdma_virt_queue and use idxs[0] instead of a local variable
pointer. Also consolidate the fle_sdd pointer assignment for LONG and
SG FD types to avoid code duplication.

Fixes: 388e888dc082 ("dma/dpaa2: support short FD")
Cc: [email protected]
Signed-off-by: Jun Yang <[email protected]>
---
 drivers/dma/dpaa2/dpaa2_qdma.c | 38 ++++++++++++++--------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/dma/dpaa2/dpaa2_qdma.c b/drivers/dma/dpaa2/dpaa2_qdma.c
index f7d94bb799..6881ab1420 100644
--- a/drivers/dma/dpaa2/dpaa2_qdma.c
+++ b/drivers/dma/dpaa2/dpaa2_qdma.c
@@ -66,16 +66,19 @@ qdma_cntx_idx_ring_eq(struct qdma_cntx_idx_ring *ring,
        const uint16_t *elem, uint16_t nb,
        uint16_t *free_space)
 {
-       uint16_t i;
+       uint16_t first;
 
        if (unlikely(nb > ring->free_space))
                return 0;
 
-       for (i = 0; i < nb; i++) {
-               ring->cntx_idx_ring[ring->tail] = elem[i];
-               ring->tail = (ring->tail + 1) &
-                       (DPAA2_QDMA_MAX_DESC - 1);
-       }
+       first = RTE_MIN(nb, (uint16_t)(DPAA2_QDMA_MAX_DESC - ring->tail));
+       rte_memcpy(&ring->cntx_idx_ring[ring->tail], elem,
+               first * sizeof(uint16_t));
+       if (nb > first)
+               rte_memcpy(&ring->cntx_idx_ring[0], &elem[first],
+                       (nb - first) * sizeof(uint16_t));
+
+       ring->tail = (ring->tail + nb) & (DPAA2_QDMA_MAX_DESC - 1);
        ring->free_space -= nb;
        ring->nb_in_ring += nb;
 
@@ -935,35 +938,26 @@ dpaa2_qdma_dq_fd(const struct qbman_fd *fd,
        enum dpaa2_qdma_fd_type type;
        int ret;
        struct qdma_cntx_sg *cntx_sg;
-       struct qdma_cntx_fle_sdd *fle_sdd;
+       struct qdma_cntx_fle_sdd *fle_sdd = NULL;
 
        att = dpaa2_qdma_fd_get_att(fd);
        type = DPAA2_QDMA_FD_ATT_TYPE(att);
-       if (type == DPAA2_QDMA_FD_SHORT) {
-               idx = DPAA2_QDMA_FD_ATT_CNTX(att);
-               ret = qdma_cntx_idx_ring_eq(qdma_vq->ring_cntx_idx,
-                               &idx, 1, free_space);
-               if (unlikely(ret != 1))
-                       return -ENOSPC;
-
-               return 0;
-       }
-       if (type == DPAA2_QDMA_FD_LONG) {
-               idx = DPAA2_QDMA_FD_ATT_CNTX(att);
+       if (type == DPAA2_QDMA_FD_LONG || type == DPAA2_QDMA_FD_SG) {
                fle_sdd = (void *)(uintptr_t)DPAA2_GET_FD_FLC(fd);
                qdma_vq->fle_elem[*fle_elem_nb] = fle_sdd;
                (*fle_elem_nb)++;
+       }
+       if (type == DPAA2_QDMA_FD_SHORT ||
+               type == DPAA2_QDMA_FD_LONG) {
+               idx = DPAA2_QDMA_FD_ATT_CNTX(att);
                ret = qdma_cntx_idx_ring_eq(qdma_vq->ring_cntx_idx,
-                               &idx, 1, free_space);
+                       &idx, 1, free_space);
                if (unlikely(ret != 1))
                        return -ENOSPC;
 
                return 0;
        }
        if (type == DPAA2_QDMA_FD_SG) {
-               fle_sdd = (void *)(uintptr_t)DPAA2_GET_FD_FLC(fd);
-               qdma_vq->fle_elem[*fle_elem_nb] = fle_sdd;
-               (*fle_elem_nb)++;
                cntx_sg = container_of(fle_sdd,
                                struct qdma_cntx_sg, fle_sdd);
                ret = qdma_cntx_idx_ring_eq(qdma_vq->ring_cntx_idx,
-- 
2.43.0

Reply via email to