svn commit: r299544 - head/sys/dev/an

John Baldwin jhb at freebsd.org
Thu May 12 19:13:47 UTC 2016


On Thursday, May 12, 2016 05:47:30 PM Scott Long wrote:
> Author: scottl
> Date: Thu May 12 17:47:30 2016
> New Revision: 299544
> URL: https://svnweb.freebsd.org/changeset/base/299544
> 
> Log:
>   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.

Except that if they return 0 (which most shouldn't) it is guaranteed.
an_probe() used to return 0, but it was changed to return BUS_PROBE_DEFAULT
without fixing this.  (Oops)

an_probe() could just be fixed to destroy the lock and the lock init could
then be moved into an_attach().

> Modified: head/sys/dev/an/if_an_pci.c
> ==============================================================================
> --- head/sys/dev/an/if_an_pci.c	Thu May 12 16:34:59 2016	(r299543)
> +++ head/sys/dev/an/if_an_pci.c	Thu May 12 17:47:30 2016	(r299544)
> @@ -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));

This wasn't necessary before.

>  	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));

This isn't necessary now (softc's are pre-zeroed by new-bus).

>  	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;
> 

-- 
John Baldwin


More information about the svn-src-all mailing list