Move mutex initialization from PCI probe to PCI attach. Drivers are not

allowed to create any persistent state in their probe routine because it's
not guaranteed that they'll win the election and be allowed to attach.

Submitted by:	Matthew Macy
MFC after:	3 days
This commit is contained in:
scottl 2016-05-12 17:47:30 +00:00
parent 6d95624949
commit 1adf5af9a5
3 changed files with 13 additions and 23 deletions

View File

@ -303,23 +303,6 @@ sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW, SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW,
0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", ""); 0, sizeof(an_conf_cache), sysctl_an_cache_mode, "A", "");
/*
* Setup the lock for PCI attachment since it skips the an_probe
* function. We need to setup the lock in an_probe since some
* operations need the lock. So we might as well create the
* lock in the probe.
*/
int
an_pci_probe(device_t dev)
{
struct an_softc *sc = device_get_softc(dev);
mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF);
return(0);
}
/* /*
* We probe for an Aironet 4500/4800 card by attempting to * We probe for an Aironet 4500/4800 card by attempting to
* read the default SSID list. On reset, the first entry in * read the default SSID list. On reset, the first entry in

View File

@ -119,16 +119,16 @@ static int
an_probe_pci(device_t dev) an_probe_pci(device_t dev)
{ {
struct an_type *t; struct an_type *t;
struct an_softc *sc = device_get_softc(dev); uint16_t vid, did;
bzero(sc, sizeof(struct an_softc));
t = an_devs; t = an_devs;
vid = pci_get_vendor(dev);
did = pci_get_device(dev);
while (t->an_name != NULL) { while (t->an_name != NULL) {
if (pci_get_vendor(dev) == t->an_vid && if (vid == t->an_vid &&
pci_get_device(dev) == t->an_did) { did == t->an_did) {
device_set_desc(dev, t->an_name); device_set_desc(dev, t->an_name);
an_pci_probe(dev);
return(BUS_PROBE_DEFAULT); return(BUS_PROBE_DEFAULT);
} }
t++; t++;
@ -145,8 +145,16 @@ an_attach_pci(dev)
int flags, error = 0; int flags, error = 0;
sc = device_get_softc(dev); sc = device_get_softc(dev);
bzero(sc, sizeof(struct an_softc));
flags = device_get_flags(dev); flags = device_get_flags(dev);
/*
* Setup the lock in PCI attachment since it skips the an_probe
* function.
*/
mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF);
if (pci_get_vendor(dev) == AIRONET_VENDORID && if (pci_get_vendor(dev) == AIRONET_VENDORID &&
pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
sc->mpi350 = 1; sc->mpi350 = 1;

View File

@ -500,7 +500,6 @@ int an_alloc_port (device_t, int, int);
int an_alloc_memory (device_t, int, int); int an_alloc_memory (device_t, int, int);
int an_alloc_aux_memory (device_t, int, int); int an_alloc_aux_memory (device_t, int, int);
int an_alloc_irq (device_t, int, int); int an_alloc_irq (device_t, int, int);
int an_pci_probe (device_t);
int an_probe (device_t); int an_probe (device_t);
int an_shutdown (device_t); int an_shutdown (device_t);
void an_resume (device_t); void an_resume (device_t);