1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-16 08:12:53 +08:00

modules/mqnic: Clean up ring allocation error handling

Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
Alex Forencich 2022-08-15 23:50:36 -07:00
parent 338457cd75
commit c5efd8ff0a
4 changed files with 44 additions and 40 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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,