Simplify ActiveNblCount decrement

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-07-05 14:32:13 +00:00
parent 50aa1f924c
commit 17a0e2647a

View File

@ -196,18 +196,12 @@ TunCompleteRequest(_Inout_ TUN_CTX *Ctx, _Inout_ IRP *Irp, _In_ NTSTATUS Status,
} }
_IRQL_requires_max_(DISPATCH_LEVEL) _IRQL_requires_max_(DISPATCH_LEVEL)
static NDIS_STATUS static void
TunCompletePause(_Inout_ TUN_CTX *Ctx, _In_ BOOLEAN AsyncCompletion) TunDecrementActiveNblCount(_Inout_ TUN_CTX *Ctx)
{ {
ASSERT(InterlockedGet64(&Ctx->ActiveNblCount) > 0); ASSERT(InterlockedGet64(&Ctx->ActiveNblCount) > 0);
if (InterlockedDecrement64(&Ctx->ActiveNblCount) <= 0) if (InterlockedDecrement64(&Ctx->ActiveNblCount) <= 0)
{ NdisMPauseComplete(Ctx->MiniportAdapterHandle);
if (AsyncCompletion)
NdisMPauseComplete(Ctx->MiniportAdapterHandle);
return NDIS_STATUS_SUCCESS;
}
return NDIS_STATUS_PENDING;
} }
static IO_CSQ_INSERT_IRP_EX TunCsqInsertIrpEx; static IO_CSQ_INSERT_IRP_EX TunCsqInsertIrpEx;
@ -459,7 +453,7 @@ TunNblRefDec(_Inout_ TUN_CTX *Ctx, _Inout_ NET_BUFFER_LIST *Nbl, _In_ ULONG Send
NdisMSendNetBufferListsComplete(Ctx->MiniportAdapterHandle, Nbl, SendCompleteFlags); NdisMSendNetBufferListsComplete(Ctx->MiniportAdapterHandle, Nbl, SendCompleteFlags);
ASSERT(InterlockedGet(&Ctx->PacketQueue.NumNbl) > 0); ASSERT(InterlockedGet(&Ctx->PacketQueue.NumNbl) > 0);
InterlockedDecrement(&Ctx->PacketQueue.NumNbl); InterlockedDecrement(&Ctx->PacketQueue.NumNbl);
TunCompletePause(Ctx, TRUE); TunDecrementActiveNblCount(Ctx);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -787,7 +781,7 @@ TunReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUFFER_LIST Net
else else
StatPacketsError++; StatPacketsError++;
TunCompletePause(Ctx, TRUE); TunDecrementActiveNblCount(Ctx);
LONG volatile *MdlRefCount = NET_BUFFER_LIST_MDL_REFCOUNT(Nbl); LONG volatile *MdlRefCount = NET_BUFFER_LIST_MDL_REFCOUNT(Nbl);
ASSERT(InterlockedGet(MdlRefCount) > 0); ASSERT(InterlockedGet(MdlRefCount) > 0);
@ -1118,7 +1112,8 @@ TunPause(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_PAUSE_PARAMETERS Min
ExAcquireSpinLockExclusive(&Ctx->TransitionLock)); /* Ensure above change is visible to all readers. */ ExAcquireSpinLockExclusive(&Ctx->TransitionLock)); /* Ensure above change is visible to all readers. */
TunQueueClear(Ctx, NDIS_STATUS_PAUSED); TunQueueClear(Ctx, NDIS_STATUS_PAUSED);
return TunCompletePause(Ctx, FALSE); ASSERT(InterlockedGet64(&Ctx->ActiveNblCount) > 0);
return InterlockedDecrement64(&Ctx->ActiveNblCount) <= 0 ? NDIS_STATUS_SUCCESS : NDIS_STATUS_PENDING;
} }
static MINIPORT_DEVICE_PNP_EVENT_NOTIFY TunDevicePnPEventNotify; static MINIPORT_DEVICE_PNP_EVENT_NOTIFY TunDevicePnPEventNotify;