Skip to content

Commit

Permalink
Avoid NdisWait at Dispatch level in DriverUnload via NPF_CloseOpenIns…
Browse files Browse the repository at this point in the history
…tance
  • Loading branch information
bonsaiviking committed Jun 1, 2021
1 parent 1736f3c commit 01ba22d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packetWin7/npf/npf/Packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,21 +976,23 @@ Return Value:
TRACE_MESSAGE2(PACKET_DEBUG_LOUD, "Deleting Adapter, Device Obj=%p (%p)",
DeviceObject, OldDeviceObject);

// Not sure if we need to acquire this lock, since no new IRPs can be issued during unload,
// but better safe than sorry.
NdisAcquireRWLockWrite(DeviceExtension->AllOpensLock, &lockState, 0);
for (CurrEntry = DeviceExtension->AllOpens.Flink;
CurrEntry != &DeviceExtension->AllOpens;
CurrEntry = CurrEntry->Flink)
CurrEntry = RemoveHeadList(&DeviceExtension->AllOpens);
while (CurrEntry != &DeviceExtension->AllOpens)
{
POPEN_INSTANCE pOpen = CONTAINING_RECORD(CurrEntry, OPEN_INSTANCE, AllOpensEntry);
if (pOpen->OpenStatus == OpenDetached)
{
CurrEntry = CurrEntry->Blink;
RemoveEntryList(&pOpen->AllOpensEntry);

NPF_CloseOpenInstance(pOpen);
NPF_ReleaseOpenInstanceResources(pOpen);
ExFreePool(pOpen);
}
// NPF_CloseOpenInstance needs PASSIVE_LEVEL
NdisReleaseRWLock(DeviceExtension->AllOpensLock, &lockState);

NPF_CloseOpenInstance(pOpen);
NPF_ReleaseOpenInstanceResources(pOpen);
ExFreePool(pOpen);

NdisAcquireRWLockWrite(DeviceExtension->AllOpensLock, &lockState, 0);
CurrEntry = RemoveHeadList(&DeviceExtension->AllOpens);
}
NdisReleaseRWLock(DeviceExtension->AllOpensLock, &lockState);

Expand Down

0 comments on commit 01ba22d

Please sign in to comment.