net/bnxt: fix accessing variable before null check
authorKalesh AP <kalesh-anakkur.purayil@broadcom.com>
Wed, 2 Oct 2019 17:17:41 +0000 (10:17 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 8 Oct 2019 10:14:30 +0000 (12:14 +0200)
Check input argument "rxq" in bnxt_rx_queue_release_mbufs(), to be sure
variable is not NULL before accessing it.

Fixes: 9b63c6fd70e3 ("net/bnxt: support Rx/Tx queue start/stop")
Cc: stable@dpdk.org
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Santoshkumar Karanappa Rastapur <santosh.rastapur@broadcom.com>
drivers/net/bnxt/bnxt_rxq.c

index 4b506f8..dac8ccb 100644 (file)
@@ -207,39 +207,40 @@ void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
        struct bnxt_tpa_info *tpa_info;
        uint16_t i;
 
+       if (!rxq)
+               return;
+
        rte_spinlock_lock(&rxq->lock);
 
-       if (rxq) {
-               sw_ring = rxq->rx_ring->rx_buf_ring;
-               if (sw_ring) {
-                       for (i = 0;
-                            i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
-                               if (sw_ring[i].mbuf) {
-                                       rte_pktmbuf_free_seg(sw_ring[i].mbuf);
-                                       sw_ring[i].mbuf = NULL;
-                               }
+       sw_ring = rxq->rx_ring->rx_buf_ring;
+       if (sw_ring) {
+               for (i = 0;
+                    i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
+                       if (sw_ring[i].mbuf) {
+                               rte_pktmbuf_free_seg(sw_ring[i].mbuf);
+                               sw_ring[i].mbuf = NULL;
                        }
                }
-               /* Free up mbufs in Agg ring */
-               sw_ring = rxq->rx_ring->ag_buf_ring;
-               if (sw_ring) {
-                       for (i = 0;
-                            i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
-                               if (sw_ring[i].mbuf) {
-                                       rte_pktmbuf_free_seg(sw_ring[i].mbuf);
-                                       sw_ring[i].mbuf = NULL;
-                               }
+       }
+       /* Free up mbufs in Agg ring */
+       sw_ring = rxq->rx_ring->ag_buf_ring;
+       if (sw_ring) {
+               for (i = 0;
+                    i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
+                       if (sw_ring[i].mbuf) {
+                               rte_pktmbuf_free_seg(sw_ring[i].mbuf);
+                               sw_ring[i].mbuf = NULL;
                        }
                }
+       }
 
-               /* Free up mbufs in TPA */
-               tpa_info = rxq->rx_ring->tpa_info;
-               if (tpa_info) {
-                       for (i = 0; i < BNXT_TPA_MAX; i++) {
-                               if (tpa_info[i].mbuf) {
-                                       rte_pktmbuf_free_seg(tpa_info[i].mbuf);
-                                       tpa_info[i].mbuf = NULL;
-                               }
+       /* Free up mbufs in TPA */
+       tpa_info = rxq->rx_ring->tpa_info;
+       if (tpa_info) {
+               for (i = 0; i < BNXT_TPA_MAX; i++) {
+                       if (tpa_info[i].mbuf) {
+                               rte_pktmbuf_free_seg(tpa_info[i].mbuf);
+                               tpa_info[i].mbuf = NULL;
                        }
                }
        }