Don't destroy bus_dma maps created by bus_dmamem_alloc(). In some cases,

don't create a map before calling bus_dmamem_alloc() (such maps were
leaked).  It is believed that the extra destroy of the map was generally
harmless since bus_dmamem_alloc() often uses special maps for which
bus_dmamap_destroy() is a no-op (e.g. on x86).

Reviewed by:	scottl
This commit is contained in:
John Baldwin 2014-06-10 20:25:45 +00:00
parent 5ebc578ba6
commit f07894dbde
16 changed files with 18 additions and 118 deletions

View File

@ -363,8 +363,6 @@ versatile_clcdc_attach(device_t dev)
fail:
if (sc->fb_base)
bus_dmamem_free(sc->dma_tag, sc->fb_base, sc->dma_map);
if (sc->dma_map)
bus_dmamap_destroy(sc->dma_tag, sc->dma_map);
if (sc->dma_tag)
bus_dma_tag_destroy(sc->dma_tag);
return (err);

View File

@ -777,7 +777,6 @@ adw_free(struct adw_softc *adw)
case 7:
bus_dmamem_free(adw->acb_dmat, adw->acbs,
adw->acb_dmamap);
bus_dmamap_destroy(adw->acb_dmat, adw->acb_dmamap);
case 6:
bus_dma_tag_destroy(adw->acb_dmat);
case 5:
@ -785,7 +784,6 @@ adw_free(struct adw_softc *adw)
case 4:
bus_dmamem_free(adw->carrier_dmat, adw->carriers,
adw->carrier_dmamap);
bus_dmamap_destroy(adw->carrier_dmat, adw->carrier_dmamap);
case 3:
bus_dma_tag_destroy(adw->carrier_dmat);
case 2:

View File

@ -483,10 +483,6 @@ an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
{
int r;
r = bus_dmamap_create(sc->an_dtag, BUS_DMA_NOWAIT, &dma->an_dma_map);
if (r != 0)
goto fail_0;
r = bus_dmamem_alloc(sc->an_dtag, (void**) &dma->an_dma_vaddr,
BUS_DMA_NOWAIT, &dma->an_dma_map);
if (r != 0)
@ -507,9 +503,6 @@ an_dma_malloc(struct an_softc *sc, bus_size_t size, struct an_dma_alloc *dma,
bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
fail_1:
bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
fail_0:
bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
dma->an_dma_map = NULL;
return (r);
}
@ -519,7 +512,6 @@ an_dma_free(struct an_softc *sc, struct an_dma_alloc *dma)
bus_dmamap_unload(sc->an_dtag, dma->an_dma_map);
bus_dmamem_free(sc->an_dtag, dma->an_dma_vaddr, dma->an_dma_map);
dma->an_dma_vaddr = 0;
bus_dmamap_destroy(sc->an_dtag, dma->an_dma_map);
}
/*

View File

@ -224,11 +224,9 @@ ata_dmafree(device_t dev)
bus_dmamap_unload(slot->sg_tag, slot->sg_map);
slot->sg_bus = 0;
}
if (slot->sg_map) {
if (slot->sg) {
bus_dmamem_free(slot->sg_tag, slot->sg, slot->sg_map);
bus_dmamap_destroy(slot->sg_tag, slot->sg_map);
slot->sg = NULL;
slot->sg_map = NULL;
}
if (slot->data_map) {
bus_dmamap_destroy(slot->data_tag, slot->data_map);

View File

@ -246,7 +246,6 @@ bt_free_softc(device_t dev)
case 6:
bus_dmamem_free(bt->ccb_dmat, bt->bt_ccb_array,
bt->ccb_dmamap);
bus_dmamap_destroy(bt->ccb_dmat, bt->ccb_dmamap);
/* FALLTHROUGH */
case 5:
bus_dma_tag_destroy(bt->ccb_dmat);
@ -257,7 +256,6 @@ bt_free_softc(device_t dev)
case 3:
bus_dmamem_free(bt->mailbox_dmat, bt->in_boxes,
bt->mailbox_dmamap);
bus_dmamap_destroy(bt->mailbox_dmat, bt->mailbox_dmamap);
/* FALLTHROUGH */
case 2:
bus_dma_tag_destroy(bt->buffer_dmat);

View File

@ -1149,7 +1149,6 @@ dpt_free(struct dpt_softc *dpt)
case 4:
bus_dmamem_free(dpt->dccb_dmat, dpt->dpt_dccbs,
dpt->dccb_dmamap);
bus_dmamap_destroy(dpt->dccb_dmat, dpt->dccb_dmamap);
case 3:
bus_dma_tag_destroy(dpt->dccb_dmat);
case 2:

View File

@ -463,7 +463,6 @@ hifn_attach(device_t dev)
BUS_DMA_NOWAIT)) {
device_printf(dev, "cannot load dma map\n");
bus_dmamem_free(sc->sc_dmat, kva, sc->sc_dmamap);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
bus_dma_tag_destroy(sc->sc_dmat);
goto fail_io1;
}
@ -603,7 +602,6 @@ hifn_attach(device_t dev)
fail_mem:
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
bus_dmamem_free(sc->sc_dmat, sc->sc_dma, sc->sc_dmamap);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
bus_dma_tag_destroy(sc->sc_dmat);
/* Turn off DMA polling */
@ -653,7 +651,6 @@ hifn_detach(device_t dev)
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
bus_dmamem_free(sc->sc_dmat, sc->sc_dma, sc->sc_dmamap);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
bus_dma_tag_destroy(sc->sc_dmat);
bus_release_resource(dev, SYS_RES_MEMORY, HIFN_BAR1, sc->sc_bar1res);

View File

@ -496,13 +496,6 @@ malo_desc_setup(struct malo_softc *sc, const char *name,
}
/* allocate descriptors */
error = bus_dmamap_create(dd->dd_dmat, BUS_DMA_NOWAIT, &dd->dd_dmamap);
if (error != 0) {
if_printf(ifp, "unable to create dmamap for %s descriptors, "
"error %u\n", dd->dd_name, error);
goto fail0;
}
error = bus_dmamem_alloc(dd->dd_dmat, (void**) &dd->dd_desc,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dd->dd_dmamap);
if (error != 0) {
@ -530,8 +523,6 @@ malo_desc_setup(struct malo_softc *sc, const char *name,
fail2:
bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
fail1:
bus_dmamap_destroy(dd->dd_dmat, dd->dd_dmamap);
fail0:
bus_dma_tag_destroy(dd->dd_dmat);
memset(dd, 0, sizeof(*dd));
return error;
@ -632,7 +623,6 @@ malo_desc_cleanup(struct malo_softc *sc, struct malo_descdma *dd)
{
bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
bus_dmamap_destroy(dd->dd_dmat, dd->dd_dmamap);
bus_dma_tag_destroy(dd->dd_dmat);
memset(dd, 0, sizeof(*dd));

View File

@ -137,13 +137,6 @@ malo_hal_attach(device_t dev, uint16_t devid,
}
/* allocate descriptors */
error = bus_dmamap_create(mh->mh_dmat, BUS_DMA_NOWAIT, &mh->mh_dmamap);
if (error != 0) {
device_printf(dev, "unable to create dmamap for cmd buffers, "
"error %u\n", error);
goto fail;
}
error = bus_dmamem_alloc(mh->mh_dmat, (void**) &mh->mh_cmdbuf,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
&mh->mh_dmamap);
@ -166,13 +159,9 @@ malo_hal_attach(device_t dev, uint16_t devid,
return (mh);
fail:
if (mh->mh_dmamap != NULL) {
bus_dmamap_unload(mh->mh_dmat, mh->mh_dmamap);
if (mh->mh_cmdbuf != NULL)
bus_dmamem_free(mh->mh_dmat, mh->mh_cmdbuf,
mh->mh_dmamap);
bus_dmamap_destroy(mh->mh_dmat, mh->mh_dmamap);
}
if (mh->mh_cmdbuf != NULL)
bus_dmamem_free(mh->mh_dmat, mh->mh_cmdbuf,
mh->mh_dmamap);
if (mh->mh_dmat)
bus_dma_tag_destroy(mh->mh_dmat);
free(mh, M_DEVBUF);
@ -592,7 +581,6 @@ malo_hal_detach(struct malo_hal *mh)
{
bus_dmamem_free(mh->mh_dmat, mh->mh_cmdbuf, mh->mh_dmamap);
bus_dmamap_destroy(mh->mh_dmat, mh->mh_dmamap);
bus_dma_tag_destroy(mh->mh_dmat);
mtx_destroy(&mh->mh_mtx);
free(mh, M_DEVBUF);

View File

@ -2041,13 +2041,6 @@ mwl_desc_setup(struct mwl_softc *sc, const char *name,
}
/* allocate descriptors */
error = bus_dmamap_create(dd->dd_dmat, BUS_DMA_NOWAIT, &dd->dd_dmamap);
if (error != 0) {
if_printf(ifp, "unable to create dmamap for %s descriptors, "
"error %u\n", dd->dd_name, error);
goto fail0;
}
error = bus_dmamem_alloc(dd->dd_dmat, (void**) &dd->dd_desc,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
&dd->dd_dmamap);
@ -2077,8 +2070,6 @@ mwl_desc_setup(struct mwl_softc *sc, const char *name,
fail2:
bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
fail1:
bus_dmamap_destroy(dd->dd_dmat, dd->dd_dmamap);
fail0:
bus_dma_tag_destroy(dd->dd_dmat);
memset(dd, 0, sizeof(*dd));
return error;
@ -2090,7 +2081,6 @@ mwl_desc_cleanup(struct mwl_softc *sc, struct mwl_descdma *dd)
{
bus_dmamap_unload(dd->dd_dmat, dd->dd_dmamap);
bus_dmamem_free(dd->dd_dmat, dd->dd_desc, dd->dd_dmamap);
bus_dmamap_destroy(dd->dd_dmat, dd->dd_dmamap);
bus_dma_tag_destroy(dd->dd_dmat);
memset(dd, 0, sizeof(*dd));
@ -2229,9 +2219,8 @@ mwl_rxdma_setup(struct mwl_softc *sc)
NULL, /* lockfunc */
NULL, /* lockarg */
&sc->sc_rxdmat);
error = bus_dmamap_create(sc->sc_rxdmat, BUS_DMA_NOWAIT, &sc->sc_rxmap);
if (error != 0) {
if_printf(ifp, "could not create rx DMA map\n");
if_printf(ifp, "could not create rx DMA tag\n");
return error;
}
@ -2292,16 +2281,14 @@ mwl_rxdma_setup(struct mwl_softc *sc)
static void
mwl_rxdma_cleanup(struct mwl_softc *sc)
{
if (sc->sc_rxmap != NULL)
if (sc->sc_rxmem_paddr != 0) {
bus_dmamap_unload(sc->sc_rxdmat, sc->sc_rxmap);
sc->sc_rxmem_paddr = 0;
}
if (sc->sc_rxmem != NULL) {
bus_dmamem_free(sc->sc_rxdmat, sc->sc_rxmem, sc->sc_rxmap);
sc->sc_rxmem = NULL;
}
if (sc->sc_rxmap != NULL) {
bus_dmamap_destroy(sc->sc_rxdmat, sc->sc_rxmap);
sc->sc_rxmap = NULL;
}
if (sc->sc_rxdma.dd_bufptr != NULL) {
free(sc->sc_rxdma.dd_bufptr, M_MWLDEV);
sc->sc_rxdma.dd_bufptr = NULL;

View File

@ -309,19 +309,12 @@ mwl_hal_attach(device_t dev, uint16_t devid,
NULL, /* lockarg */
&mh->mh_dmat);
if (error != 0) {
device_printf(dev, "unable to allocate memory for cmd buffer, "
device_printf(dev, "unable to allocate memory for cmd tag, "
"error %u\n", error);
goto fail0;
}
/* allocate descriptors */
error = bus_dmamap_create(mh->mh_dmat, BUS_DMA_NOWAIT, &mh->mh_dmamap);
if (error != 0) {
device_printf(dev, "unable to create dmamap for cmd buffers, "
"error %u\n", error);
goto fail0;
}
error = bus_dmamem_alloc(mh->mh_dmat, (void**) &mh->mh_cmdbuf,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
&mh->mh_dmamap);
@ -365,9 +358,8 @@ mwl_hal_attach(device_t dev, uint16_t devid,
fail2:
bus_dmamem_free(mh->mh_dmat, mh->mh_cmdbuf, mh->mh_dmamap);
fail1:
bus_dmamap_destroy(mh->mh_dmat, mh->mh_dmamap);
fail0:
bus_dma_tag_destroy(mh->mh_dmat);
fail0:
mtx_destroy(&mh->mh_mtx);
free(mh, M_DEVBUF);
return NULL;
@ -379,7 +371,6 @@ mwl_hal_detach(struct mwl_hal *mh0)
struct mwl_hal_priv *mh = MWLPRIV(mh0);
bus_dmamem_free(mh->mh_dmat, mh->mh_cmdbuf, mh->mh_dmamap);
bus_dmamap_destroy(mh->mh_dmat, mh->mh_dmamap);
bus_dma_tag_destroy(mh->mh_dmat);
mtx_destroy(&mh->mh_mtx);
free(mh, M_DEVBUF);

View File

@ -1807,20 +1807,13 @@ safe_dma_malloc(
goto fail_0;
}
r = bus_dmamap_create(dma->dma_tag, BUS_DMA_NOWAIT, &dma->dma_map);
if (r != 0) {
device_printf(sc->sc_dev, "safe_dma_malloc: "
"bus_dmamap_create failed; error %u\n", r);
goto fail_1;
}
r = bus_dmamem_alloc(dma->dma_tag, (void**) &dma->dma_vaddr,
BUS_DMA_NOWAIT, &dma->dma_map);
if (r != 0) {
device_printf(sc->sc_dev, "safe_dma_malloc: "
"bus_dmammem_alloc failed; size %zu, error %u\n",
size, r);
goto fail_2;
goto fail_1;
}
r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
@ -1831,21 +1824,18 @@ safe_dma_malloc(
if (r != 0) {
device_printf(sc->sc_dev, "safe_dma_malloc: "
"bus_dmamap_load failed; error %u\n", r);
goto fail_3;
goto fail_2;
}
dma->dma_size = size;
return (0);
fail_3:
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
fail_2:
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
fail_1:
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
bus_dma_tag_destroy(dma->dma_tag);
fail_0:
dma->dma_map = NULL;
dma->dma_tag = NULL;
return (r);
}
@ -1855,7 +1845,6 @@ safe_dma_free(struct safe_softc *sc, struct safe_dma_alloc *dma)
{
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
bus_dma_tag_destroy(dma->dma_tag);
}

View File

@ -617,11 +617,8 @@ static m_addr_t ___dma_getp(m_pool_s *mp)
bus_dmamap_unload(mp->dmat, vbp->dmamap);
if (vaddr)
bus_dmamem_free(mp->dmat, vaddr, vbp->dmamap);
if (vbp) {
if (vbp->dmamap)
bus_dmamap_destroy(mp->dmat, vbp->dmamap);
if (vbp)
__sym_mfree(&mp0, vbp, sizeof(*vbp), "VTOB");
}
return 0;
}
@ -639,7 +636,6 @@ static void ___dma_freep(m_pool_s *mp, m_addr_t m)
*vbpp = (*vbpp)->next;
bus_dmamap_unload(mp->dmat, vbp->dmamap);
bus_dmamem_free(mp->dmat, (void *) vbp->vaddr, vbp->dmamap);
bus_dmamap_destroy(mp->dmat, vbp->dmamap);
__sym_mfree(&mp0, vbp, sizeof(*vbp), "VTOB");
--mp->nump;
}

View File

@ -2944,12 +2944,11 @@ trm_destroySRB(PACB pACB)
pSRB = pACB->pFreeSRB;
while (pSRB) {
if (pSRB->sg_dmamap) {
if (pSRB->SRBSGPhyAddr)
bus_dmamap_unload(pACB->sg_dmat, pSRB->sg_dmamap);
if (pSRB->pSRBSGL)
bus_dmamem_free(pACB->sg_dmat, pSRB->pSRBSGL,
pSRB->sg_dmamap);
bus_dmamap_destroy(pACB->sg_dmat, pSRB->sg_dmamap);
}
if (pSRB->dmamap)
bus_dmamap_destroy(pACB->buffer_dmat, pSRB->dmamap);
pSRB = pSRB->pNextSRB;
@ -3494,7 +3493,6 @@ trm_init(u_int16_t unit, device_t dev)
bus_dmamap_unload(pACB->sense_dmat, pACB->sense_dmamap);
bus_dmamem_free(pACB->sense_dmat, pACB->sense_buffers,
pACB->sense_dmamap);
bus_dmamap_destroy(pACB->sense_dmat, pACB->sense_dmamap);
}
if (pACB->sense_dmat)
bus_dma_tag_destroy(pACB->sense_dmat);
@ -3502,11 +3500,10 @@ trm_init(u_int16_t unit, device_t dev)
trm_destroySRB(pACB);
bus_dma_tag_destroy(pACB->sg_dmat);
}
if (pACB->srb_dmamap) {
if (pACB->pFreeSRB) {
bus_dmamap_unload(pACB->srb_dmat, pACB->srb_dmamap);
bus_dmamem_free(pACB->srb_dmat, pACB->pFreeSRB,
pACB->srb_dmamap);
bus_dmamap_destroy(pACB->srb_dmat, pACB->srb_dmamap);
}
if (pACB->srb_dmat)
bus_dma_tag_destroy(pACB->srb_dmat);
@ -3618,19 +3615,17 @@ trm_attach(device_t dev)
bus_dma_tag_destroy(pACB->sg_dmat);
}
if (pACB->srb_dmamap) {
if (pACB->pFreeSRB) {
bus_dmamap_unload(pACB->srb_dmat, pACB->srb_dmamap);
bus_dmamem_free(pACB->srb_dmat, pACB->pFreeSRB,
pACB->srb_dmamap);
bus_dmamap_destroy(pACB->srb_dmat, pACB->srb_dmamap);
}
if (pACB->srb_dmat)
bus_dma_tag_destroy(pACB->srb_dmat);
if (pACB->sense_dmamap) {
if (pACB->sense_buffers) {
bus_dmamap_unload(pACB->sense_dmat, pACB->sense_dmamap);
bus_dmamem_free(pACB->sense_dmat, pACB->sense_buffers,
pACB->sense_dmamap);
bus_dmamap_destroy(pACB->sense_dmat, pACB->sense_dmamap);
}
if (pACB->sense_dmat)
bus_dma_tag_destroy(pACB->sense_dmat);
@ -3680,12 +3675,10 @@ trm_detach(device_t dev)
bus_dmamap_unload(pACB->srb_dmat, pACB->srb_dmamap);
bus_dmamem_free(pACB->srb_dmat, pACB->pFreeSRB,
pACB->srb_dmamap);
bus_dmamap_destroy(pACB->srb_dmat, pACB->srb_dmamap);
bus_dma_tag_destroy(pACB->srb_dmat);
bus_dmamap_unload(pACB->sense_dmat, pACB->sense_dmamap);
bus_dmamem_free(pACB->sense_dmat, pACB->sense_buffers,
pACB->sense_dmamap);
bus_dmamap_destroy(pACB->sense_dmat, pACB->sense_dmamap);
bus_dma_tag_destroy(pACB->sense_dmat);
bus_dma_tag_destroy(pACB->buffer_dmat);
bus_teardown_intr(dev, pACB->irq, pACB->ih);

View File

@ -447,17 +447,14 @@ epic_release(epic_softc_t *sc)
if (sc->tx_flist) {
bus_dmamap_unload(sc->ftag, sc->fmap);
bus_dmamem_free(sc->ftag, sc->tx_flist, sc->fmap);
bus_dmamap_destroy(sc->ftag, sc->fmap);
}
if (sc->tx_desc) {
bus_dmamap_unload(sc->ttag, sc->tmap);
bus_dmamem_free(sc->ttag, sc->tx_desc, sc->tmap);
bus_dmamap_destroy(sc->ttag, sc->tmap);
}
if (sc->rx_desc) {
bus_dmamap_unload(sc->rtag, sc->rmap);
bus_dmamem_free(sc->rtag, sc->rx_desc, sc->rmap);
bus_dmamap_destroy(sc->rtag, sc->rmap);
}
if (sc->mtag)
bus_dma_tag_destroy(sc->mtag);

View File

@ -1856,13 +1856,6 @@ ubsec_dma_malloc(
if (r != 0) {
device_printf(sc->sc_dev, "ubsec_dma_malloc: "
"bus_dma_tag_create failed; error %u\n", r);
goto fail_0;
}
r = bus_dmamap_create(dma->dma_tag, BUS_DMA_NOWAIT, &dma->dma_map);
if (r != 0) {
device_printf(sc->sc_dev, "ubsec_dma_malloc: "
"bus_dmamap_create failed; error %u\n", r);
goto fail_1;
}
@ -1894,10 +1887,7 @@ ubsec_dma_malloc(
fail_2:
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
fail_1:
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
bus_dma_tag_destroy(dma->dma_tag);
fail_0:
dma->dma_map = NULL;
dma->dma_tag = NULL;
return (r);
}
@ -1907,7 +1897,6 @@ ubsec_dma_free(struct ubsec_softc *sc, struct ubsec_dma_alloc *dma)
{
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
bus_dma_tag_destroy(dma->dma_tag);
}