buildkernel is broken in if_ndis

Bill Paul wpaul at FreeBSD.ORG
Tue Oct 11 15:10:45 PDT 2005


[Charset ISO-8859-1 unsupported, filtering to ASCII...]
> dear hackers,
> 
> make buildworld is broken for me. since NDIS_LOCK(sc) does not uses 
> sc->ndis_mtx anymore, shouldn't the following patch be put in place?
> 
> max
> 
> p.s. i could not find KeIsInitializedSpinLock function in subr_ndis.c. 
> quick look at msdn did not reveal it either
> 
> 
> --- if_ndis.c.orig      Tue Oct 11 11:11:52 2005
> +++ if_ndis.c   Tue Oct 11 11:11:31 2005
> @@ -917,8 +917,6 @@
>          driver_object           *drv;
> 
>          sc = device_get_softc(dev);
> -       KASSERT(mtx_initialized(&sc->ndis_mtx),
> -           ("ndis mutex not initialized"));
>          NDIS_LOCK(sc);
>          ifp = sc->ifp;
>          ifp->if_flags &= ~IFF_UP;
> 

Fixed. The KASSERT just doesn't need to be there anymore. In Windows,
a spinlock is just a 32-bit long, and the only thing
KeInitializeSpinLock() does is set spinlock = 0. There is no
KeDestroySpinLock(): when you're done with the spinlock, you just
free the storage in which it resides (after unlocking it for the
last time, of course).

Now, the NDIS API has NdisAllocateSpinLock() and NdisFreeSpinLock(),
however I think Microsoft put them there based on the assumption that
someone might want to implement the NDIS API on another OS where
you really do have to allocate and free resources for spinlocks.
However, NdisAllocateSpinLock() doesn't really allocate anything:
it just calls KeInitializeSpinLock(), and NdisFreeSpinLock() does
nothing.

(Note also there's at least one driver out there which calls
NdisFreeSpinLock() _AFTER_ releasing the storage in which the spinlock
resides. But since NdisFreeSpinLock() is a no-op in Windows, the
Microsoft driver verified never flags the error.)

-Bill

--
=============================================================================
-Bill Paul            (510) 749-2329 | Senior Engineer, Master of Unix-Fu
                 wpaul at windriver.com | Wind River Systems
=============================================================================
              <adamw> you're just BEGGING to face the moose
=============================================================================


More information about the freebsd-current mailing list