Unmap registers upon detach. Avoid panics when detaching a partially attached
authorkettenis <kettenis@openbsd.org>
Sat, 7 Aug 2010 16:16:18 +0000 (16:16 +0000)
committerkettenis <kettenis@openbsd.org>
Sat, 7 Aug 2010 16:16:18 +0000 (16:16 +0000)
device.  Found out the hard way by hotplugging an unsupported "Soft-Mac"
device.

ok deraadt@

sys/dev/ic/pgt.c
sys/dev/pci/if_pgt_pci.c

index 67740f4..99c0a35 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pgt.c,v 1.60 2010/08/07 03:50:01 krw Exp $  */
+/*     $OpenBSD: pgt.c,v 1.61 2010/08/07 16:16:18 kettenis Exp $  */
 
 /*
  * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@@ -603,6 +603,7 @@ pgt_attach(void *xsc)
        tsleep(&sc->sc_flags, 0, "pgtres", hz);
        if (sc->sc_flags & SC_UNINITIALIZED) {
                printf("%s: not responding\n", sc->sc_dev.dv_xname);
+               sc->sc_flags |= SC_NEEDS_FIRMWARE;
                return;
        } else {
                /* await all interrupts */
index f6ceaa5..7fb29bd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_pgt_pci.c,v 1.11 2009/06/02 04:03:39 jsg Exp $  */
+/*     $OpenBSD: if_pgt_pci.c,v 1.12 2010/08/07 16:16:18 kettenis Exp $  */
 
 /*
  * Copyright (c) 2006 Marcus Glocker <mglocker@openbsd.org>
@@ -147,8 +147,13 @@ pgt_pci_detach(struct device *self, int flags)
        struct pgt_pci_softc *psc = (struct pgt_pci_softc *)self;
        struct pgt_softc *sc = &psc->sc_pgt;
 
-       pgt_detach(sc);
-       pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
+       if (psc->sc_ih != NULL) {
+               pgt_detach(sc);
+               pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
+       }
+       if (psc->sc_mapsize > 0)
+               bus_space_unmap(sc->sc_iotag, sc->sc_iohandle,
+                   psc->sc_mapsize);
 
        return (0);
 }