diff --git a/modules/mqnic/mqnic_cq.c b/modules/mqnic/mqnic_cq.c index 372f2973d..8ce786dc4 100644 --- a/modules/mqnic/mqnic_cq.c +++ b/modules/mqnic/mqnic_cq.c @@ -78,6 +78,9 @@ void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr) int mqnic_alloc_cq_ring(struct mqnic_cq_ring *ring, int size, int stride) { + if (ring->active || ring->buf) + return -EINVAL; + ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; ring->stride = roundup_pow_of_two(stride); @@ -110,12 +113,11 @@ void mqnic_free_cq_ring(struct mqnic_cq_ring *ring) { mqnic_deactivate_cq_ring(ring); - if (!ring->buf) - return; - - dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - ring->buf = NULL; - ring->buf_dma_addr = 0; + if (ring->buf) { + dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + } } int mqnic_activate_cq_ring(struct mqnic_cq_ring *ring, struct mqnic_eq_ring *eq_ring) diff --git a/modules/mqnic/mqnic_eq.c b/modules/mqnic/mqnic_eq.c index 5612ff7f3..1f5127b5e 100644 --- a/modules/mqnic/mqnic_eq.c +++ b/modules/mqnic/mqnic_eq.c @@ -90,6 +90,9 @@ void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr) int mqnic_alloc_eq_ring(struct mqnic_eq_ring *ring, int size, int stride) { + if (ring->active || ring->buf) + return -EINVAL; + ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; ring->stride = roundup_pow_of_two(stride); @@ -122,12 +125,11 @@ void mqnic_free_eq_ring(struct mqnic_eq_ring *ring) { mqnic_deactivate_eq_ring(ring); - if (!ring->buf) - return; - - dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - ring->buf = NULL; - ring->buf_dma_addr = 0; + if (ring->buf) { + dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + } } int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, struct mqnic_irq *irq) diff --git a/modules/mqnic/mqnic_rx.c b/modules/mqnic/mqnic_rx.c index 729d62ed8..678c295c9 100644 --- a/modules/mqnic/mqnic_rx.c +++ b/modules/mqnic/mqnic_rx.c @@ -79,7 +79,7 @@ void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr) int mqnic_alloc_rx_ring(struct mqnic_ring *ring, int size, int stride) { - int ret; + int ret = 0; if (ring->active || ring->buf) return -EINVAL; @@ -100,7 +100,7 @@ int mqnic_alloc_rx_ring(struct mqnic_ring *ring, int size, int stride) ring->buf = dma_alloc_coherent(ring->dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); if (!ring->buf) { ret = -ENOMEM; - goto fail_info; + goto fail; } ring->head_ptr = 0; @@ -123,9 +123,8 @@ int mqnic_alloc_rx_ring(struct mqnic_ring *ring, int size, int stride) return 0; -fail_info: - kvfree(ring->rx_info); - ring->rx_info = NULL; +fail: + mqnic_free_rx_ring(ring); return ret; } @@ -133,17 +132,18 @@ void mqnic_free_rx_ring(struct mqnic_ring *ring) { mqnic_deactivate_rx_ring(ring); - if (!ring->buf) - return; + if (ring->buf) { + mqnic_free_rx_buf(ring); - mqnic_free_rx_buf(ring); + dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + } - dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - ring->buf = NULL; - ring->buf_dma_addr = 0; - - kvfree(ring->rx_info); - ring->rx_info = NULL; + if (ring->rx_info) { + kvfree(ring->rx_info); + ring->rx_info = NULL; + } } int mqnic_activate_rx_ring(struct mqnic_ring *ring, struct mqnic_priv *priv, diff --git a/modules/mqnic/mqnic_tx.c b/modules/mqnic/mqnic_tx.c index b69a73f93..627aae22a 100644 --- a/modules/mqnic/mqnic_tx.c +++ b/modules/mqnic/mqnic_tx.c @@ -80,7 +80,7 @@ void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr) int mqnic_alloc_tx_ring(struct mqnic_ring *ring, int size, int stride) { - int ret; + int ret = 0; if (ring->active || ring->buf) return -EINVAL; @@ -102,7 +102,7 @@ int mqnic_alloc_tx_ring(struct mqnic_ring *ring, int size, int stride) ring->buf = dma_alloc_coherent(ring->dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); if (!ring->buf) { ret = -ENOMEM; - goto fail_info; + goto fail; } ring->head_ptr = 0; @@ -125,9 +125,8 @@ int mqnic_alloc_tx_ring(struct mqnic_ring *ring, int size, int stride) return 0; -fail_info: - kvfree(ring->tx_info); - ring->tx_info = NULL; +fail: + mqnic_free_tx_ring(ring); return ret; } @@ -135,17 +134,18 @@ void mqnic_free_tx_ring(struct mqnic_ring *ring) { mqnic_deactivate_tx_ring(ring); - if (!ring->buf) - return; + if (ring->buf) { + mqnic_free_tx_buf(ring); - mqnic_free_tx_buf(ring); + dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + } - dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - ring->buf = NULL; - ring->buf_dma_addr = 0; - - kvfree(ring->tx_info); - ring->tx_info = NULL; + if (ring->tx_info) { + kvfree(ring->tx_info); + ring->tx_info = NULL; + } } int mqnic_activate_tx_ring(struct mqnic_ring *ring, struct mqnic_priv *priv,