[v2,6/6] net/bnxt: fix potential NULL pointer dereference
diff mbox series

Message ID 20191113150700.2517-7-ajit.khaparde@broadcom.com
State Accepted, archived
Delegated to: Ajit Khaparde
Headers show
Series
  • bnxt patchset with bug fixes
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Ajit Khaparde Nov. 13, 2019, 3:07 p.m. UTC
Null-checking "rxq" suggests that it may be null, but it has already
been dereferenced on all paths leading to the check.
Refactored the code to address this issue.

Coverity issue: 350594
Fixes: fc4bfea59696 ("net/bnxt: fix Rx queue start/stop for Thor based NICs")

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
---
 drivers/net/bnxt/bnxt_rxq.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/bnxt/bnxt_rxq.c b/drivers/net/bnxt/bnxt_rxq.c
index 7fd079da3..94f105d34 100644
--- a/drivers/net/bnxt/bnxt_rxq.c
+++ b/drivers/net/bnxt/bnxt_rxq.c
@@ -515,13 +515,18 @@  int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	}
 
 	rxq = bp->rx_queues[rx_queue_id];
-	vnic = rxq->vnic;
-
-	if (!rxq || !vnic) {
+	if (!rxq) {
 		PMD_DRV_LOG(ERR, "Invalid Rx queue %d\n", rx_queue_id);
 		return -EINVAL;
 	}
 
+	vnic = rxq->vnic;
+	if (!vnic) {
+		PMD_DRV_LOG(ERR, "VNIC not initialized for RxQ %d\n",
+			    rx_queue_id);
+		return -EINVAL;
+	}
+
 	dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
 	rxq->rx_started = false;
 	PMD_DRV_LOG(DEBUG, "Rx queue stopped\n");