From 3934bc5561de24ea02938e73890c309e67ccac5f Mon Sep 17 00:00:00 2001 From: Scott Long Date: Thu, 12 May 2016 17:47:30 +0000 Subject: [PATCH] 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 --- sys/dev/an/if_an.c | 17 ----------------- sys/dev/an/if_an_pci.c | 18 +++++++++++++----- sys/dev/an/if_anreg.h | 1 - 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/sys/dev/an/if_an.c b/sys/dev/an/if_an.c index a85136bf3a70..4b1891d1be9d 100644 --- a/sys/dev/an/if_an.c +++ b/sys/dev/an/if_an.c @@ -303,23 +303,6 @@ sysctl_an_cache_mode(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_hw_an, OID_AUTO, an_cache_mode, CTLTYPE_STRING | CTLFLAG_RW, 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 * read the default SSID list. On reset, the first entry in diff --git a/sys/dev/an/if_an_pci.c b/sys/dev/an/if_an_pci.c index 1c3032c942e2..db658cfa6139 100644 --- a/sys/dev/an/if_an_pci.c +++ b/sys/dev/an/if_an_pci.c @@ -119,16 +119,16 @@ static int an_probe_pci(device_t dev) { 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; + vid = pci_get_vendor(dev); + did = pci_get_device(dev); while (t->an_name != NULL) { - if (pci_get_vendor(dev) == t->an_vid && - pci_get_device(dev) == t->an_did) { + if (vid == t->an_vid && + did == t->an_did) { device_set_desc(dev, t->an_name); - an_pci_probe(dev); return(BUS_PROBE_DEFAULT); } t++; @@ -145,8 +145,16 @@ an_attach_pci(dev) int flags, error = 0; sc = device_get_softc(dev); + bzero(sc, sizeof(struct an_softc)); 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 && pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { sc->mpi350 = 1; diff --git a/sys/dev/an/if_anreg.h b/sys/dev/an/if_anreg.h index 0004e8e66e45..ee69b8856019 100644 --- a/sys/dev/an/if_anreg.h +++ b/sys/dev/an/if_anreg.h @@ -500,7 +500,6 @@ int an_alloc_port (device_t, int, int); int an_alloc_memory (device_t, int, int); int an_alloc_aux_memory (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_shutdown (device_t); void an_resume (device_t);