net/bnxt: validate structs and pointers before use

Validate pointers aren't pointing to uninitialized areas
including txq and rxq before using them to avoid
bnxt driver from crashing.

Signed-off-by: Rahul Gupta <rahul.gupta@broadcom.com>
Signed-off-by: Jay Ding <jay.ding@broadcom.com>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
Tested-by: Randy Schacher <stuart.schacher@broadcom.com>
This commit is contained in:
Rahul Gupta 2018-04-30 18:06:09 -07:00 committed by Ferruh Yigit
parent a42b152aba
commit f7b36e8f36
3 changed files with 10 additions and 8 deletions

View File

@ -24,6 +24,9 @@
void bnxt_free_ring(struct bnxt_ring *ring)
{
if (!ring)
return;
if (ring->vmem_size && *ring->vmem) {
memset((char *)*ring->vmem, 0, ring->vmem_size);
*ring->vmem = NULL;

View File

@ -23,10 +23,8 @@
void bnxt_free_rxq_stats(struct bnxt_rx_queue *rxq)
{
struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
if (cpr->hw_stats)
cpr->hw_stats = NULL;
if (rxq && rxq->cp_ring && rxq->cp_ring->hw_stats)
rxq->cp_ring->hw_stats = NULL;
}
int bnxt_mq_rx_configure(struct bnxt *bp)

View File

@ -19,10 +19,8 @@
void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
{
struct bnxt_cp_ring_info *cpr = txq->cp_ring;
if (cpr->hw_stats)
cpr->hw_stats = NULL;
if (txq && txq->cp_ring && txq->cp_ring->hw_stats)
txq->cp_ring->hw_stats = NULL;
}
static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
@ -30,6 +28,9 @@ static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
struct bnxt_sw_tx_bd *sw_ring;
uint16_t i;
if (!txq)
return;
sw_ring = txq->tx_ring->tx_buf_ring;
if (sw_ring) {
for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {