diff options
author | jhb <jhb@FreeBSD.org> | 2014-06-11 14:53:58 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2014-06-11 14:53:58 +0000 |
commit | e8769d6be243ea7d1540dd79d95893ea33393634 (patch) | |
tree | 5544dcfb2be4391a29657081ad30163d6c502e86 /sys/arm/cavium/cns11xx | |
parent | 60cbac59442236d3d8d9a9d3475a8b1b7421ae33 (diff) | |
download | FreeBSD-src-e8769d6be243ea7d1540dd79d95893ea33393634.zip FreeBSD-src-e8769d6be243ea7d1540dd79d95893ea33393634.tar.gz |
Fix various NIC drivers to properly cleanup static DMA resources.
In particular, don't check the value of the bus_dma map against NULL
to determine if either bus_dmamem_alloc() or bus_dmamap_load() succeeded.
Instead, assume that bus_dmamap_load() succeeeded (and thus that
bus_dmamap_unload() should be called) if the bus address for a resource
is non-zero, and assume that bus_dmamem_alloc() succeeded (and thus
that bus_dmamem_free() should be called) if the virtual address for a
resource is not NULL.
In many cases these bugs could result in leaks when a driver was detached.
Reviewed by: yongari
MFC after: 2 weeks
Diffstat (limited to 'sys/arm/cavium/cns11xx')
-rw-r--r-- | sys/arm/cavium/cns11xx/if_ece.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/sys/arm/cavium/cns11xx/if_ece.c b/sys/arm/cavium/cns11xx/if_ece.c index 657f6f3..0ba2d77 100644 --- a/sys/arm/cavium/cns11xx/if_ece.c +++ b/sys/arm/cavium/cns11xx/if_ece.c @@ -565,13 +565,15 @@ ece_free_desc_dma_tx(struct ece_softc *sc) } } - if (sc->dmamap_ring_tx) { + if (sc->ring_paddr_tx) { bus_dmamap_unload(sc->dmatag_data_tx, sc->dmamap_ring_tx); - if (sc->desc_tx) { - bus_dmamem_free(sc->dmatag_data_tx, - sc->desc_tx, sc->dmamap_ring_tx); - } - sc->dmamap_ring_tx = 0; + sc->ring_paddr_tx = 0; + } + + if (sc->desc_tx) { + bus_dmamem_free(sc->dmatag_data_tx, + sc->desc_tx, sc->dmamap_ring_tx); + sc->desc_tx = NULL; } if (sc->dmatag_data_tx) { @@ -679,18 +681,24 @@ ece_free_desc_dma_rx(struct ece_softc *sc) for (i = 0; i < ECE_MAX_RX_BUFFERS; i++) { if (sc->rx_desc[i].buff) { m_freem(sc->rx_desc[i].buff); - sc->rx_desc[i].buff= 0; + sc->rx_desc[i].buff = NULL; } } - if (sc->dmatag_data_rx) { + if (sc->ring_paddr_rx) { bus_dmamap_unload(sc->dmatag_data_rx, sc->dmamap_ring_rx); + sc->ring_paddr_rx = 0; + } + + if (sc->desc_rx) { bus_dmamem_free(sc->dmatag_data_rx, sc->desc_rx, sc->dmamap_ring_rx); + sc->desc_rx = NULL; + } + + if (sc->dmatag_data_rx) { bus_dma_tag_destroy(sc->dmatag_data_rx); - sc->dmatag_data_rx = 0; - sc->dmamap_ring_rx = 0; - sc->desc_rx = 0; + sc->dmatag_data_rx = NULL; } if (sc->dmatag_ring_rx) { @@ -699,7 +707,7 @@ ece_free_desc_dma_rx(struct ece_softc *sc) sc->rx_desc[i].dmamap); bus_dmamap_destroy(sc->dmatag_ring_rx, sc->rx_sparemap); bus_dma_tag_destroy(sc->dmatag_ring_rx); - sc->dmatag_ring_rx = 0; + sc->dmatag_ring_rx = NULL; } } |