Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pcmcia Free resources on attach failure.



details:   https://anonhg.NetBSD.org/src/rev/600b32c6e84e
branches:  trunk
changeset: 481718:600b32c6e84e
user:      enami <enami%NetBSD.org@localhost>
date:      Fri Feb 04 09:31:07 2000 +0000

description:
Free resources on attach failure.

diffstat:

 sys/dev/pcmcia/aic_pcmcia.c |  30 +++++++++++++++++++++++++-----
 sys/dev/pcmcia/wdc_pcmcia.c |  39 +++++++++++++++++++++++++++++++++------
 2 files changed, 58 insertions(+), 11 deletions(-)

diffs (169 lines):

diff -r ab1cf57feda0 -r 600b32c6e84e sys/dev/pcmcia/aic_pcmcia.c
--- a/sys/dev/pcmcia/aic_pcmcia.c       Fri Feb 04 09:30:28 2000 +0000
+++ b/sys/dev/pcmcia/aic_pcmcia.c       Fri Feb 04 09:31:07 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: aic_pcmcia.c,v 1.15 2000/02/04 01:27:12 cgd Exp $      */
+/*     $NetBSD: aic_pcmcia.c,v 1.16 2000/02/04 09:31:07 enami Exp $    */
 
 /*
  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
@@ -134,7 +134,7 @@
 
        if (cfe == 0) {
                printf(": can't alloc i/o space\n");
-               return;
+               goto no_config_entry;
        }
 
        sc->sc_iot = psc->sc_pcioh.iot;
@@ -144,19 +144,19 @@
        pcmcia_function_init(pf, cfe);
        if (pcmcia_function_enable(pf)) {
                printf(": function enable failed\n");
-               return;
+               goto enable_failed;
        }
 
        /* Map in the io space */
        if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
            &psc->sc_pcioh, &psc->sc_io_window)) {
                printf(": can't map i/o space\n");
-               return;
+               goto iomap_failed;
        }
 
        if (!aic_find(sc->sc_iot, sc->sc_ioh)) {
                printf(": unable to detect chip!\n");
-               return;
+               goto no_aic_found;
        }
 
        pp = pcmcia_product_lookup(pa, aic_pcmcia_products,
@@ -174,6 +174,22 @@
        psc->sc_flags |= AIC_PCMCIA_ATTACH;
        aicattach(sc);
        psc->sc_flags &= ~AIC_PCMCIA_ATTACH;
+       return;
+
+ no_aic_found:
+       /* Unmap our i/o window. */
+       pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
+
+ iomap_failed:
+       /* Disable the device. */
+       pcmcia_function_disable(psc->sc_pf);
+
+ enable_failed:
+       /* Unmap our i/o space. */
+       pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
+
+ no_config_entry:
+       psc->sc_io_window = -1;
 }
 
 int
@@ -184,6 +200,10 @@
        struct aic_pcmcia_softc *sc = (struct aic_pcmcia_softc *)self;
        int error;
 
+       if (sc->sc_io_window == -1)
+               /* Nothing to detach. */
+               return (0);
+
        if ((error = aic_detach(self, flags)) != 0)
                return (error);
 
diff -r ab1cf57feda0 -r 600b32c6e84e sys/dev/pcmcia/wdc_pcmcia.c
--- a/sys/dev/pcmcia/wdc_pcmcia.c       Fri Feb 04 09:30:28 2000 +0000
+++ b/sys/dev/pcmcia/wdc_pcmcia.c       Fri Feb 04 09:31:07 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wdc_pcmcia.c,v 1.28 2000/02/01 06:48:15 enami Exp $ */
+/*     $NetBSD: wdc_pcmcia.c,v 1.29 2000/02/04 09:31:07 enami Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -292,14 +292,14 @@
 
        if (cfe == NULL) {
                printf(": can't handle card info\n");
-               return;
+               goto no_config_entry;
        }
 
        /* Enable the card. */
        pcmcia_function_init(pa->pf, cfe);
        if (pcmcia_function_enable(pa->pf)) {
                printf(": function enable failed\n");
-               return;
+               goto enable_failed;
        }
 
        wpp = wdc_pcmcia_lookup(pa);
@@ -311,7 +311,7 @@
        if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
            sc->sc_pioh.size, &sc->sc_pioh, &sc->sc_iowindow)) {
                printf(": can't map first I/O space\n");
-               return;
+               goto iomap_failed;
        } 
 
        if (cfe->num_iospace <= 1)
@@ -319,7 +319,7 @@
        else if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0,
            sc->sc_auxpioh.size, &sc->sc_auxpioh, &sc->sc_auxiowindow)) {
                printf(": can't map second I/O space\n");
-               return;
+               goto iomapaux_failed;
        }
 
        if ((wpp != NULL) && (wpp->wpp_name != NULL))
@@ -345,7 +345,7 @@
        if (sc->wdc_channel.ch_queue == NULL) {
                printf("%s: can't allocate memory for command queue\n",
                    sc->sc_wdcdev.sc_dev.dv_xname);
-               return;
+               goto ch_queue_alloc_failed;
        }
        if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
                sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
@@ -356,6 +356,29 @@
        sc->sc_flags |= WDC_PCMCIA_ATTACH;
        wdcattach(&sc->wdc_channel);
        sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
+       return;
+
+ ch_queue_alloc_failed:
+       /* Unmap our aux i/o window. */
+       if (sc->sc_auxiowindow != -1)
+               pcmcia_io_unmap(sc->sc_pf, sc->sc_auxiowindow);
+
+ iomapaux_failed:
+       /* Unmap our i/o window. */
+       pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);
+
+ iomap_failed:
+       /* Disable the function */
+       pcmcia_function_disable(sc->sc_pf);
+
+ enable_failed:
+       /* Unmap our i/o space. */
+       pcmcia_io_free(sc->sc_pf, &sc->sc_pioh);
+       if (cfe->num_iospace == 2)
+               pcmcia_io_free(sc->sc_pf, &sc->sc_auxpioh);
+
+ no_config_entry:
+       sc->sc_iowindow = -1;
 }
 
 int
@@ -366,6 +389,10 @@
        struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
        int error;
 
+       if (sc->sc_iowindow == -1)
+               /* Nothing to detach */
+               return (0);
+
        if ((error = wdcdetach(self, flags)) != 0)
                return (error);
 



Home | Main Index | Thread Index | Old Index