diff options
author | imp <imp@FreeBSD.org> | 2007-02-15 07:22:27 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2007-02-15 07:22:27 +0000 |
commit | 5b972eaa75bb5b34836068e7f6d55dccc2b1cd23 (patch) | |
tree | 16d4f30a1c07375a16af4c4f9008aacd4db6e70b | |
parent | b0a1de450233d09e5dd7d67549686aff67b8ddc1 (diff) | |
download | FreeBSD-src-5b972eaa75bb5b34836068e7f6d55dccc2b1cd23.zip FreeBSD-src-5b972eaa75bb5b34836068e7f6d55dccc2b1cd23.tar.gz |
It turns out that it is easier to not NULL out pccard and cardbus
device pointers. They don't change as the children device drivers
come and go. Rather, check to see if the device is attached where we
would have checked ! NULL. This solves many asymmetries in the code
that likely could lead to crashes when loading/unloading cbb without
one or more of the expected children's driver not present.
-rw-r--r-- | sys/dev/exca/exca.c | 2 | ||||
-rw-r--r-- | sys/dev/pccbb/pccbb.c | 20 |
2 files changed, 7 insertions, 15 deletions
diff --git a/sys/dev/exca/exca.c b/sys/dev/exca/exca.c index 8845e65..a46ba47 100644 --- a/sys/dev/exca/exca.c +++ b/sys/dev/exca/exca.c @@ -780,7 +780,7 @@ exca_insert(struct exca_softc *exca) void exca_removal(struct exca_softc *exca) { - if (exca->pccarddev != NULL) + if (device_is_attached(exca->pccarddev)) CARD_DETACH_CARD(exca->pccarddev); } diff --git a/sys/dev/pccbb/pccbb.c b/sys/dev/pccbb/pccbb.c index a7cb56b..45a8954 100644 --- a/sys/dev/pccbb/pccbb.c +++ b/sys/dev/pccbb/pccbb.c @@ -431,13 +431,8 @@ cbb_driver_added(device_t brdev, driver_t *driver) for (tmp = 0; tmp < numdevs; tmp++) { dev = devlist[tmp]; if (device_get_state(dev) == DS_NOTPRESENT && - device_probe_and_attach(dev) == 0) { + device_probe_and_attach(dev) == 0) wake++; - if (strcmp(device_get_name(dev), "cardbus") == 0) - sc->cbdev = dev; - else if (strcmp(device_get_name(dev), "pccard") == 0) - sc->exca[0].pccarddev = dev; - } } free(devlist, M_TEMP); @@ -453,11 +448,8 @@ cbb_child_detached(device_t brdev, device_t child) { struct cbb_softc *sc = device_get_softc(brdev); - if (child == sc->cbdev) - sc->cbdev = NULL; - else if (child == sc->exca[0].pccarddev) - sc->exca[0].pccarddev = NULL; - else + /* I'm not sure we even need this */ + if (child != sc->cbdev && child != sc->exca[0].pccarddev) device_printf(brdev, "Unknown child detached: %s\n", device_get_nameunit(child)); } @@ -556,7 +548,7 @@ cbb_insert(struct cbb_softc *sc) sockevent, sockstate)); if (sockstate & CBB_STATE_R2_CARD) { - if (sc->exca[0].pccarddev) { + if (device_is_attached(sc->exca[0].pccarddev)) { sc->flags |= CBB_16BIT_CARD; exca_insert(&sc->exca[0]); } else { @@ -564,7 +556,7 @@ cbb_insert(struct cbb_softc *sc) "16-bit card inserted, but no pccard bus.\n"); } } else if (sockstate & CBB_STATE_CB_CARD) { - if (sc->cbdev != NULL) { + if (device_is_attached(sc->cbdev)) { sc->flags &= ~CBB_16BIT_CARD; CARD_ATTACH_CARD(sc->cbdev); } else { @@ -587,7 +579,7 @@ cbb_removal(struct cbb_softc *sc) if (sc->flags & CBB_16BIT_CARD) { exca_removal(&sc->exca[0]); } else { - if (sc->cbdev != NULL) + if (device_is_attached(sc->cbdev)) CARD_DETACH_CARD(sc->cbdev); } cbb_destroy_res(sc); |