/* Free the IRP and its MDL */
IoFreeMdl(Irp->MdlAddress);
IoFreeIrp(Irp);
- Irp = NULL;
+
+ /* Fail */
+ _SEH2_YIELD(return NULL);
}
_SEH2_END;
-
- /* This is how we know if we failed during the probe */
- if (!Irp) return NULL;
}
else
{
/* Free the input buffer and IRP */
if (InputBuffer) ExFreePool(Irp->AssociatedIrp.SystemBuffer);
IoFreeIrp(Irp);
- Irp = NULL;
+
+ /* Fail */
+ _SEH2_YIELD(return NULL);
}
_SEH2_END;
-
- /* This is how we know if probing failed */
- if (!Irp) return NULL;
}
break;
PDRIVER_OBJECT DriverObject;
PIO_STACK_LOCATION StackPtr;
+ /* Make sure this is a valid IRP */
+ ASSERT(Irp->Type == IO_TYPE_IRP);
+
/* Get the Driver Object */
DriverObject = DeviceObject->DriverObject;
ErrorCode = PtrToUlong(LastStackPtr->Parameters.Others.Argument4);
}
- /* Get the Current Stack and skip it */
- StackPtr = IoGetCurrentIrpStackLocation(Irp);
- IoSkipCurrentIrpStackLocation(Irp);
-
- /* Loop the Stacks and complete the IRPs */
- do
+ /*
+ * Start the loop with the current stack and point the IRP to the next stack
+ * and then keep incrementing the stack as we loop through. The IRP should
+ * always point to the next stack location w.r.t the one currently being
+ * analyzed, so completion routine code will see the appropriate value.
+ * Because of this, we must loop until the current stack location is +1 of
+ * the stack count, because when StackPtr is at the end, CurrentLocation is +1.
+ */
+ for (StackPtr = IoGetCurrentIrpStackLocation(Irp),
+ Irp->CurrentLocation++,
+ Irp->Tail.Overlay.CurrentStackLocation++;
+ Irp->CurrentLocation <= (Irp->StackCount + 1);
+ StackPtr++,
+ Irp->CurrentLocation++,
+ Irp->Tail.Overlay.CurrentStackLocation++)
{
/* Set Pending Returned */
Irp->PendingReturned = StackPtr->Control & SL_PENDING_RETURNED;
/* Clear the stack location */
IopClearStackLocation(StackPtr);
}
-
- /* Move to next stack location and pointer */
- IoSkipCurrentIrpStackLocation(Irp);
- StackPtr++;
- } while (Irp->CurrentLocation <= (Irp->StackCount + 1));
+ }
/* Check if the IRP is an associated IRP */
if (Irp->Flags & IRP_ASSOCIATED_IRP)