PiSwIrpCleanup

VOID __fastcall PiSwIrpCleanup(_PI_SWD_OBJECT *SwDeviceObject){
  INT64 v1; 
  _IRP *v2; 
  _ETHREAD *CurrentThread; 
  __int64 v5; 
  char v6; 
  wchar_t *v7; 
  _ADAPTER_OBJECT *v8; 
  __int64 v9; 
  _PI_SWD_OBJECT *SwDevice; 
  _UNICODE_STRING DestinationString; 

  v2 = 0i64;
  DestinationString = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  --CurrentThread->Tcb.KernelApcDisable;
  ExAcquireResourceExclusiveLite((UINT64)&PiSwLockObj, 1, v1);
  if( !SwDeviceObject[45] )
    goto LABEL_11;
  v5 = *((_QWORD *)SwDeviceObject + 14);
  v6 = 0;
  while( 1 )
  {
    v7 = *(wchar_t **)(v5 + 8);
    if( wcsnicmp(v7, L"SWD\\", 4u) )
      break;
    SwDevice = PiSwFindSwDevice(v7);
    if( !SwDevice )
      goto LABEL_11;
    if( !SwDevice[45] && (SwDevice[1] & 2) == 0 )
      goto LABEL_6;
    v5 = *((_QWORD *)SwDevice + 14);
  }
  RtlInitUnicodeString(&DestinationString, v7);
  v8 = (_ADAPTER_OBJECT *)PnpDeviceObjectFromDeviceInstanceWithTag((__int64)&DestinationString, 0x746C6644u);
  if( v8 )
    HalPutDmaAdapter(v8);
  else
LABEL_11:
    v6 = 1;
LABEL_6:
  v9 = *((_QWORD *)SwDeviceObject + 18);
  if( v9 && _InterlockedExchange64((volatile __int64 *)(v9 + 104), 0i64) )
  {
    v2 = (_IRP *)*((_QWORD *)SwDeviceObject + 18);
    *((_QWORD *)SwDeviceObject + 18) = 0i64;
  }
  SwDeviceObject[1] &= ~1u;
  if( v6 )
  {
    PiSwCloseDescendants((_UNICODE_STRING *)(SwDeviceObject + 18));
    PiSwCloseDevice(SwDeviceObject);
  }
  ExReleaseResourceLite(&PiSwLockObj);
  KeLeaveCriticalRegionThread(KeGetCurrentThread());
  if( v2 )
  {
    v2->IoStatus.Information = 0i64;
    v2->IoStatus.Status = -1073741536;
    IofCompleteRequest(v2, 0);
  }
}

Referenced by:

PiSwDispatch
PiSwIrpStartCreateWorker