From 5cecd1536cbf1b40b238255b97083e249262de50 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 10 Apr 2019 14:35:50 +0200 Subject: [PATCH] Clean excessive miniport adapter state checks Signed-off-by: Simon Rozman --- wintun.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/wintun.c b/wintun.c index 01618ba..96474c8 100644 --- a/wintun.c +++ b/wintun.c @@ -768,10 +768,7 @@ static NDIS_STATUS TunPause(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_P TUN_CTX *ctx = (TUN_CTX *)MiniportAdapterContext; InterlockedIncrement64(&ctx->ActiveTransactionCount); - if (InterlockedCompareExchange((LONG *)&ctx->State, TUN_STATE_PAUSING, TUN_STATE_RUNNING) != TUN_STATE_RUNNING) { - InterlockedDecrement64(&ctx->ActiveTransactionCount); - return NDIS_STATUS_FAILURE; - } + InterlockedExchange((LONG *)&ctx->State, TUN_STATE_PAUSING); TunQueueClear(ctx); @@ -783,9 +780,8 @@ _Use_decl_annotations_ static NDIS_STATUS TunRestart(NDIS_HANDLE MiniportAdapterContext, PNDIS_MINIPORT_RESTART_PARAMETERS MiniportRestartParameters) { TUN_CTX *ctx = (TUN_CTX *)MiniportAdapterContext; - if (InterlockedCompareExchange((LONG *)&ctx->State, TUN_STATE_RESTARTING, TUN_STATE_PAUSED) != TUN_STATE_PAUSED) - return NDIS_STATUS_FAILURE; + //InterlockedExchange((LONG *)&ctx->State, TUN_STATE_RESTARTING); InterlockedExchange((LONG *)&ctx->State, TUN_STATE_RUNNING); return NDIS_STATUS_SUCCESS; } @@ -1098,10 +1094,8 @@ _Use_decl_annotations_ static void TunHaltEx(NDIS_HANDLE MiniportAdapterContext, NDIS_HALT_ACTION HaltAction) { TUN_CTX *ctx = (TUN_CTX *)MiniportAdapterContext; - if (InterlockedCompareExchange((LONG *)&ctx->State, TUN_STATE_HALTING, TUN_STATE_PAUSED) != TUN_STATE_PAUSED) - return; - ASSERT(!InterlockedGet64(&ctx->ActiveTransactionCount)); + InterlockedExchange((LONG *)&ctx->State, TUN_STATE_HALTING); /* Cancel pending IRPs to unblock waiting clients. */ for (IRP *pending_irp; (pending_irp = IoCsqRemoveNextIrp(&ctx->Device.ReadQueue.Csq, NULL)) != NULL;)