[CRT] Massively improve performance of rand_s
[reactos.git] / drivers / usb / usbccgp / misc.c
index 1cb81f6..9242fcf 100644 (file)
 
 #include "usbccgp.h"
 
-//
-// driver verifier
-//
+#define NDEBUG
+#include <debug.h>
+
+/* Driver verifier */
 IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
 
 NTSTATUS
 NTAPI
 USBSTOR_SyncForwardIrpCompletionRoutine(
     PDEVICE_OBJECT DeviceObject,
-    PIRP Irp, 
+    PIRP Irp,
     PVOID Context)
 {
     if (Irp->PendingReturned)
@@ -30,58 +31,6 @@ USBSTOR_SyncForwardIrpCompletionRoutine(
     return STATUS_MORE_PROCESSING_REQUIRED;
 }
 
-NTSTATUS
-NTAPI
-USBCCGP_SyncForwardIrp(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-    KEVENT Event;
-    NTSTATUS Status;
-
-    //
-    // initialize event
-    //
-    KeInitializeEvent(&Event, NotificationEvent, FALSE);
-
-    //
-    // copy irp stack location
-    //
-    IoCopyCurrentIrpStackLocationToNext(Irp);
-
-    //
-    // set completion routine
-    //
-    IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE);
-
-
-    //
-    // call driver
-    //
-    Status = IoCallDriver(DeviceObject, Irp);
-
-    //
-    // check if pending
-    //
-    if (Status == STATUS_PENDING)
-    {
-        //
-        // wait for the request to finish
-        //
-        KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
-
-        //
-        // copy status code
-        //
-        Status = Irp->IoStatus.Status;
-    }
-
-    //
-    // done
-    //
-    return Status;
-}
-
 NTSTATUS
 USBCCGP_SyncUrbRequest(
     IN PDEVICE_OBJECT DeviceObject,
@@ -92,72 +41,52 @@ USBCCGP_SyncUrbRequest(
     KEVENT Event;
     NTSTATUS Status;
 
-    //
-    // allocate irp
-    //
+    /* Allocate irp */
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
     if (!Irp)
     {
-        //
-        // no memory
-        //
+        /* No memory */
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-    //
-    // initialize event
-    //
+    /* Initialize event */
     KeInitializeEvent(&Event, NotificationEvent, FALSE);
 
-
-    //
-    // get next stack location
-    //
+    /* Get next stack location */
     IoStack = IoGetNextIrpStackLocation(Irp);
 
-    //
-    // initialize stack location
-    //
+    /* Initialize stack location */
     IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
     IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
     IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
     IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
-    //
-    // setup completion routine
-    //
-    IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE);
+    /* Setup completion routine */
+    IoSetCompletionRoutine(Irp,
+                           USBSTOR_SyncForwardIrpCompletionRoutine,
+                           &Event,
+                           TRUE,
+                           TRUE,
+                           TRUE);
 
-    //
-    // call driver
-    //
+    /* Call driver */
     Status = IoCallDriver(DeviceObject, Irp);
 
-    //
-    // check if request is pending
-    //
+    /* Check if request is pending */
     if (Status == STATUS_PENDING)
     {
-        //
-        // wait for completion
-        //
+        /* Wait for completion */
         KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
 
-        //
-        // update status
-        //
+        /* Update status */
         Status = Irp->IoStatus.Status;
     }
 
-    //
-    // free irp
-    //
+    /* Free irp */
     IoFreeIrp(Irp);
 
-    //
-    // done
-    //
+    /* Done */
     return Status;
 }
 
@@ -166,32 +95,15 @@ AllocateItem(
     IN POOL_TYPE PoolType,
     IN ULONG ItemSize)
 {
-    //
-    // allocate item
-    //
-    PVOID Item = ExAllocatePoolWithTag(PoolType, ItemSize, USBCCPG_TAG);
-
-    if (Item)
-    {
-        //
-        // zero item
-        //
-        RtlZeroMemory(Item, ItemSize);
-    }
-
-    //
-    // return element
-    //
-    return Item;
+    /* Allocate, zero and return item */
+    return ExAllocatePoolZero(PoolType, ItemSize, USBCCPG_TAG);
 }
 
 VOID
 FreeItem(
     IN PVOID Item)
 {
-    //
-    // free item
-    //
+    /* Free item */
     ExFreePoolWithTag(Item, USBCCPG_TAG);
 }
 
@@ -202,23 +114,30 @@ DumpFunctionDescriptor(
 {
     ULONG Index, SubIndex;
 
-
-    DPRINT1("FunctionCount %lu\n", FunctionDescriptorCount);
-    for(Index = 0; Index < FunctionDescriptorCount; Index++)
+    DPRINT("FunctionCount %lu\n", FunctionDescriptorCount);
+    for (Index = 0; Index < FunctionDescriptorCount; Index++)
     {
-        DPRINT1("Function %lu\n", Index);
-        DPRINT1("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
-        DPRINT1("HardwareId %wZ\n", &FunctionDescriptor[Index].HardwareId);
-        DPRINT1("CompatibleId %wZ\n", &FunctionDescriptor[Index].CompatibleId);
-        DPRINT1("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
-        DPRINT1("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
+        DPRINT("Function %lu\n", Index);
+        DPRINT("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
+        DPRINT("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
+        DPRINT("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
+        DPRINT("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
+        DPRINT("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
 
         for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
         {
-            DPRINT1(" Interface %p\n", FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
-            DPRINT1(" Interface InterfaceNumber %x\n", FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
-            DPRINT1(" Interface Alternate %x\n", FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
+            DPRINT(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
+            DPRINT(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
+            DPRINT(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
+            DPRINT(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
+            DPRINT(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
+            DPRINT(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
+            DPRINT(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
+            DPRINT(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
+            DPRINT(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
+            DPRINT(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
+            DPRINT(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
+            DPRINT(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
         }
     }
-
-}
\ No newline at end of file
+}