net/hinic: fix queues resource free
[dpdk.git] / drivers / net / hinic / hinic_pmd_tx.c
index 64ec2c1..996e0b2 100644 (file)
@@ -16,6 +16,7 @@
 #include "base/hinic_pmd_hwif.h"
 #include "base/hinic_pmd_wq.h"
 #include "base/hinic_pmd_nicio.h"
+#include "base/hinic_pmd_niccfg.h"
 #include "hinic_pmd_ethdev.h"
 #include "hinic_pmd_tx.h"
 
@@ -333,7 +334,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
                i = 0;
                for (sge_idx = sges; (u64)sge_idx <= txq->sq_bot_sge_addr;
                     sge_idx++) {
+                       if (unlikely(mbuf == NULL)) {
+                               txq->txq_stats.mbuf_null++;
+                               return false;
+                       }
+
                        dma_addr = rte_mbuf_data_iova(mbuf);
+                       if (unlikely(mbuf->data_len == 0)) {
+                               txq->txq_stats.sge_len0++;
+                               return false;
+                       }
                        hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
                                      mbuf->data_len);
                        mbuf = mbuf->next;
@@ -344,7 +354,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
                sge_idx = (struct hinic_sq_bufdesc *)
                                ((void *)txq->sq_head_addr);
                for (; i < nb_segs; i++) {
+                       if (unlikely(mbuf == NULL)) {
+                               txq->txq_stats.mbuf_null++;
+                               return false;
+                       }
+
                        dma_addr = rte_mbuf_data_iova(mbuf);
+                       if (unlikely(mbuf->data_len == 0)) {
+                               txq->txq_stats.sge_len0++;
+                               return false;
+                       }
                        hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
                                      mbuf->data_len);
                        mbuf = mbuf->next;
@@ -356,7 +375,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
        } else {
                /* wqe is in continuous space */
                for (i = 0; i < nb_segs; i++) {
+                       if (unlikely(mbuf == NULL)) {
+                               txq->txq_stats.mbuf_null++;
+                               return false;
+                       }
+
                        dma_addr = rte_mbuf_data_iova(mbuf);
+                       if (unlikely(mbuf->data_len == 0)) {
+                               txq->txq_stats.sge_len0++;
+                               return false;
+                       }
                        hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
                                      mbuf->data_len);
                        mbuf = mbuf->next;
@@ -377,6 +405,10 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
 
                /* deal with the last mbuf */
                dma_addr = rte_mbuf_data_iova(mbuf);
+               if (unlikely(mbuf->data_len == 0)) {
+                       txq->txq_stats.sge_len0++;
+                       return false;
+               }
                hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
                              mbuf->data_len);
                if (unlikely(sqe_info->around))
@@ -1185,7 +1217,8 @@ void hinic_free_all_tx_resources(struct rte_eth_dev *eth_dev)
                                HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
 
        for (q_id = 0; q_id < nic_dev->num_sq; q_id++) {
-               eth_dev->data->tx_queues[q_id] = NULL;
+               if (eth_dev->data->tx_queues != NULL)
+                       eth_dev->data->tx_queues[q_id] = NULL;
 
                if (nic_dev->txqs[q_id] == NULL)
                        continue;