Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is loaded or mapped, respectively. This is mandatory for some archs. See, e.g.: http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312 http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93 For some drivers, resource leaks for error paths are fixed at the same time. XXX XXX XXX Compile test only (at least one arch per driver).
This commit is contained in:
parent
a191b8c434
commit
aba664485b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_hvn.c,v 1.22 2022/05/20 13:55:17 nonaka Exp $ */
|
||||
/* $NetBSD: if_hvn.c,v 1.23 2022/05/29 10:43:45 rin Exp $ */
|
||||
/* $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $ */
|
||||
|
||||
/*-
|
||||
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.22 2022/05/20 13:55:17 nonaka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.23 2022/05/29 10:43:45 rin Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_if_hvn.h"
|
||||
|
@ -3997,10 +3997,11 @@ hvn_rndis_init(struct hvn_softc *sc)
|
|||
PAGE_SIZE, NULL, BUS_DMA_WAITOK)) {
|
||||
DPRINTF("%s: failed to load RNDIS command map\n",
|
||||
device_xname(sc->sc_dev));
|
||||
bus_dmamem_unmap(sc->sc_dmat, rc->rc_req, PAGE_SIZE);
|
||||
rc->rc_req = NULL;
|
||||
bus_dmamem_free(sc->sc_dmat, &rc->rc_segs,
|
||||
rc->rc_nsegs);
|
||||
bus_dmamap_destroy(sc->sc_dmat, rc->rc_dmap);
|
||||
rc->rc_req = NULL;
|
||||
goto errout;
|
||||
}
|
||||
rc->rc_gpa = atop(rc->rc_dmap->dm_segs[0].ds_addr);
|
||||
|
@ -4034,8 +4035,10 @@ hvn_rndis_destroy(struct hvn_softc *sc)
|
|||
continue;
|
||||
|
||||
TAILQ_REMOVE(&sc->sc_cntl_fq, rc, rc_entry);
|
||||
bus_dmamem_free(sc->sc_dmat, &rc->rc_segs, rc->rc_nsegs);
|
||||
bus_dmamap_unload(sc->sc_dmat, rc->rc_dmap);
|
||||
bus_dmamem_unmap(sc->sc_dmat, rc->rc_req, PAGE_SIZE);
|
||||
rc->rc_req = NULL;
|
||||
bus_dmamem_free(sc->sc_dmat, &rc->rc_segs, rc->rc_nsegs);
|
||||
bus_dmamap_destroy(sc->sc_dmat, rc->rc_dmap);
|
||||
mutex_destroy(&rc->rc_lock);
|
||||
cv_destroy(&rc->rc_cv);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ciss.c,v 1.53 2022/01/01 09:53:32 msaitoh Exp $ */
|
||||
/* $NetBSD: ciss.c,v 1.54 2022/05/29 10:43:46 rin Exp $ */
|
||||
/* $OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.53 2022/01/01 09:53:32 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.54 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include "bio.h"
|
||||
|
||||
|
@ -334,8 +334,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
if ((error = bus_dmamap_load(sc->sc_dmat, sc->cmdmap, sc->ccbs, total,
|
||||
NULL, BUS_DMA_NOWAIT))) {
|
||||
aprint_error(": cannot load CCBs dmamap (%d)\n", error);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -370,8 +370,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
aprint_error(": cannot create ccb#%d dmamap (%d)\n", i, error);
|
||||
if (i == 0) {
|
||||
/* TODO leaking cmd's dmamaps and shitz */
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -395,8 +395,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
if (ciss_inq(sc, inq)) {
|
||||
aprint_error(": adapter inquiry failed\n");
|
||||
mutex_exit(&sc->sc_mutex_scratch);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -404,8 +404,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
aprint_error(": big map is not supported, flags=0x%x\n",
|
||||
inq->flags);
|
||||
mutex_exit(&sc->sc_mutex_scratch);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -434,8 +434,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
/* map LDs */
|
||||
if (ciss_ldmap(sc)) {
|
||||
aprint_error_dev(sc->sc_dev, "adapter LD map failed\n");
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -446,8 +446,8 @@ ciss_attach(struct ciss_softc *sc)
|
|||
if (!(sc->sc_sh = shutdownhook_establish(ciss_shutdown, sc))) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to establish shutdown hook\n");
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->cmdmap);
|
||||
bus_dmamem_free(sc->sc_dmat, sc->cmdseg, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: elinkxl.c,v 1.138 2020/03/12 03:01:46 thorpej Exp $ */
|
||||
/* $NetBSD: elinkxl.c,v 1.139 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: elinkxl.c,v 1.138 2020/03/12 03:01:46 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: elinkxl.c,v 1.139 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -1598,10 +1598,10 @@ ex_stop(struct ifnet *ifp, int disable)
|
|||
for (tx = sc->tx_head ; tx != NULL; tx = tx->tx_next) {
|
||||
if (tx->tx_mbhead == NULL)
|
||||
continue;
|
||||
m_freem(tx->tx_mbhead);
|
||||
tx->tx_mbhead = NULL;
|
||||
bus_dmamap_unload(sc->sc_dmat, tx->tx_dmamap);
|
||||
tx->tx_dpd->dpd_fsh = tx->tx_dpd->dpd_nextptr = 0;
|
||||
m_freem(tx->tx_mbhead);
|
||||
tx->tx_mbhead = NULL;
|
||||
bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
|
||||
((char *)tx->tx_dpd - (char *)sc->sc_dpd),
|
||||
sizeof (struct ex_dpd),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: hme.c,v 1.108 2020/03/12 03:01:46 thorpej Exp $ */
|
||||
/* $NetBSD: hme.c,v 1.109 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
|
@ -34,7 +34,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.108 2020/03/12 03:01:46 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: hme.c,v 1.109 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
/* #define HMEDEBUG */
|
||||
|
||||
|
@ -198,16 +198,14 @@ hme_config(struct hme_softc *sc)
|
|||
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
||||
aprint_error_dev(sc->sc_dev, "DMA buffer map error %d\n",
|
||||
error);
|
||||
bus_dmamap_unload(dmatag, sc->sc_dmamap);
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
return;
|
||||
goto bad_free;
|
||||
}
|
||||
|
||||
if ((error = bus_dmamap_create(dmatag, size, 1, size, 0,
|
||||
BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
|
||||
aprint_error_dev(sc->sc_dev, "DMA map create error %d\n",
|
||||
error);
|
||||
return;
|
||||
goto bad_unmap;
|
||||
}
|
||||
|
||||
/* Load the buffer */
|
||||
|
@ -216,8 +214,7 @@ hme_config(struct hme_softc *sc)
|
|||
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
||||
aprint_error_dev(sc->sc_dev, "DMA buffer map load error %d\n",
|
||||
error);
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr;
|
||||
|
||||
|
@ -316,6 +313,15 @@ hme_config(struct hme_softc *sc)
|
|||
|
||||
callout_init(&sc->sc_tick_ch, 0);
|
||||
callout_setfunc(&sc->sc_tick_ch, hme_tick, sc);
|
||||
|
||||
return;
|
||||
|
||||
bad_destroy:
|
||||
bus_dmamap_destroy(dmatag, sc->sc_dmamap);
|
||||
bad_unmap:
|
||||
bus_dmamem_unmap(dmatag, sc->sc_rb.rb_membase, size);
|
||||
bad_free:
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: i82596.c,v 1.45 2021/11/10 17:19:30 msaitoh Exp $ */
|
||||
/* $NetBSD: i82596.c,v 1.46 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 Jochen Kunz.
|
||||
|
@ -43,7 +43,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: i82596.c,v 1.45 2021/11/10 17:19:30 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: i82596.c,v 1.46 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
/* autoconfig and device stuff */
|
||||
#include <sys/param.h>
|
||||
|
@ -330,10 +330,10 @@ iee_intr(void *intarg)
|
|||
if (sc->sc_next_tbd != 0) {
|
||||
/* A TX CMD list finished, cleanup */
|
||||
for (n = 0 ; n < sc->sc_next_cb ; n++) {
|
||||
m_freem(sc->sc_tx_mbuf[n]);
|
||||
sc->sc_tx_mbuf[n] = NULL;
|
||||
bus_dmamap_unload(sc->sc_dmat,
|
||||
sc->sc_tx_map[n]);
|
||||
m_freem(sc->sc_tx_mbuf[n]);
|
||||
sc->sc_tx_mbuf[n] = NULL;
|
||||
IEE_CBSYNC(sc, n,
|
||||
BUS_DMASYNC_POSTREAD |
|
||||
BUS_DMASYNC_POSTWRITE);
|
||||
|
@ -968,11 +968,11 @@ iee_init(struct ifnet *ifp)
|
|||
IEE_SWAPA32(IEE_PHYS_SHMEM(sc->sc_rbd_off));
|
||||
if (err != 0) {
|
||||
for (n = 0 ; n < r; n++) {
|
||||
m_freem(sc->sc_rx_mbuf[n]);
|
||||
sc->sc_rx_mbuf[n] = NULL;
|
||||
bus_dmamap_unload(sc->sc_dmat, sc->sc_rx_map[n]);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_map[n]);
|
||||
sc->sc_rx_map[n] = NULL;
|
||||
m_freem(sc->sc_rx_mbuf[n]);
|
||||
sc->sc_rx_mbuf[n] = NULL;
|
||||
}
|
||||
for (n = 0 ; n < t ; n++) {
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->sc_tx_map[n]);
|
||||
|
@ -1034,14 +1034,14 @@ iee_stop(struct ifnet *ifp, int disable)
|
|||
sc->sc_tx_map[n] = NULL;
|
||||
}
|
||||
for (n = 0 ; n < IEE_NRFD ; n++) {
|
||||
if (sc->sc_rx_mbuf[n] != NULL)
|
||||
m_freem(sc->sc_rx_mbuf[n]);
|
||||
sc->sc_rx_mbuf[n] = NULL;
|
||||
if (sc->sc_rx_map[n] != NULL) {
|
||||
bus_dmamap_unload(sc->sc_dmat, sc->sc_rx_map[n]);
|
||||
bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_map[n]);
|
||||
}
|
||||
sc->sc_rx_map[n] = NULL;
|
||||
if (sc->sc_rx_mbuf[n] != NULL)
|
||||
m_freem(sc->sc_rx_mbuf[n]);
|
||||
sc->sc_rx_mbuf[n] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_le_isa.c,v 1.52 2021/12/08 20:50:02 andvar Exp $ */
|
||||
/* $NetBSD: if_le_isa.c,v 1.53 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -65,7 +65,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_isa.c,v 1.52 2021/12/08 20:50:02 andvar Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_isa.c,v 1.53 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -328,13 +328,13 @@ le_isa_attach(device_t parent, struct le_softc *lesc,
|
|||
&rseg, BUS_DMA_NOWAIT)) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"couldn't allocate memory for card\n");
|
||||
return;
|
||||
goto bad_bsunmap;
|
||||
}
|
||||
if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE,
|
||||
(void **)&sc->sc_mem,
|
||||
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
|
||||
aprint_error_dev(sc->sc_dev, "couldn't map memory for card\n");
|
||||
return;
|
||||
goto bad_free;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -343,14 +343,12 @@ le_isa_attach(device_t parent, struct le_softc *lesc,
|
|||
if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1,
|
||||
LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
|
||||
aprint_error_dev(sc->sc_dev, "couldn't create DMA map\n");
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
return;
|
||||
goto bad_unmap;
|
||||
}
|
||||
if (bus_dmamap_load(dmat, lesc->sc_dmam,
|
||||
sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
|
||||
aprint_error_dev(sc->sc_dev, "couldn't load DMA map\n");
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
|
||||
sc->sc_conf3 = 0;
|
||||
|
@ -372,7 +370,7 @@ le_isa_attach(device_t parent, struct le_softc *lesc,
|
|||
ia->ia_drq[0].ir_drq)) != 0) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to cascade DRQ, error = %d\n", error);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,6 +379,17 @@ le_isa_attach(device_t parent, struct le_softc *lesc,
|
|||
|
||||
aprint_normal("%s", device_xname(sc->sc_dev));
|
||||
am7990_config(&lesc->sc_am7990);
|
||||
|
||||
return;
|
||||
|
||||
bad_destroy:
|
||||
bus_dmamap_destroy(dmat, lesc->sc_dmam);
|
||||
bad_unmap:
|
||||
bus_dmamem_unmap(dmat, sc->sc_mem, LE_ISA_MEMSIZE);
|
||||
bad_free:
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
bad_bsunmap:
|
||||
bus_space_unmap(iot, ioh, p->iosize);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_le_isapnp.c,v 1.36 2021/12/08 20:50:02 andvar Exp $ */
|
||||
/* $NetBSD: if_le_isapnp.c,v 1.37 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
|
@ -61,7 +61,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_isapnp.c,v 1.36 2021/12/08 20:50:02 andvar Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_isapnp.c,v 1.37 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -206,7 +206,7 @@ le_isapnp_attach(device_t parent, device_t self, void *aux)
|
|||
if (bus_dmamem_map(dmat, &seg, rseg, LE_ISAPNP_MEMSIZE,
|
||||
(void **)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
|
||||
aprint_error(": couldn't map memory for card\n");
|
||||
return;
|
||||
goto bad_free;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -215,14 +215,12 @@ le_isapnp_attach(device_t parent, device_t self, void *aux)
|
|||
if (bus_dmamap_create(dmat, LE_ISAPNP_MEMSIZE, 1,
|
||||
LE_ISAPNP_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
|
||||
aprint_error(": couldn't create DMA map\n");
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
return;
|
||||
goto bad_unmap;
|
||||
}
|
||||
if (bus_dmamap_load(dmat, lesc->sc_dmam,
|
||||
sc->sc_mem, LE_ISAPNP_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
|
||||
aprint_error(": couldn't load DMA map\n");
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
|
||||
sc->sc_conf3 = 0;
|
||||
|
@ -244,7 +242,7 @@ le_isapnp_attach(device_t parent, device_t self, void *aux)
|
|||
ipa->ipa_drq[0].num)) != 0) {
|
||||
aprint_error(": unable to cascade DRQ, error = %d\n",
|
||||
error);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,6 +253,15 @@ le_isapnp_attach(device_t parent, device_t self, void *aux)
|
|||
|
||||
aprint_normal("%s", device_xname(self));
|
||||
am7990_config(&lesc->sc_am7990);
|
||||
|
||||
return;
|
||||
|
||||
bad_destroy:
|
||||
bus_dmamap_destroy(dmat, lesc->sc_dmam);
|
||||
bad_unmap:
|
||||
bus_dmamem_unmap(dmat, sc->sc_mem, LE_ISAPNP_MEMSIZE);
|
||||
bad_free:
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_le.c,v 1.41 2019/05/29 06:21:58 msaitoh Exp $ */
|
||||
/* $NetBSD: if_le.c,v 1.42 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.41 2019/05/29 06:21:58 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.42 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
|
||||
|
@ -233,6 +233,7 @@ leattach_sbus(device_t parent, device_t self, void *aux)
|
|||
&seg, 1, &rseg, BUS_DMA_NOWAIT | BUS_DMA_24BIT)) != 0) {
|
||||
aprint_error(": DMA buffer allocation error %d\n",
|
||||
error);
|
||||
bus_dmamap_destroy(dmatag, lesc->sc_dmamap);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -242,6 +243,7 @@ leattach_sbus(device_t parent, device_t self, void *aux)
|
|||
!= 0) {
|
||||
aprint_error(": DMA buffer map error %d\n", error);
|
||||
bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
|
||||
bus_dmamap_destroy(dmatag, lesc->sc_dmamap);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -249,8 +251,9 @@ leattach_sbus(device_t parent, device_t self, void *aux)
|
|||
if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap,
|
||||
sc->sc_mem, MEMSIZE, NULL, BUS_DMA_NOWAIT)) != 0) {
|
||||
aprint_error(": DMA buffer map load error %d\n", error);
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
bus_dmamem_unmap(dmatag, sc->sc_mem, MEMSIZE);
|
||||
bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
|
||||
bus_dmamap_destroy(dmatag, lesc->sc_dmamap);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_le_ledma.c,v 1.36 2019/04/25 10:44:53 msaitoh Exp $ */
|
||||
/* $NetBSD: if_le_ledma.c,v 1.37 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_ledma.c,v 1.36 2019/04/25 10:44:53 msaitoh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_ledma.c,v 1.37 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
|
||||
|
@ -360,24 +360,21 @@ leattach_ledma(device_t parent, device_t self, void *aux)
|
|||
if ((error = bus_dmamem_alloc(dmatag, MEMSIZE, 0, LEDMA_BOUNDARY,
|
||||
&seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
|
||||
aprint_error(": DMA buffer alloc error %d\n",error);
|
||||
return;
|
||||
goto bad_destroy;
|
||||
}
|
||||
|
||||
/* Map DMA buffer into kernel space */
|
||||
if ((error = bus_dmamem_map(dmatag, &seg, rseg, MEMSIZE,
|
||||
(void **)&sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
||||
aprint_error(": DMA buffer map error %d\n", error);
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
return;
|
||||
goto bad_free;
|
||||
}
|
||||
|
||||
/* Load DMA buffer */
|
||||
if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap, sc->sc_mem,
|
||||
MEMSIZE, NULL, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
||||
aprint_error(": DMA buffer map load error %d\n", error);
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
bus_dmamem_unmap(dmatag, sc->sc_mem, MEMSIZE);
|
||||
return;
|
||||
goto bad_unmap;
|
||||
}
|
||||
|
||||
lesc->sc_laddr = lesc->sc_dmamap->dm_segs[0].ds_addr;
|
||||
|
@ -414,4 +411,13 @@ leattach_ledma(device_t parent, device_t self, void *aux)
|
|||
|
||||
/* now initialize DMA */
|
||||
lehwreset(sc);
|
||||
|
||||
return;
|
||||
|
||||
bad_unmap:
|
||||
bus_dmamem_unmap(dmatag, sc->sc_mem, MEMSIZE);
|
||||
bad_free:
|
||||
bus_dmamem_free(dmatag, &seg, rseg);
|
||||
bad_destroy:
|
||||
bus_dmamap_destroy(dmatag, lesc->sc_dmamap);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_le_ioasic.c,v 1.34 2018/09/03 16:29:33 riastradh Exp $ */
|
||||
/* $NetBSD: if_le_ioasic.c,v 1.35 2022/05/29 10:43:46 rin Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Carnegie-Mellon University.
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_ioasic.c,v 1.34 2018/09/03 16:29:33 riastradh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_le_ioasic.c,v 1.35 2022/05/29 10:43:46 rin Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
|
||||
|
@ -130,8 +130,7 @@ le_ioasic_attach(device_t parent, device_t self, void *aux)
|
|||
if (bus_dmamem_map(dmat, &seg, rseg, LE_IOASIC_MEMSIZE,
|
||||
&le_iomem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
|
||||
aprint_error(": can't map DMA area for LANCE\n");
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
return;
|
||||
goto bad_free;
|
||||
}
|
||||
/*
|
||||
* Create and load the DMA map for the DMA area.
|
||||
|
@ -139,12 +138,12 @@ le_ioasic_attach(device_t parent, device_t self, void *aux)
|
|||
if (bus_dmamap_create(dmat, LE_IOASIC_MEMSIZE, 1,
|
||||
LE_IOASIC_MEMSIZE, 0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) {
|
||||
aprint_error(": can't create DMA map\n");
|
||||
goto bad;
|
||||
goto bad_unmap;
|
||||
}
|
||||
if (bus_dmamap_load(dmat, sc->sc_dmamap,
|
||||
le_iomem, LE_IOASIC_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
|
||||
aprint_error(": can't load DMA map\n");
|
||||
goto bad;
|
||||
goto bad_destroy;
|
||||
}
|
||||
/*
|
||||
* Bind 128KB buffer with IOASIC DMA.
|
||||
|
@ -171,8 +170,11 @@ le_ioasic_attach(device_t parent, device_t self, void *aux)
|
|||
am7990_intr, sc);
|
||||
return;
|
||||
|
||||
bad:
|
||||
bad_destroy:
|
||||
bus_dmamap_destroy(dmat, sc->sc_dmamap);
|
||||
bad_unmap:
|
||||
bus_dmamem_unmap(dmat, le_iomem, LE_IOASIC_MEMSIZE);
|
||||
bad_free:
|
||||
bus_dmamem_free(dmat, &seg, rseg);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue