net/iavf: fix mbuf leak
authorQiming Chen <chenqiming_huawei@163.com>
Thu, 16 Sep 2021 14:04:00 +0000 (22:04 +0800)
committerQi Zhang <qi.z.zhang@intel.com>
Wed, 22 Sep 2021 07:05:50 +0000 (09:05 +0200)
In the iavf_dev_rx_queue_start function, if the iavf_switch_queue
or iavf_switch_queue_lv function fails, the previously applied mbuf
is not released, resulting in leakage. The patch fixes the problem.

Fixes: 9cf9c02bf6ee ("net/iavf: add enable/disable queues for large VF")
Cc: stable@dpdk.org
Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
drivers/net/iavf/iavf_rxtx.c

index 6de8ad3..87afc0b 100644 (file)
@@ -278,11 +278,15 @@ alloc_rxq_mbufs(struct iavf_rx_queue *rxq)
        volatile union iavf_rx_desc *rxd;
        struct rte_mbuf *mbuf = NULL;
        uint64_t dma_addr;
-       uint16_t i;
+       uint16_t i, j;
 
        for (i = 0; i < rxq->nb_rx_desc; i++) {
                mbuf = rte_mbuf_raw_alloc(rxq->mp);
                if (unlikely(!mbuf)) {
+                       for (j = 0; j < i; j++) {
+                               rte_pktmbuf_free_seg(rxq->sw_ring[j]);
+                               rxq->sw_ring[j] = NULL;
+                       }
                        PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
                        return -ENOMEM;
                }
@@ -852,12 +856,14 @@ iavf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
        else
                err = iavf_switch_queue_lv(adapter, rx_queue_id, true, true);
 
-       if (err)
+       if (err) {
+               release_rxq_mbufs(rxq);
                PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
                            rx_queue_id);
-       else
+       } else {
                dev->data->rx_queue_state[rx_queue_id] =
                        RTE_ETH_QUEUE_STATE_STARTED;
+       }
 
        return err;
 }