Make sure we clean up any DMA maps if the open fails.

This commit is contained in:
mycroft 1999-03-22 14:38:02 +00:00
parent 41d5307e95
commit 9e4bd01bff

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbdsp.c,v 1.97 1999/03/22 07:37:35 mycroft Exp $ */ /* $NetBSD: sbdsp.c,v 1.98 1999/03/22 14:38:02 mycroft Exp $ */
/*- /*-
* Copyright (c) 1999 The NetBSD Foundation, Inc. * Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -867,7 +867,7 @@ sbdsp_open(addr, flags)
int flags; int flags;
{ {
struct sbdsp_softc *sc = addr; struct sbdsp_softc *sc = addr;
int error; int error, state;
DPRINTF(("sbdsp_open: sc=%p\n", sc)); DPRINTF(("sbdsp_open: sc=%p\n", sc));
@ -875,6 +875,7 @@ sbdsp_open(addr, flags)
return (EBUSY); return (EBUSY);
sc->sc_open = SB_OPEN_AUDIO; sc->sc_open = SB_OPEN_AUDIO;
sc->sc_openflags = flags; sc->sc_openflags = flags;
state = 0;
if (sc->sc_drq8 != -1) { if (sc->sc_drq8 != -1) {
error = isa_dmamap_create(sc->sc_ic, sc->sc_drq8, error = isa_dmamap_create(sc->sc_ic, sc->sc_drq8,
@ -884,6 +885,7 @@ sbdsp_open(addr, flags)
sc->sc_dev.dv_xname, sc->sc_drq8); sc->sc_dev.dv_xname, sc->sc_drq8);
goto bad; goto bad;
} }
state |= 1;
} }
if (sc->sc_drq16 != -1 && sc->sc_drq16 != sc->sc_drq8) { if (sc->sc_drq16 != -1 && sc->sc_drq16 != sc->sc_drq8) {
error = isa_dmamap_create(sc->sc_ic, sc->sc_drq16, error = isa_dmamap_create(sc->sc_ic, sc->sc_drq16,
@ -893,6 +895,7 @@ sbdsp_open(addr, flags)
sc->sc_dev.dv_xname, sc->sc_drq16); sc->sc_dev.dv_xname, sc->sc_drq16);
goto bad; goto bad;
} }
state |= 2;
} }
if (sbdsp_reset(sc) != 0) { if (sbdsp_reset(sc) != 0) {
@ -917,6 +920,11 @@ sbdsp_open(addr, flags)
return (0); return (0);
bad: bad:
if (state & 1)
isa_dmamap_destroy(sc->sc_ic, sc->sc_drq8);
if (state & 2)
isa_dmamap_destroy(sc->sc_ic, sc->sc_drq16);
sc->sc_open = SB_CLOSED; sc->sc_open = SB_CLOSED;
return (error); return (error);
} }