[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] SDV: RemoveLock rule violations


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Mon, 7 Feb 2022 13:15:03 +0000
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Mon, 07 Feb 2022 13:15:24 +0000
  • Ironport-data: A9a23:sxuvNahwSUkIiOf6nvCSPrMFX161QBcKZh0ujC45NGQN5FlHY01je htvWzvVM/uIZmLyfIt2ati+8x9XvcSEx4dmSAM9rXhmFy4b9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oAMKRCQ7InQLlbGILes1htZGEk0GE/NtTo5w7Rj2tQw3oDga++wk YiaT/P3aQfNNwFcagr424rbwP+4lK2v0N+wlgVWicFj5DcypVFMZH4sDfjZw0/DaptVBoaHq 9Prl9lVyI97EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPg/W+5PwZG8O4whlkeydx /1TuafhW1wwMpaPhf4vWiIIDAMuD5Z/reqvzXiX6aR/zmXDenrohf5vEFs3LcsT/eMf7WNmr KJCbmpXN1ba2rzwkOnTpupE36zPKOHsI44Z/GplzC3ZJf0nXYrCU+PB4towMDIY2JsTQKyAP ZtxhTxHMT2HWydCM3ssIZMSwdupjSHuUgxktwfAzUYwyzeKl1EguFT3C/LKe9rPXdsQkkuGq 2bu+2XiHgpcJNGZ0SCC8H+nmqnIhyyTZW4JPOTmrLgw2gTVnzFNTk1NPbemnRWnolCyYINNc FUYwWkzt5o7zxy0bInPZCTt9RZooSUgc9ZXFuQ77iSExazV/xuVCwA4c9JRVDA1nJRoHGJ3j zdli/usXGUy6+PNFRpx45/J9WvaBMQDEYMVicbopyMh6sKrnow8hwmnoj1LQP/s1Y2d9d0dL lm3QMkCa1c70JRjO0aTpwmvb9eQSn/hFF9d2+kvdjj5hj6Vnab8D2BS1XDV7OxbMKGSRUSbs X4PlqC2tb5SUcjczXXTEb9UR9lFAspp1xWG0DZS82QJrWzxqxZPg6gMiN2BGKuZGpldImK4C KMikQhQ+IVSLBOXgVxfOOqM5zAR5fG4T7zND6mMBvIXO8QZXFLXrUlGOB/Lt0iwwRdEuf9kY /+zL53zZUv2/Iw6lVJasc9GiuR1rs3/rEuOLa3GI+OPi+bHNCXLGOtabDNjrIkRtcu5nekcy P4HX+Pi9vmVeLeWjvD//dFBIFYUA2I8AJyq+cVbevTaelhtGX07Cu+XyrQkItQ3k6NQn+bO3 3e8Rk4Hlwav2SyZcV2HOiJ5dbfifZdjtnZnbyYiCkmlhio4aoG14aZBK5ZuJes79PZuxOJfR uUef5nSGexGTznKomxPbZT0oIF4Wg6sgAaCY3isbDQlJsYyTA3V4N70OADo8XBWXCawsMI/p Zym1x/aHsVfF1gzUp6OZav2nV2rvHUblOZjZGfyI4FeKBf27YxnCy3tlftrccsCHgrOm2mB3 AGMDBZG+eSU+90p8MPEjLyvppuyF7csBVJTGmTW4OrkNSTe+Wb/k4ZMXPzRIGLYXWLwvq6je f9U37f3N/hexARGtI91ErBKy6Mi5oSw++8Gn1o8RHibPU62Dr5AI2Wd2Zgdv6JA8bZVpA+qV x/d4dJdI7iIZJvoHVN5yNDJtQhfOSX4QgXv0Mk=
  • Ironport-hdrordr: A9a23:q1QAkqMLoxTlksBcTvmjsMiBIKoaSvp037Eqv3oedfUzSL3/qy nOpoVi6faaslYssR0b9exofZPwJE80lqQFhrX5X43SPzUO0VHAROoJgLcKgQeQfxEWntQtrJ uIGJIeNDSfNzdHZL7BkWuFL+o=
  • Ironport-sdr: g8FpLFlgfKj7It8i7CbBsFwQbDVy/61shntJ0d7oyeRsYt/YYC+BVR253ymQDA5klyQMBZ4NQB 5UBOnpBijngrgF6iry7NI95K12VNT+5gVKN/s/goOsPNh0vF3l5U2PW7luokiRVekQ0oLqSFxt cffRWVbpUlzgGhAdJOq6ECJWuFe7aQiRPZcITqIciQEh/UupJdtysYHMIFCGY+iAOPz4SrisZC rsNzAV2jOapwHb88uuW66YNB+YWegvaLtJkp/noFEL7ZLSrNqnkTImFVYFQGr5JAhKd8HztfGp 7S1nIRR1JGf155oI9NCyvpLM
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Calls to IoAcquireRemoveLock and IoReleaseRemoveLock should be paired within
the same dispatch entry point, unless the IoCompletionRoutine does some work.
Remove completion routines that are not required and call IoReleaseRemoveLock
after the IRP has been passed to IoCallDriver.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xenfilt/fdo.c | 284 ++++--------------------------------------
 src/xenfilt/pdo.c | 307 ++++------------------------------------------
 2 files changed, 46 insertions(+), 545 deletions(-)

diff --git a/src/xenfilt/fdo.c b/src/xenfilt/fdo.c
index 6a45b0f..63fa7b3 100644
--- a/src/xenfilt/fdo.c
+++ b/src/xenfilt/fdo.c
@@ -581,27 +581,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoQueryStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoQueryStopDevice(
     IN  PXENFILT_FDO    Fdo,
@@ -617,15 +596,10 @@ FdoQueryStopDevice(
     __FdoSetDevicePnpState(Fdo, StopPending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoQueryStopDeviceCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -636,27 +610,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoCancelStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoCancelStopDevice(
     IN  PXENFILT_FDO    Fdo,
@@ -673,15 +626,10 @@ FdoCancelStopDevice(
 
     __FdoRestoreDevicePnpState(Fdo, StopPending);
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoCancelStopDeviceCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -692,27 +640,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoStopDevice(
     IN  PXENFILT_FDO            Fdo,
@@ -739,15 +666,10 @@ FdoStopDevice(
     __FdoSetDevicePnpState(Fdo, Stopped);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoStopDeviceCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -758,27 +680,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoQueryRemoveDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoQueryRemoveDevice(
     IN  PXENFILT_FDO    Fdo,
@@ -794,15 +695,10 @@ FdoQueryRemoveDevice(
     __FdoSetDevicePnpState(Fdo, RemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoQueryRemoveDeviceCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -813,27 +709,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoCancelRemoveDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoCancelRemoveDevice(
     IN  PXENFILT_FDO    Fdo,
@@ -849,15 +724,10 @@ FdoCancelRemoveDevice(
     __FdoRestoreDevicePnpState(Fdo, RemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoCancelRemoveDeviceCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -868,27 +738,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoSurpriseRemovalCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoSurpriseRemoval(
     IN  PXENFILT_FDO    Fdo,
@@ -904,15 +753,10 @@ FdoSurpriseRemoval(
     __FdoSetDevicePnpState(Fdo, SurpriseRemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoSurpriseRemovalCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -974,10 +818,9 @@ FdoRemoveDevice(
 done:
     __FdoSetDevicePnpState(Fdo, Deleted);
 
-    IoReleaseRemoveLockAndWait(&Fdo->Dx->RemoveLock, Irp);
-
     status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+    IoReleaseRemoveLockAndWait(&Fdo->Dx->RemoveLock, Irp);
 
     __FdoAcquireMutex(Fdo);
     ASSERT3U(Fdo->References, !=, 0);
@@ -990,6 +833,8 @@ done:
         DriverReleaseMutex();
     }
 
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
     return status;
 
 fail1:
@@ -1159,26 +1004,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoDispatchPnpCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoDispatchPnp(
     IN  PXENFILT_FDO    Fdo,
@@ -1234,15 +1059,10 @@ FdoDispatchPnp(
         if (!NT_SUCCESS(status))
             goto fail1;
 
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               FdoDispatchPnpCompletion,
-                               Fdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
         break;
     }
 
@@ -1754,26 +1574,6 @@ FdoSystemPower(
     return STATUS_SUCCESS;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoDispatchPowerCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoDispatchPower(
     IN  PXENFILT_FDO    Fdo,
@@ -1794,15 +1594,10 @@ FdoDispatchPower(
 
     if (MinorFunction != IRP_MN_QUERY_POWER &&
         MinorFunction != IRP_MN_SET_POWER) {
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               FdoDispatchPowerCompletion,
-                               Fdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
         goto done;
     }
@@ -1840,15 +1635,10 @@ FdoDispatchPower(
         break;
 
     default:
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               FdoDispatchPowerCompletion,
-                               Fdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
         break;
     }
 
@@ -1870,27 +1660,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-FdoDispatchDefaultCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 FdoDispatchDefault(
     IN  PXENFILT_FDO    Fdo,
@@ -1903,15 +1672,10 @@ FdoDispatchDefault(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           FdoDispatchDefaultCompletion,
-                           Fdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
     return status;
 
diff --git a/src/xenfilt/pdo.c b/src/xenfilt/pdo.c
index b3569a3..741c2f3 100644
--- a/src/xenfilt/pdo.c
+++ b/src/xenfilt/pdo.c
@@ -523,27 +523,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoQueryStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoQueryStopDevice(
     IN  PXENFILT_PDO    Pdo,
@@ -559,15 +538,10 @@ PdoQueryStopDevice(
     __PdoSetDevicePnpState(Pdo, StopPending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoQueryStopDeviceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -578,27 +552,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoCancelStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoCancelStopDevice(
     IN  PXENFILT_PDO    Pdo,
@@ -615,15 +568,10 @@ PdoCancelStopDevice(
 
     __PdoRestoreDevicePnpState(Pdo, StopPending);
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoCancelStopDeviceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -634,27 +582,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoStopDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoStopDevice(
     IN  PXENFILT_PDO    Pdo,
@@ -682,15 +609,10 @@ done:
     __PdoSetDevicePnpState(Pdo, Stopped);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoStopDeviceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -701,27 +623,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoQueryRemoveDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoQueryRemoveDevice(
     IN  PXENFILT_PDO    Pdo,
@@ -737,15 +638,10 @@ PdoQueryRemoveDevice(
     __PdoSetDevicePnpState(Pdo, RemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoQueryRemoveDeviceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -756,27 +652,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoCancelRemoveDeviceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoCancelRemoveDevice(
     IN  PXENFILT_PDO    Pdo,
@@ -792,15 +667,10 @@ PdoCancelRemoveDevice(
     __PdoRestoreDevicePnpState(Pdo, RemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoCancelRemoveDeviceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -811,27 +681,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoSurpriseRemovalCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoSurpriseRemoval(
     IN  PXENFILT_PDO    Pdo,
@@ -847,15 +696,10 @@ PdoSurpriseRemoval(
     __PdoSetDevicePnpState(Pdo, SurpriseRemovePending);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoSurpriseRemovalCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -930,27 +774,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoQueryInterfaceCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 #define DEFINE_PDO_QUERY_INTERFACE(_Interface)                      \
 static NTSTATUS                                                     \
 PdoQuery ## _Interface ## Interface(                                \
@@ -1041,15 +864,10 @@ PdoQueryInterface(
     }
 
 done:
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoQueryInterfaceCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
@@ -1283,26 +1101,6 @@ PdoEject(
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoDispatchPnpCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoDispatchPnp(
     IN  PXENFILT_PDO    Pdo,
@@ -1370,15 +1168,10 @@ PdoDispatchPnp(
         if (!NT_SUCCESS(status))
             goto fail1;
 
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               PdoDispatchPnpCompletion,
-                               Pdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
         break;
     }
 
@@ -1894,26 +1687,6 @@ PdoSystemPower(
     return STATUS_SUCCESS;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoDispatchPowerCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoDispatchPower(
     IN  PXENFILT_PDO    Pdo,
@@ -1934,15 +1707,10 @@ PdoDispatchPower(
 
     if (MinorFunction != IRP_MN_QUERY_POWER &&
         MinorFunction != IRP_MN_SET_POWER) {
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               PdoDispatchPowerCompletion,
-                               Pdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
         goto done;
     }
@@ -1980,15 +1748,10 @@ PdoDispatchPower(
         break;
 
     default:
-        IoCopyCurrentIrpStackLocationToNext(Irp);
-        IoSetCompletionRoutine(Irp,
-                               PdoDispatchPowerCompletion,
-                               Pdo,
-                               TRUE,
-                               TRUE,
-                               TRUE);
+        IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
         break;
     }
 
@@ -2010,27 +1773,6 @@ fail1:
     return status;
 }
 
-__drv_functionClass(IO_COMPLETION_ROUTINE)
-__drv_sameIRQL
-static NTSTATUS
-PdoDispatchDefaultCompletion(
-    IN  PDEVICE_OBJECT  DeviceObject,
-    IN  PIRP            Irp,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-
-    UNREFERENCED_PARAMETER(DeviceObject);
-
-    if (Irp->PendingReturned)
-        IoMarkIrpPending(Irp);
-
-    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-
-    return STATUS_SUCCESS;
-}
-
 static NTSTATUS
 PdoDispatchDefault(
     IN  PXENFILT_PDO    Pdo,
@@ -2043,15 +1785,10 @@ PdoDispatchDefault(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-    IoSetCompletionRoutine(Irp,
-                           PdoDispatchDefaultCompletion,
-                           Pdo,
-                           TRUE,
-                           TRUE,
-                           TRUE);
+    IoSkipCurrentIrpStackLocation(Irp);
 
     status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+    IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
 
     return status;
 
-- 
2.33.0.windows.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.