Re: buildkernel is broken in if_ndis

From: Bill Paul <wpaul_at_FreeBSD.ORG>
Date: Tue, 11 Oct 2005 22:10:45 +0000 (GMT)
[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
> _at__at_ -917,8 +917,6 _at__at_
>          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
=============================================================================
Received on Tue Oct 11 2005 - 20:10:45 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:45 UTC