Index: trunk/src/VBox/HostDrivers/VBoxUSB/win/dev/VBoxUsbRt.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxUSB/win/dev/VBoxUsbRt.cpp	(revision 62699)
+++ trunk/src/VBox/HostDrivers/VBoxUSB/win/dev/VBoxUsbRt.cpp	(revision 62702)
@@ -3,4 +3,5 @@
  * VBox USB R0 runtime
  */
+
 /*
  * Copyright (C) 2011-2016 Oracle Corporation
@@ -15,4 +16,7 @@
  */
 
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
 #include "VBoxUsbCmn.h"
 #include "../cmn/VBoxUsbIdc.h"
@@ -22,5 +26,10 @@
 #include <iprt/assert.h>
 #include <VBox/log.h>
-#define _USBD_
+
+
+/*********************************************************************************************************************************
+*   Defined Constants And Macros                                                                                                 *
+*********************************************************************************************************************************/
+#define _USBD_ /** @todo r=bird: What is this?? */
 
 #define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
@@ -28,4 +37,7 @@
 #define VBOXUSB_MAGIC  0xABCF1423
 
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
 typedef struct VBOXUSB_URB_CONTEXT
 {
@@ -47,30 +59,24 @@
 } VBOXUSB_SETUP, *PVBOXUSB_SETUP;
 
+
+
 static bool vboxUsbRtCtxSetOwner(PVBOXUSBDEV_EXT pDevExt, PFILE_OBJECT pFObj)
 {
-    bool bRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, pFObj, NULL);
-    if (bRc)
-    {
+    bool fRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, pFObj, NULL);
+    if (fRc)
         LogFunc(("pDevExt (0x%x) Owner(0x%x) acquired\n", pFObj));
-    }
     else
-    {
         LogFunc(("pDevExt (0x%x) Owner(0x%x) FAILED!!\n", pFObj));
-    }
-    return bRc;
+    return fRc;
 }
 
 static bool vboxUsbRtCtxReleaseOwner(PVBOXUSBDEV_EXT pDevExt, PFILE_OBJECT pFObj)
 {
-    bool bRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, NULL, pFObj);
-    if (bRc)
-    {
+    bool fRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, NULL, pFObj);
+    if (fRc)
         LogFunc(("pDevExt (0x%x) Owner(0x%x) released\n", pFObj));
-    }
     else
-    {
         LogFunc(("pDevExt (0x%x) Owner(0x%x) release: is NOT an owner\n", pFObj));
-    }
-    return bRc;
+    return fRc;
 }
 
@@ -100,6 +106,9 @@
         if (NT_SUCCESS(Status))
         {
-            if (Version.u32Major == VBOXUSBIDC_VERSION_MAJOR
-                    && Version.u32Minor >= VBOXUSBIDC_VERSION_MINOR)
+            if (   Version.u32Major == VBOXUSBIDC_VERSION_MAJOR
+#if VBOXUSBIDC_VERSION_MINOR != 0
+                && Version.u32Minor >= VBOXUSBIDC_VERSION_MINOR
+#endif
+               )
                 return STATUS_SUCCESS;
             AssertFailed();
@@ -408,6 +417,6 @@
     {
         vboxUsbRtFreeCachedDescriptors(pDevExt);
-        bool bRc = vboxUsbRtCtxReleaseOwner(pDevExt, pFObj);
-        Assert(bRc);
+        bool fRc = vboxUsbRtCtxReleaseOwner(pDevExt, pFObj);
+        Assert(fRc); NOREF(fRc);
     }
     else
@@ -464,12 +473,12 @@
 {
     PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
-    PUSBSUP_GETDEV pDev  = (PUSBSUP_GETDEV)pIrp->AssociatedIrp.SystemBuffer;
-    NTSTATUS Status = STATUS_SUCCESS;
+    PUSBSUP_GETDEV pDev = (PUSBSUP_GETDEV)pIrp->AssociatedIrp.SystemBuffer;
     ULONG cbOut = 0;
 
     /* don't check for owner since this request is allowed for non-owners as well */
-
-    if (pDev && pSl->Parameters.DeviceIoControl.InputBufferLength == sizeof (*pDev)
-             && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof (*pDev))
+    NTSTATUS Status;
+    if (   pDev
+        && pSl->Parameters.DeviceIoControl.InputBufferLength  == sizeof(*pDev)
+        && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof(*pDev))
     {
         Status = VBoxUsbToolGetDeviceSpeed(pDevExt->pLowerDO, &pDevExt->Rt.fIsHighSpeed);
@@ -483,7 +492,5 @@
     }
     else
-    {
         Status = STATUS_INVALID_PARAMETER;
-    }
 
     Assert(Status != STATUS_PENDING);
@@ -495,42 +502,40 @@
 static NTSTATUS vboxUsbRtDispatchUsbReset(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
 {
-    PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
-    PFILE_OBJECT pFObj = pSl->FileObject;
-    PUSBSUP_GETDEV pDev  = (PUSBSUP_GETDEV)pIrp->AssociatedIrp.SystemBuffer;
-    NTSTATUS Status = STATUS_SUCCESS;
-
-    do
-    {
-        if (!pFObj)
+    PIO_STACK_LOCATION  pSl   = IoGetCurrentIrpStackLocation(pIrp);
+    PFILE_OBJECT        pFObj = pSl->FileObject;
+    NTSTATUS            rcNt;
+    if (pFObj)
+    {
+        if (vboxUsbRtCtxIsOwner(pDevExt, pFObj))
+        {
+            if (   pIrp->AssociatedIrp.SystemBuffer == NULL
+                && pSl->Parameters.DeviceIoControl.InputBufferLength == 0
+                && pSl->Parameters.DeviceIoControl.OutputBufferLength == 0)
+            {
+                rcNt = VBoxUsbToolIoInternalCtlSendSync(pDevExt->pLowerDO, IOCTL_INTERNAL_USB_RESET_PORT, NULL, NULL);
+                Assert(NT_SUCCESS(rcNt));
+            }
+            else
+            {
+                AssertFailed();
+                rcNt = STATUS_INVALID_PARAMETER;
+            }
+        }
+        else
         {
             AssertFailed();
-            Status = STATUS_INVALID_PARAMETER;
-            break;
-        }
-
-        if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
-        {
-            AssertFailed();
-            Status = STATUS_ACCESS_DENIED;
-            break;
-        }
-
-        if (pIrp->AssociatedIrp.SystemBuffer
-                || pSl->Parameters.DeviceIoControl.InputBufferLength
-                || pSl->Parameters.DeviceIoControl.OutputBufferLength)
-        {
-            AssertFailed();
-            Status = STATUS_INVALID_PARAMETER;
-            break;
-        }
-
-        Status = VBoxUsbToolIoInternalCtlSendSync(pDevExt->pLowerDO, IOCTL_INTERNAL_USB_RESET_PORT, NULL, NULL);
-        Assert(NT_SUCCESS(Status));
-    } while (0);
-
-    Assert(Status != STATUS_PENDING);
-    VBoxDrvToolIoComplete(pIrp, Status, 0);
+            rcNt = STATUS_ACCESS_DENIED;
+        }
+    }
+    else
+    {
+        AssertFailed();
+        rcNt = STATUS_INVALID_PARAMETER;
+    }
+
+    Assert(rcNt != STATUS_PENDING);
+    VBoxDrvToolIoComplete(pIrp, rcNt, 0);
     vboxUsbDdiStateRelease(pDevExt);
-    return Status;
+    return rcNt;
 }
 
@@ -770,6 +775,6 @@
     NTSTATUS Status = STATUS_SUCCESS;
     PURB pUrb;
-    PUSBD_INTERFACE_INFORMATION pNewIFInfo;
-    VBOXUSB_PIPE_INFO *pNewPipeInfo;
+    PUSBD_INTERFACE_INFORMATION pNewIFInfo = NULL;
+    VBOXUSB_PIPE_INFO *pNewPipeInfo = NULL;
 
     if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo)
@@ -898,7 +903,5 @@
 {
     if (EndPointAddress == 0)
-    {
         return pDevExt->Rt.hPipe0;
-    }
 
     for (ULONG i = 0; i < pDevExt->Rt.uNumInterfaces; i++)
@@ -1026,4 +1029,6 @@
 static NTSTATUS vboxUsbRtUrbSendCompletion(PDEVICE_OBJECT pDevObj, IRP *pIrp, void *pvContext)
 {
+    RT_NOREF1(pDevObj);
+
     if (!pvContext)
     {
@@ -1076,5 +1081,5 @@
             default:
                 pUrbInfo->error = USBSUP_XFER_DNR;
-            break;
+                break;
         }
 
@@ -1300,5 +1305,5 @@
                  * data length is therefore pUrb->len - 8
                  */
-                PVBOXUSB_SETUP pSetup = (PVBOXUSB_SETUP)pUrb->UrbControlTransfer.SetupPacket;
+                //PVBOXUSB_SETUP pSetup = (PVBOXUSB_SETUP)pUrb->UrbControlTransfer.SetupPacket;
                 memcpy(pUrb->UrbControlTransfer.SetupPacket, pBuffer, min(sizeof (pUrb->UrbControlTransfer.SetupPacket), pUrbInfo->len));
 
@@ -1488,6 +1493,7 @@
     NTSTATUS Status = STATUS_SUCCESS;
 
-    if (pVer && pSl->Parameters.DeviceIoControl.InputBufferLength == 0
-             && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof (*pVer))
+    if (   pVer
+        && pSl->Parameters.DeviceIoControl.InputBufferLength == 0
+        && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof(*pVer))
     {
         pVer->u32Major = USBDRV_MAJOR_VERSION;
@@ -1515,12 +1521,8 @@
 DECLHIDDEN(NTSTATUS) vboxUsbRtCreate(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
 {
+    RT_NOREF1(pDevExt);
     PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
     PFILE_OBJECT pFObj = pSl->FileObject;
-    if (!pFObj)
-    {
-        AssertFailed();
-        return STATUS_INVALID_PARAMETER;
-    }
-
+    AssertReturn(pFObj, STATUS_INVALID_PARAMETER);
     return STATUS_SUCCESS;
 }
@@ -1543,51 +1545,38 @@
     {
         case SUPUSB_IOCTL_USB_CLAIM_DEVICE:
-        {
             return vboxUsbRtDispatchClaimDevice(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_RELEASE_DEVICE:
-        {
             return vboxUsbRtDispatchReleaseDevice(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_GET_DEVICE:
-        {
             return vboxUsbRtDispatchGetDevice(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_RESET:
-        {
             return vboxUsbRtDispatchUsbReset(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_SET_CONFIG:
-        {
             return vboxUsbRtDispatchUsbSetConfig(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_SELECT_INTERFACE:
-        {
             return vboxUsbRtDispatchUsbSelectInterface(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_CLEAR_ENDPOINT:
-        {
             return vboxUsbRtDispatchUsbClearEndpoint(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_USB_ABORT_ENDPOINT:
-        {
             return vboxUsbRtDispatchUsbAbortEndpoint(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_SEND_URB:
-        {
             return vboxUsbRtDispatchSendUrb(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_IS_OPERATIONAL:
-        {
             return vboxUsbRtDispatchIsOperational(pDevExt, pIrp);
-        }
+
         case SUPUSB_IOCTL_GET_VERSION:
-        {
             return vboxUsbRtDispatchGetVersion(pDevExt, pIrp);
-        }
+
         default:
-        {
             return vboxUsbRtDispatchDefault(pDevExt, pIrp);
-        }
-    }
-}
+    }
+}
