win-pvdrivers

changeset 979:8f483a2b2991

Fix up PREfast warnings
author James Harper <james.harper@bendigoit.com.au>
date Sun Apr 15 19:47:10 2012 +1000 (2012-04-15)
parents 965ad76636ed
children ea3c61839ff5
files shutdownmon/shutdownmon.c xennet/xennet5.c xennet/xennet5_rx.c xennet/xennet6.c xennet/xennet6_tx.c xenpci/xenpci.c xenpci/xenpci_dbgprint.c xenpci/xenpci_fdo.c xenusb/xenusb_devurb.c xenusb/xenusb_fdo.c xenusb/xenusb_hub.c xenvbd/xenvbd_scsiport.c xenvbd/xenvbd_storport.c
line diff
     1.1 --- a/shutdownmon/shutdownmon.c	Sun Apr 15 18:57:34 2012 +1000
     1.2 +++ b/shutdownmon/shutdownmon.c	Sun Apr 15 19:47:10 2012 +1000
     1.3 @@ -187,10 +187,15 @@ do_hibernate()
     1.4    printf("token_handle = %p\n", token_handle);
     1.5  
     1.6    tp = malloc(sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES));
     1.7 +  if (!tp) {
     1.8 +    printf("malloc failed\n");
     1.9 +    CloseHandle(token_handle);
    1.10 +    return;
    1.11 +  }
    1.12    tp->PrivilegeCount = 1;
    1.13 -  if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid))
    1.14 -  {
    1.15 +  if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid)) {
    1.16      printf("LookupPrivilegeValue failed\n");
    1.17 +    free(tp);
    1.18      CloseHandle(token_handle);
    1.19      return;
    1.20    }
    1.21 @@ -198,15 +203,16 @@ do_hibernate()
    1.22    tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    1.23    if (!AdjustTokenPrivileges(token_handle, FALSE, tp, 0, NULL, NULL))
    1.24    {
    1.25 +    printf("AdjustTokenPrivileges failed\n");
    1.26 +    free(tp);
    1.27      CloseHandle(token_handle);
    1.28      return;
    1.29    }
    1.30  
    1.31 -  if (!SetSuspendState(TRUE, FALSE, FALSE))
    1.32 -  {
    1.33 +  if (!SetSuspendState(TRUE, FALSE, FALSE)) {
    1.34      printf("hibernate failed\n");
    1.35    }
    1.36 -
    1.37 +  free(tp);
    1.38    CloseHandle(token_handle);
    1.39  }
    1.40  
    1.41 @@ -227,10 +233,16 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.42    printf("token_handle = %p\n", token_handle);
    1.43  
    1.44    tp = malloc(sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES));
    1.45 +  if (!tp) {
    1.46 +    printf("malloc failed\n");
    1.47 +    CloseHandle(token_handle);
    1.48 +    return;
    1.49 +  }
    1.50    tp->PrivilegeCount = 1;
    1.51    if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid))
    1.52    {
    1.53      printf("LookupPrivilegeValue failed\n");
    1.54 +    free(tp);
    1.55      CloseHandle(token_handle);
    1.56      return;
    1.57    }
    1.58 @@ -238,10 +250,11 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.59    tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    1.60    if (!AdjustTokenPrivileges(token_handle, FALSE, tp, 0, NULL, NULL))
    1.61    {
    1.62 +    free(tp);
    1.63      CloseHandle(token_handle);
    1.64      return;
    1.65    }
    1.66 -
    1.67 +  #pragma warning(suppress:28159)
    1.68    if (!InitiateSystemShutdownEx(NULL, NULL, 0, TRUE, bRebootAfterShutdown, SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER))
    1.69    {
    1.70      printf("InitiateSystemShutdownEx failed\n");
    1.71 @@ -249,6 +262,7 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.72    }
    1.73    printf("InitiateSystemShutdownEx succeeded\n");
    1.74  
    1.75 +  free(tp);
    1.76    CloseHandle(token_handle);
    1.77  }
    1.78  
     2.1 --- a/xennet/xennet5.c	Sun Apr 15 18:57:34 2012 +1000
     2.2 +++ b/xennet/xennet5.c	Sun Apr 15 19:47:10 2012 +1000
     2.3 @@ -27,6 +27,7 @@ DRIVER_INITIALIZE DriverEntry;
     2.4  static IO_WORKITEM_ROUTINE XenNet_ResumeWorkItem;
     2.5  #if (VER_PRODUCTBUILD >= 7600)
     2.6  static KDEFERRED_ROUTINE XenNet_SuspendResume;
     2.7 +static KDEFERRED_ROUTINE XenNet_RxTxDpc;
     2.8  #endif
     2.9  
    2.10  #pragma NDIS_INIT_FUNCTION(DriverEntry)
     3.1 --- a/xennet/xennet5_rx.c	Sun Apr 15 18:57:34 2012 +1000
     3.2 +++ b/xennet/xennet5_rx.c	Sun Apr 15 19:47:10 2012 +1000
     3.3 @@ -371,14 +371,17 @@ XenNet_SumPacketData(
     3.4    //FUNCTION_ENTER();
     3.5  
     3.6    NdisGetFirstBufferFromPacketSafe(packet, &mdl, &buffer, &buffer_length, &total_length, NormalPagePriority);
     3.7 +  if (!buffer) {
     3.8 +    FUNCTION_MSG("NdisGetFirstBufferFromPacketSafe failed, buffer == NULL\n");
     3.9 +    return FALSE;
    3.10 +  }
    3.11    ASSERT(mdl);
    3.12  
    3.13    ip4_length = GET_NET_PUSHORT(&buffer[XN_HDR_SIZE + 2]);
    3.14    data_length = ip4_length + XN_HDR_SIZE;
    3.15    
    3.16 -  if ((USHORT)data_length > total_length)
    3.17 -  {
    3.18 -    KdPrint((__DRIVER_NAME "     Size Mismatch %d (ip4_length + XN_HDR_SIZE) != %d (total_length)\n", ip4_length + XN_HDR_SIZE, total_length));
    3.19 +  if ((USHORT)data_length > total_length) {
    3.20 +    FUNCTION_MSG("Size Mismatch %d (ip4_length + XN_HDR_SIZE) != %d (total_length)\n", ip4_length + XN_HDR_SIZE, total_length);
    3.21      return FALSE;
    3.22    }
    3.23  
    3.24 @@ -692,6 +695,7 @@ XenNet_ReturnPacket(
    3.25        /* this isn't actually a share_buffer, it is some memory allocated for the header - just free it */
    3.26        PUCHAR va;
    3.27        UINT len;
    3.28 +      #pragma warning(suppress:28193) /* va is valid because it was mapped earlier */
    3.29        NdisQueryBufferSafe(buffer, &va, &len, NormalPagePriority);
    3.30        NdisFreeToNPagedLookasideList(&xi->rx_lookaside_list, va - sizeof(shared_buffer_t));
    3.31        NdisFreeBuffer(buffer);
     4.1 --- a/xennet/xennet6.c	Sun Apr 15 18:57:34 2012 +1000
     4.2 +++ b/xennet/xennet6.c	Sun Apr 15 19:47:10 2012 +1000
     4.3 @@ -27,6 +27,7 @@ DRIVER_INITIALIZE DriverEntry;
     4.4  static IO_WORKITEM_ROUTINE XenNet_ResumeWorkItem;
     4.5  #if (VER_PRODUCTBUILD >= 7600)
     4.6  static KDEFERRED_ROUTINE XenNet_SuspendResume;
     4.7 +static KDEFERRED_ROUTINE XenNet_RxTxDpc;
     4.8  #endif
     4.9  
    4.10  #pragma NDIS_INIT_FUNCTION(DriverEntry)
     5.1 --- a/xennet/xennet6_tx.c	Sun Apr 15 18:57:34 2012 +1000
     5.2 +++ b/xennet/xennet6_tx.c	Sun Apr 15 19:47:10 2012 +1000
     5.3 @@ -518,7 +518,8 @@ XenNet_TxBufferGC(struct xennet_info *xi
     5.4          PUCHAR header;
     5.5          nb = shadow->nb;
     5.6          mdl = NET_BUFFER_CURRENT_MDL(nb);
     5.7 -        header = MmGetSystemAddressForMdlSafe(mdl, LowPagePriority); /* already mapped so guaranteed to work */
     5.8 +        #pragma warning(suppress:28193) /* already mapped so guaranteed to work */
     5.9 +        header = MmGetSystemAddressForMdlSafe(mdl, LowPagePriority);
    5.10          header += NET_BUFFER_CURRENT_MDL_OFFSET(nb);
    5.11  
    5.12          xi->stats.ifHCOutOctets += nb->DataLength;
     6.1 --- a/xenpci/xenpci.c	Sun Apr 15 18:57:34 2012 +1000
     6.2 +++ b/xenpci/xenpci.c	Sun Apr 15 19:47:10 2012 +1000
     6.3 @@ -405,6 +405,7 @@ extern PULONG InitSafeBootMode;
     6.4  VOID
     6.5  XenPci_HideQemuDevices()
     6.6  {
     6.7 +  #pragma warning(suppress:28138)
     6.8    WRITE_PORT_USHORT(XEN_IOPORT_DEVICE_MASK, (USHORT)qemu_hide_flags_value); //QEMU_UNPLUG_ALL_IDE_DISKS|QEMU_UNPLUG_ALL_NICS);
     6.9    KdPrint((__DRIVER_NAME "     Disabled qemu devices %02x\n", qemu_hide_flags_value));
    6.10  }
    6.11 @@ -412,15 +413,20 @@ XenPci_HideQemuDevices()
    6.12  static BOOLEAN
    6.13  XenPci_CheckHideQemuDevices()
    6.14  {
    6.15 +  #pragma warning(suppress:28138)
    6.16    if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2)
    6.17    {
    6.18 +    #pragma warning(suppress:28138)
    6.19      qemu_protocol_version = READ_PORT_UCHAR(XEN_IOPORT_VERSION);
    6.20      KdPrint((__DRIVER_NAME "     Version = %d\n", qemu_protocol_version));
    6.21      switch(qemu_protocol_version)
    6.22      {
    6.23      case 1:
    6.24 +      #pragma warning(suppress:28138)
    6.25        WRITE_PORT_USHORT(XEN_IOPORT_PRODUCT, XEN_PV_PRODUCT_NUMBER);
    6.26 +      #pragma warning(suppress:28138)
    6.27        WRITE_PORT_ULONG(XEN_IOPORT_BUILD, XEN_PV_PRODUCT_BUILD);
    6.28 +      #pragma warning(suppress:28138)
    6.29        if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) != 0x49d2)
    6.30        {
    6.31          KdPrint((__DRIVER_NAME "     Blacklisted\n"));
    6.32 @@ -622,6 +628,12 @@ XenPci_InitialBalloonDown()
    6.33  
    6.34    /* this code is mostly duplicated from the actual balloon thread... too hard to reuse */
    6.35    pfns = ExAllocatePoolWithTag(NonPagedPool, max(BALLOON_UNIT_PAGES, (64 << 8)) * sizeof(xen_pfn_t), XENPCI_POOL_TAG);
    6.36 +  if (!pfns) {
    6.37 +      /* If we can't balloon down then we are going to crash in strange ways later. Better to bug check now. */
    6.38 +      KdPrint((__DRIVER_NAME "     Initial Balloon Down failed - no memory for pfn list\n"));
    6.39 +      #pragma warning(suppress:28159)
    6.40 +      KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000003, 0x00000000, 0x00000000, 0x00000000);
    6.41 +  }
    6.42    curr_pfns_offset = 0;
    6.43    /* this makes sure we balloon up to the next multiple of BALLOON_UNITS_KB */
    6.44    for (j = 0; j < (int)extra_kb; j += BALLOON_UNITS_KB)
    6.45 @@ -636,8 +648,8 @@ XenPci_InitialBalloonDown()
    6.46      {
    6.47        /* this should actually never happen. If we can't allocate the memory it means windows is using it, and if it was using it we would have crashed already... */
    6.48        KdPrint((__DRIVER_NAME "     Initial Balloon Down failed\n"));
    6.49 +      #pragma warning(suppress:28159)
    6.50        KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, extra_kb, j, 0x00000000);
    6.51 -      break;
    6.52      }
    6.53      else
    6.54      {
    6.55 @@ -680,6 +692,9 @@ XenPci_InitialBalloonDown()
    6.56    return head;
    6.57  }
    6.58  
    6.59 +/* this isn't freed on shutdown... perhaps it should be */
    6.60 +PVOID dump_page;
    6.61 +
    6.62  NTSTATUS
    6.63  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    6.64  {
    6.65 @@ -700,7 +715,6 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    6.66    WDFSTRING wdf_system_start_options;
    6.67    UNICODE_STRING system_start_options;
    6.68  #if (NTDDI_VERSION >= NTDDI_WS03SP1)  
    6.69 -  PVOID dump_page;
    6.70    ULONG dump_header_size;
    6.71  #endif
    6.72    
     7.1 --- a/xenpci/xenpci_dbgprint.c	Sun Apr 15 18:57:34 2012 +1000
     7.2 +++ b/xenpci/xenpci_dbgprint.c	Sun Apr 15 19:47:10 2012 +1000
     7.3 @@ -88,11 +88,16 @@ static void XenDbgPrint(PCHAR string, UL
     7.4        for (j = 1000000000000000000L; j >= 1; j /= 10)
     7.5          if (current_time.QuadPart / j)
     7.6            break;
     7.7 -      for (; j >= 1; j /= 10)
     7.8 +      for (; j >= 1; j /= 10) {
     7.9 +        #pragma warning(suppress:28138)
    7.10          WRITE_PORT_UCHAR(XEN_IOPORT_LOG, '0' + (UCHAR)((current_time.QuadPart / j) % 10));
    7.11 +      }
    7.12 +      #pragma warning(suppress:28138)
    7.13        WRITE_PORT_UCHAR(XEN_IOPORT_LOG, ':');
    7.14 +      #pragma warning(suppress:28138)
    7.15        WRITE_PORT_UCHAR(XEN_IOPORT_LOG, ' ');
    7.16      }
    7.17 +    #pragma warning(suppress:28138)
    7.18      WRITE_PORT_UCHAR(XEN_IOPORT_LOG, string[i]);
    7.19      last_newline = (string[i] == '\n');
    7.20    }
    7.21 @@ -103,6 +108,7 @@ static void XenDbgPrint(PCHAR string, UL
    7.22  static VOID
    7.23  XenPci_DbgWriteChar(CHAR c)
    7.24  {
    7.25 +  #pragma warning(suppress:28138)
    7.26    WRITE_PORT_UCHAR(XEN_IOPORT_LOG, c);
    7.27  }
    7.28  
    7.29 @@ -111,6 +117,7 @@ XenPci_DbgWriteString(PCHAR string)
    7.30  {
    7.31    while (*string)
    7.32    {
    7.33 +    #pragma warning(suppress:28138)
    7.34      WRITE_PORT_UCHAR(XEN_IOPORT_LOG, *string);
    7.35      string++;
    7.36    }
    7.37 @@ -258,7 +265,9 @@ XenPci_HookDbgPrint()
    7.38  {
    7.39    NTSTATUS status = STATUS_SUCCESS;
    7.40  
    7.41 +  #pragma warning(suppress:28138)
    7.42    if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
    7.43 +    #pragma warning(suppress:28138)
    7.44      || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
    7.45    {
    7.46      //#pragma warning(suppress:4055)
    7.47 @@ -299,7 +308,9 @@ XenPci_UnHookDbgPrint()
    7.48  {
    7.49    NTSTATUS status = STATUS_SUCCESS;
    7.50  
    7.51 +  #pragma warning(suppress:28138)
    7.52    if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
    7.53 +    #pragma warning(suppress:28138)
    7.54      || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
    7.55    {
    7.56      //#pragma warning(suppress:4055)
     8.1 --- a/xenpci/xenpci_fdo.c	Sun Apr 15 18:57:34 2012 +1000
     8.2 +++ b/xenpci/xenpci_fdo.c	Sun Apr 15 19:47:10 2012 +1000
     8.3 @@ -189,6 +189,7 @@ XenPci_SysrqHandler(char *path, PVOID co
     8.4    case 0:
     8.5      break;
     8.6    case 'B': /* cause a bug check */
     8.7 +    #pragma warning(suppress:28159)
     8.8      KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000001, 0x00000000, 0x00000000, 0x00000000);
     8.9      break;
    8.10    case 'A': /* cause an assert */
    8.11 @@ -595,7 +596,11 @@ XenPci_SuspendEvtDpc(PVOID context)
    8.12    WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
    8.13    attributes.ParentObject = device;
    8.14    status = WdfWorkItemCreate(&workitem_config, &attributes, &workitem);
    8.15 -  // TODO: check status here
    8.16 +  if (status != STATUS_SUCCESS) {
    8.17 +    /* how should we fail here */
    8.18 +    FUNCTION_MSG("WdfWorkItemCreate failed\n");
    8.19 +    return;
    8.20 +  }
    8.21    WdfWorkItemEnqueue(workitem);
    8.22  }
    8.23  
     9.1 --- a/xenusb/xenusb_devurb.c	Sun Apr 15 18:57:34 2012 +1000
     9.2 +++ b/xenusb/xenusb_devurb.c	Sun Apr 15 19:47:10 2012 +1000
     9.3 @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     9.4  
     9.5  #define EPROTO          71      /* Protocol error */
     9.6  
     9.7 +EVT_WDF_REQUEST_COMPLETION_ROUTINE XenUsb_CompletionBulkInterrupt;
     9.8 +
     9.9  static USBD_STATUS
    9.10  XenUsb_GetUsbdStatusFromPvStatus(ULONG pvstatus) {
    9.11    switch (pvstatus)
    10.1 --- a/xenusb/xenusb_fdo.c	Sun Apr 15 18:57:34 2012 +1000
    10.2 +++ b/xenusb/xenusb_fdo.c	Sun Apr 15 19:47:10 2012 +1000
    10.3 @@ -754,43 +754,39 @@ XenUsb_EvtIoDeviceControl(
    10.4      KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_ROOT_HUB_NAME\n"));
    10.5      KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
    10.6        
    10.7 -    if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME))
    10.8 -    {
    10.9 +    if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME)) {
   10.10        status = STATUS_BUFFER_TOO_SMALL;
   10.11 -    }
   10.12 -    else
   10.13 -    {
   10.14 +    } else {
   10.15        status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uhdn, &length);
   10.16 -      if (NT_SUCCESS(status))
   10.17 -      {
   10.18 +      if (NT_SUCCESS(status)) {
   10.19          WDFSTRING symbolic_link_wdfstring;
   10.20          UNICODE_STRING symbolic_link;
   10.21          
   10.22          uhdn->DriverKeyName[0] = 0;
   10.23          status = WdfStringCreate(NULL, WDF_NO_OBJECT_ATTRIBUTES, &symbolic_link_wdfstring);
   10.24 -        status = WdfDeviceRetrieveDeviceInterfaceString(xudd->root_hub_device, &GUID_DEVINTERFACE_USB_HUB, NULL, symbolic_link_wdfstring);
   10.25 -        if (NT_SUCCESS(status))
   10.26 -        {
   10.27 -          WdfStringGetUnicodeString(symbolic_link_wdfstring, &symbolic_link);
   10.28 -          /* remove leading \??\ from name */
   10.29 -          symbolic_link.Buffer += 4;
   10.30 -          symbolic_link.Length -= 4 * sizeof(WCHAR);
   10.31 -          required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + symbolic_link.Length + sizeof(WCHAR);
   10.32 -          FUNCTION_MSG("output_buffer_length = %d\n", output_buffer_length);
   10.33 -          FUNCTION_MSG("required_length = %d\n", required_length);
   10.34 -          if (output_buffer_length >= required_length)
   10.35 -          {
   10.36 -            uhdn->ActualLength = required_length;
   10.37 -            memcpy(uhdn->DriverKeyName, symbolic_link.Buffer, symbolic_link.Length);
   10.38 -            uhdn->DriverKeyName[symbolic_link.Length / 2] = 0;
   10.39 -            WdfRequestSetInformation(request, required_length);
   10.40 -          }
   10.41 -          else
   10.42 -          {
   10.43 -            uhdn->ActualLength = required_length;
   10.44 -            uhdn->DriverKeyName[0] = 0;
   10.45 -            status = STATUS_SUCCESS;
   10.46 -            WdfRequestSetInformation(request, output_buffer_length);
   10.47 +        if (NT_SUCCESS(status)) {
   10.48 +          status = WdfDeviceRetrieveDeviceInterfaceString(xudd->root_hub_device, &GUID_DEVINTERFACE_USB_HUB, NULL, symbolic_link_wdfstring);
   10.49 +          if (NT_SUCCESS(status)) {
   10.50 +            WdfStringGetUnicodeString(symbolic_link_wdfstring, &symbolic_link);
   10.51 +            /* remove leading \??\ from name */
   10.52 +            symbolic_link.Buffer += 4;
   10.53 +            symbolic_link.Length -= 4 * sizeof(WCHAR);
   10.54 +            required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + symbolic_link.Length + sizeof(WCHAR);
   10.55 +            FUNCTION_MSG("output_buffer_length = %d\n", output_buffer_length);
   10.56 +            FUNCTION_MSG("required_length = %d\n", required_length);
   10.57 +            if (output_buffer_length >= required_length) {
   10.58 +              uhdn->ActualLength = required_length;
   10.59 +              memcpy(uhdn->DriverKeyName, symbolic_link.Buffer, symbolic_link.Length);
   10.60 +              uhdn->DriverKeyName[symbolic_link.Length / 2] = 0;
   10.61 +              WdfRequestSetInformation(request, required_length);
   10.62 +            } else {
   10.63 +              uhdn->ActualLength = required_length;
   10.64 +              uhdn->DriverKeyName[0] = 0;
   10.65 +              status = STATUS_SUCCESS;
   10.66 +              WdfRequestSetInformation(request, output_buffer_length);
   10.67 +            }
   10.68 +          } else {
   10.69 +            KdPrint((__DRIVER_NAME "     WdfStringCreate = %08x\n", status));
   10.70            }
   10.71          }
   10.72          else
   10.73 @@ -813,46 +809,46 @@ XenUsb_EvtIoDeviceControl(
   10.74      PUSB_HCD_DRIVERKEY_NAME uhdn;
   10.75      size_t length;
   10.76      ULONG required_length = sizeof(USB_HCD_DRIVERKEY_NAME);
   10.77 +    ULONG key_length;
   10.78      
   10.79      KdPrint((__DRIVER_NAME "     IOCTL_GET_HCD_DRIVERKEY_NAME\n"));
   10.80      KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
   10.81        
   10.82 -    if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME))
   10.83 +    if (output_buffer_length < sizeof(USB_HCD_DRIVERKEY_NAME)) {
   10.84 +      FUNCTION_MSG("Buffer too small (%d < %d)\n", output_buffer_length, sizeof(USB_HCD_DRIVERKEY_NAME));
   10.85        status = STATUS_BUFFER_TOO_SMALL;
   10.86 +      break;
   10.87 +    }
   10.88 +    status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uhdn, &length);
   10.89 +    if (!NT_SUCCESS(status)) {
   10.90 +      KdPrint((__DRIVER_NAME "     WdfRequestRetrieveOutputBuffer = %08x\n", status));
   10.91 +      break;
   10.92 +    }
   10.93 +    status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 0, NULL, &key_length);
   10.94 +    if (!NT_SUCCESS(status)) {
   10.95 +      KdPrint((__DRIVER_NAME "     WdfDeviceQueryProperty = %08x\n", status));
   10.96 +      break;
   10.97 +    }    
   10.98 +    KdPrint((__DRIVER_NAME "      key_length = %d\n", key_length));
   10.99 +    required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + key_length + 2;
  10.100 +    uhdn->ActualLength = required_length;
  10.101 +    FUNCTION_MSG("output_buffer_length = %d\n", output_buffer_length);
  10.102 +    FUNCTION_MSG("required_length = %d\n", required_length);
  10.103 +    if (output_buffer_length >= required_length)
  10.104 +    {
  10.105 +      status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 
  10.106 +        required_length - FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName), uhdn->DriverKeyName,
  10.107 +        &key_length);
  10.108 +      WdfRequestSetInformation(request, required_length);
  10.109 +    }
  10.110      else
  10.111      {
  10.112 -      status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uhdn, &length);
  10.113 -      if (NT_SUCCESS(status))
  10.114 -      {
  10.115 -        ULONG key_length;
  10.116 -        status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 0, NULL, &key_length);
  10.117 -        KdPrint((__DRIVER_NAME "      key_length = %d\n", key_length));
  10.118 -        status = STATUS_SUCCESS;
  10.119 -        required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + key_length + 2;
  10.120 -        uhdn->ActualLength = required_length;
  10.121 -        FUNCTION_MSG("output_buffer_length = %d\n", output_buffer_length);
  10.122 -        FUNCTION_MSG("required_length = %d\n", required_length);
  10.123 -        if (output_buffer_length >= required_length)
  10.124 -        {
  10.125 -          status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 
  10.126 -            required_length - FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName), uhdn->DriverKeyName,
  10.127 -            &key_length);
  10.128 -          WdfRequestSetInformation(request, required_length);
  10.129 -        }
  10.130 -        else
  10.131 -        {
  10.132 -          uhdn->DriverKeyName[0] = 0;
  10.133 -          status = STATUS_SUCCESS;
  10.134 -          WdfRequestSetInformation(request, output_buffer_length);
  10.135 -        }
  10.136 -        FUNCTION_MSG(" uhdn->ActualLength = %d\n", uhdn->ActualLength);
  10.137 -        FUNCTION_MSG(" uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName);
  10.138 -      }
  10.139 -      else
  10.140 -      {
  10.141 -        KdPrint((__DRIVER_NAME "     WdfRequestRetrieveOutputBuffer = %08x\n", status));
  10.142 -      }
  10.143 +      uhdn->DriverKeyName[0] = 0;
  10.144 +      status = STATUS_SUCCESS;
  10.145 +      WdfRequestSetInformation(request, output_buffer_length);
  10.146      }
  10.147 +    FUNCTION_MSG(" uhdn->ActualLength = %d\n", uhdn->ActualLength);
  10.148 +    FUNCTION_MSG(" uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName);
  10.149      break;
  10.150    }
  10.151  #if 0
  10.152 @@ -971,6 +967,14 @@ XenUsb_EvtIoInternalDeviceControl_PVURB(
  10.153    }
  10.154    KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
  10.155    status = WdfRequestMarkCancelableEx(request, XenUsb_EvtRequestCancelPvUrb);
  10.156 +  if (!NT_SUCCESS(status)) {
  10.157 +    KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);  
  10.158 +    FUNCTION_MSG("WdfRequestMarkCancelableEx returned %08x\n", status);
  10.159 +    WdfRequestComplete(request, STATUS_INSUFFICIENT_RESOURCES);
  10.160 +    FUNCTION_EXIT();
  10.161 +    return;
  10.162 +  }  
  10.163 +  
  10.164    partial_pvurb->req = pvurb->req;
  10.165    partial_pvurb->mdl = pvurb->mdl; /* 1:1 right now, but may need to split up large pvurb into smaller partial_pvurb's */
  10.166    partial_pvurb->pvurb = pvurb;
  10.167 @@ -1203,16 +1207,28 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
  10.168    WdfDeviceSetBusInformationForChildren(device, &pbi);
  10.169  
  10.170    status = WdfDeviceCreateDeviceInterface(device, &GUID_DEVINTERFACE_USB_HOST_CONTROLLER, NULL);
  10.171 -  if (!NT_SUCCESS(status))
  10.172 +  if (!NT_SUCCESS(status)) {
  10.173 +    FUNCTION_MSG("WdfDeviceCreateDeviceInterface returned %08x\n");
  10.174      return status;
  10.175 +  }
  10.176  
  10.177    /* USB likes to have a registry key with the symbolic link name in it */
  10.178    status = WdfStringCreate(NULL, WDF_NO_OBJECT_ATTRIBUTES, &symbolicname_value_wdfstring);
  10.179 +  if (!NT_SUCCESS(status)) {
  10.180 +    FUNCTION_MSG("WdfStringCreate returned %08x\n");
  10.181 +    return status;
  10.182 +  }
  10.183    status = WdfDeviceRetrieveDeviceInterfaceString(device, &GUID_DEVINTERFACE_USB_HOST_CONTROLLER, NULL, symbolicname_value_wdfstring);
  10.184 -  if (!NT_SUCCESS(status))
  10.185 +  if (!NT_SUCCESS(status)) {
  10.186 +    FUNCTION_MSG("WdfDeviceRetrieveDeviceInterfaceString returned %08x\n");
  10.187      return status;
  10.188 +  }
  10.189    WdfStringGetUnicodeString(symbolicname_value_wdfstring, &symbolicname_value);
  10.190    status = WdfDeviceOpenRegistryKey(device, PLUGPLAY_REGKEY_DEVICE, KEY_SET_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &device_key);
  10.191 +  if (!NT_SUCCESS(status)) {
  10.192 +    FUNCTION_MSG("WdfDeviceOpenRegistryKey returned %08x\n");
  10.193 +    return status;
  10.194 +  }
  10.195    WdfRegistryAssignUnicodeString(device_key, &symbolicname_name, &symbolicname_value);
  10.196  
  10.197    FUNCTION_EXIT();
    11.1 --- a/xenusb/xenusb_hub.c	Sun Apr 15 18:57:34 2012 +1000
    11.2 +++ b/xenusb/xenusb_hub.c	Sun Apr 15 19:47:10 2012 +1000
    11.3 @@ -40,7 +40,11 @@ static EVT_WDF_TIMER XenUsbHub_HubInterr
    11.4  static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsbHub_EvtIoInternalDeviceControl;
    11.5  static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XenUsbHub_EvtIoDeviceControl;
    11.6  static EVT_WDF_IO_QUEUE_IO_DEFAULT XenUsbHub_EvtIoDefault;
    11.7 +static EVT_WDFDEVICE_WDM_IRP_PREPROCESS XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE;
    11.8 +
    11.9  static USB_BUSIFFN_CREATE_USB_DEVICE XenUsbHub_UBIH_CreateUsbDevice;
   11.10 +static USB_BUSIFFN_CREATE_USB_DEVICE_EX XenUsbHub_UBIH_CreateUsbDeviceEx;
   11.11 +static USB_BUSIFFN_CREATE_USB_DEVICE_V7 XenUsbHub_UBIH_CreateUsbDeviceV7;
   11.12  static USB_BUSIFFN_INITIALIZE_USB_DEVICE XenUsbHub_UBIH_InitializeUsbDevice;
   11.13  static USB_BUSIFFN_GET_USB_DESCRIPTORS XenUsbHub_UBIH_GetUsbDescriptors;
   11.14  static USB_BUSIFFN_REMOVE_USB_DEVICE XenUsbHub_UBIH_RemoveUsbDevice;
   11.15 @@ -56,6 +60,28 @@ static USB_BUSIFFN_INITIALIZE_20HUB XenU
   11.16  static USB_BUSIFFN_ROOTHUB_INIT_NOTIFY XenUsbHub_UBIH_RootHubInitNotification;
   11.17  static USB_BUSIFFN_FLUSH_TRANSFERS XenUsbHub_UBIH_FlushTransfers;
   11.18  static USB_BUSIFFN_SET_DEVHANDLE_DATA XenUsbHub_UBIH_SetDeviceHandleData;
   11.19 +static USB_BUSIFFN_INITIALIZE_USB_DEVICE_EX XenUsbHub_UBIH_InitializeUsbDeviceEx;
   11.20 +static USB_BUSIFFN_IS_ROOT XenUsbHub_UBIH_HubIsRoot;
   11.21 +static USB_BUSIFFN_TEST_POINT XenUsbHub_UBIH_HubTestPoint;
   11.22 +static USB_BUSIFFN_GET_DEVICE_PERFORMANCE_INFO XenUsbHub_UBIH_GetDevicePerformanceInfo;
   11.23 +static USB_BUSIFFN_WAIT_ASYNC_POWERUP XenUsbHub_UBIH_WaitAsyncPowerUp;
   11.24 +static USB_BUSIFFN_GET_DEVICE_ADDRESS XenUsbHub_UBIH_GetDeviceAddress;
   11.25 +static USB_BUSIFFN_REF_DEVICE_HANDLE XenUsbHub_UBIH_RefDeviceHandle;
   11.26 +static USB_BUSIFFN_DEREF_DEVICE_HANDLE XenUsbHub_UBIH_DerefDeviceHandle;
   11.27 +static USB_BUSIFFN_SET_DEVICE_HANDLE_IDLE_READY_STATE XenUsbHub_UBIH_SetDeviceHandleIdleReadyState;
   11.28 +static USB_BUSIFFN_GET_CONTAINER_ID_FOR_PORT XenUsbHub_UBIH_GetContainerIdForPort;
   11.29 +static USB_BUSIFFN_SET_CONTAINER_ID_FOR_PORT XenUsbHub_UBIH_SetContainerIdForPort;
   11.30 +static USB_BUSIFFN_ABORT_ALL_DEVICE_PIPES XenUsbHub_UBIH_AbortAllDevicePipes;
   11.31 +static USB_BUSIFFN_SET_DEVICE_ERRATA_FLAG XenUsbHub_UBIH_SetDeviceErrataFlag;
   11.32 +static USB_BUSIFFN_ACQUIRE_SEMAPHORE XenUsbHub_UBIH_AcquireBusSemaphore;
   11.33 +static USB_BUSIFFN_RELEASE_SEMAPHORE XenUsbHub_UBIH_ReleaseBusSemaphore;
   11.34 +static USB_BUSIFFN_CALC_PIPE_BANDWIDTH XenUsbHub_UBIH_CaculatePipeBandwidth;
   11.35 +static USB_BUSIFFN_SET_BUS_WAKE_MODE XenUsbHub_UBIH_SetBusSystemWakeMode;
   11.36 +static USB_BUSIFFN_SET_DEVICE_FLAG XenUsbHub_UBIH_SetDeviceFlag;
   11.37 +
   11.38 +
   11.39 +
   11.40 +
   11.41  
   11.42  static VOID
   11.43  XenUsbHub_EvtIoDefault(
   11.44 @@ -401,15 +427,28 @@ XenUsbHub_EvtDeviceD0Entry(WDFDEVICE dev
   11.45  
   11.46    /* USB likes to have a registry key with the symbolic link name in it. Have to wait until D0Entry as this is the PDO */
   11.47    status = WdfStringCreate(NULL, WDF_NO_OBJECT_ATTRIBUTES, &symbolicname_value_wdfstring);
   11.48 +  if (!NT_SUCCESS(status)) {
   11.49 +    FUNCTION_MSG("WdfStringCreate = %08x\n", status);
   11.50 +    return status;
   11.51 +  }
   11.52    status = WdfDeviceRetrieveDeviceInterfaceString(device, &GUID_DEVINTERFACE_USB_HUB, NULL, symbolicname_value_wdfstring);
   11.53 -  FUNCTION_MSG("WdfDeviceREtrieveDeviceInterfaceString = %08x\n", status);
   11.54 -  if (!NT_SUCCESS(status))
   11.55 +  if (!NT_SUCCESS(status)) {
   11.56 +    FUNCTION_MSG("WdfDeviceREtrieveDeviceInterfaceString = %08x\n", status);
   11.57      return status;
   11.58 +  }
   11.59    WdfStringGetUnicodeString(symbolicname_value_wdfstring, &symbolicname_value);
   11.60    FUNCTION_MSG("ROOT_HUB SymbolicName = %S\n", symbolicname_value.Buffer);
   11.61    status = WdfDeviceOpenRegistryKey(device, PLUGPLAY_REGKEY_DEVICE, KEY_SET_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &device_key);
   11.62 -  WdfRegistryAssignUnicodeString(device_key, &symbolicname_name, &symbolicname_value);
   11.63 -
   11.64 +  if (!NT_SUCCESS(status)) {
   11.65 +    FUNCTION_MSG("WdfDeviceOpenRegistryKey = %08x\n", status);
   11.66 +    return status;
   11.67 +  }
   11.68 +  status = WdfRegistryAssignUnicodeString(device_key, &symbolicname_name, &symbolicname_value);
   11.69 +  if (!NT_SUCCESS(status)) {
   11.70 +    FUNCTION_MSG("WdfDeviceOpenRegistryKey = %08x\n", status);
   11.71 +    return status;
   11.72 +  }
   11.73 +  WdfRegistryClose(device_key);
   11.74    FUNCTION_EXIT();
   11.75    
   11.76    return status;
   11.77 @@ -538,7 +577,7 @@ static NTSTATUS
   11.78  XenUsbHub_UBIH_CreateUsbDevice(
   11.79    PVOID BusContext,
   11.80    PUSB_DEVICE_HANDLE *DeviceHandle,
   11.81 -  PUSB_DEVICE_HANDLE *HubDeviceHandle,
   11.82 +  PUSB_DEVICE_HANDLE HubDeviceHandle,
   11.83    USHORT PortStatus,
   11.84    USHORT PortNumber)
   11.85  {
   11.86 @@ -551,14 +590,17 @@ XenUsbHub_UBIH_CreateUsbDevice(
   11.87    
   11.88    FUNCTION_ENTER();
   11.89  
   11.90 -  KdPrint((__DRIVER_NAME "     BusContext = %p\n", BusContext));
   11.91 -  KdPrint((__DRIVER_NAME "     DeviceHandle = %p\n", DeviceHandle));
   11.92 -  KdPrint((__DRIVER_NAME "     *DeviceHandle = %p\n", *DeviceHandle));
   11.93 -  KdPrint((__DRIVER_NAME "     HubDeviceHandle = %p\n", HubDeviceHandle));
   11.94 -  KdPrint((__DRIVER_NAME "     *HubDeviceHandle = %p\n", *HubDeviceHandle));
   11.95 -  KdPrint((__DRIVER_NAME "     PortStatus = %04X\n", PortStatus));
   11.96 -  KdPrint((__DRIVER_NAME "     PortNumber = %d\n", PortNumber));
   11.97 +  FUNCTION_MSG("BusContext = %p\n", BusContext);
   11.98 +  FUNCTION_MSG("DeviceHandle = %p\n", DeviceHandle);
   11.99 +  FUNCTION_MSG("*DeviceHandle = %p\n", *DeviceHandle);
  11.100 +  FUNCTION_MSG("HubDeviceHandle = %p\n", HubDeviceHandle);
  11.101 +  FUNCTION_MSG("PortStatus = %04X\n", PortStatus);
  11.102 +  FUNCTION_MSG("PortNumber = %d\n", PortNumber);
  11.103    usb_device = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_device_t), XENUSB_POOL_TAG);
  11.104 +  if (!usb_device) {
  11.105 +    FUNCTION_EXIT();
  11.106 +    return STATUS_INSUFFICIENT_RESOURCES;
  11.107 +  }
  11.108    usb_device->port_number = PortNumber;
  11.109    *DeviceHandle = usb_device;  
  11.110  
  11.111 @@ -603,7 +645,15 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.112    xupdd->usb_device->device_type = Usb20Device;
  11.113  
  11.114    buf = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
  11.115 +  if (!buf) {
  11.116 +    FUNCTION_MSG("ExAllocatePoolWithTag(buf) failed\n");
  11.117 +    return STATUS_INSUFFICIENT_RESOURCES;
  11.118 +  }
  11.119    mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
  11.120 +  if (!mdl) {
  11.121 +    FUNCTION_MSG("IoAllocateMdl(buf) failed\n", status);
  11.122 +    return STATUS_INSUFFICIENT_RESOURCES;
  11.123 +  }
  11.124    MmBuildMdlForNonPagedPool(mdl);
  11.125  
  11.126    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, &pvurb, sizeof(pvurb));
  11.127 @@ -624,6 +674,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.128    setup_packet->wLength = pvurb.req.buffer_length;
  11.129    pvurb.mdl = NULL;
  11.130    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
  11.131 +  if (!NT_SUCCESS(status)) {
  11.132 +    FUNCTION_MSG("WdfIoTargetSendInternalIoctlOthersSynchronously(USB_REQUEST_SET_ADDRESS) = %08x\n", status);
  11.133 +    return status;
  11.134 +  }
  11.135    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
  11.136    FUNCTION_MSG("rsp start_frame = %d\n", pvurb.rsp.start_frame);
  11.137    FUNCTION_MSG("rsp status = %d\n", pvurb.rsp.status);
  11.138 @@ -645,7 +699,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.139    setup_packet->wLength = pvurb.req.buffer_length;
  11.140    pvurb.mdl = mdl;
  11.141    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
  11.142 -  FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
  11.143 +  if (!NT_SUCCESS(status)) {
  11.144 +    FUNCTION_MSG("WdfIoTargetSendInternalIoctlOthersSynchronously(USB_REQUEST_GET_DESCRIPTOR, USB_DEVICE_DESCRIPTOR_TYPE) = %08x\n", status);
  11.145 +    return status;
  11.146 +  }
  11.147    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
  11.148    KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
  11.149    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
  11.150 @@ -656,6 +713,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.151    KdPrint((__DRIVER_NAME "     bNumConfigurations = %d\n", device_descriptor->bNumConfigurations));
  11.152    memcpy(&usb_device->device_descriptor, device_descriptor, device_descriptor->bLength);
  11.153    usb_device->configs = ExAllocatePoolWithTag(NonPagedPool, sizeof(PVOID) * device_descriptor->bNumConfigurations, XENUSB_POOL_TAG);
  11.154 +  if (!usb_device->configs) {
  11.155 +    FUNCTION_MSG("ExAllocatePoolWithTag(usb_device->configs) failed\n");
  11.156 +    return STATUS_INSUFFICIENT_RESOURCES;
  11.157 +  }
  11.158    KdPrint((__DRIVER_NAME "     bLength = %d\n", device_descriptor->bLength));
  11.159    KdPrint((__DRIVER_NAME "     bDescriptorType = %d\n", device_descriptor->bDescriptorType));
  11.160    KdPrint((__DRIVER_NAME "     bcdUSB = %04x\n", device_descriptor->bcdUSB));
  11.161 @@ -684,6 +745,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.162      setup_packet->wLength = pvurb.req.buffer_length;
  11.163      pvurb.mdl = mdl;
  11.164      status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
  11.165 +    if (!NT_SUCCESS(status)) {
  11.166 +      FUNCTION_MSG("WdfIoTargetSendInternalIoctlOthersSynchronously(USB_REQUEST_GET_DESCRIPTOR, USB_CONFIGURATION_DESCRIPTOR_TYPE) = %08x\n", status);
  11.167 +      return status;
  11.168 +    }
  11.169      KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
  11.170      KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
  11.171      KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
  11.172 @@ -700,6 +765,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
  11.173      KdPrint((__DRIVER_NAME "      bmAttributes = %02x\n", config_descriptor->bmAttributes));
  11.174      KdPrint((__DRIVER_NAME "      MaxPower = %d\n", config_descriptor->MaxPower));
  11.175      usb_device->configs[i] = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_config_t) + sizeof(PVOID) * config_descriptor->bNumInterfaces, XENUSB_POOL_TAG);
  11.176 +    if (!usb_device->configs) {
  11.177 +      FUNCTION_MSG("ExAllocatePoolWithTag(usb_device->configs[i]) failed\n");
  11.178 +      return STATUS_INSUFFICIENT_RESOURCES;
  11.179 +    }
  11.180      usb_device->configs[i]->device = usb_device;
  11.181      memcpy(&usb_device->configs[i]->config_descriptor, config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
  11.182      usb_device->configs[i]->config_descriptor_all = ExAllocatePoolWithTag(NonPagedPool, config_descriptor->wTotalLength, XENUSB_POOL_TAG);
  11.183 @@ -1171,7 +1240,7 @@ static NTSTATUS
  11.184  XenUsbHub_UBIH_CreateUsbDeviceEx(
  11.185    PVOID BusContext,
  11.186    PUSB_DEVICE_HANDLE *DeviceHandle,
  11.187 -  PUSB_DEVICE_HANDLE *HubDeviceHandle,
  11.188 +  PUSB_DEVICE_HANDLE HubDeviceHandle,
  11.189    USHORT PortStatus,
  11.190    USHORT PortNumber,
  11.191    PUSB_CD_ERROR_INFORMATION CdErrorInfo,
  11.192 @@ -1399,7 +1468,7 @@ XenUsbHub_UBIH_RefDeviceHandle(
  11.193    return STATUS_SUCCESS;
  11.194  }
  11.195  
  11.196 -static NTSTATUS
  11.197 +static VOID
  11.198  XenUsbHub_UBIH_DerefDeviceHandle(
  11.199    PVOID BusContext,
  11.200    PUSB_DEVICE_HANDLE DeviceHandle,
  11.201 @@ -1413,7 +1482,6 @@ XenUsbHub_UBIH_DerefDeviceHandle(
  11.202    FUNCTION_ENTER();
  11.203    FUNCTION_MSG("This should do something\n");
  11.204    FUNCTION_EXIT();
  11.205 -  return STATUS_SUCCESS;
  11.206  }
  11.207  
  11.208  static ULONG
  11.209 @@ -1444,7 +1512,7 @@ XenUsbHub_UBIH_GetContainerIdForPort(
  11.210    return STATUS_UNSUCCESSFUL;
  11.211  }
  11.212  
  11.213 -static NTSTATUS
  11.214 +static VOID
  11.215  XenUsbHub_UBIH_SetContainerIdForPort(
  11.216    PVOID BusContext,
  11.217    USHORT PortNumber,
  11.218 @@ -1455,7 +1523,6 @@ XenUsbHub_UBIH_SetContainerIdForPort(
  11.219    UNREFERENCED_PARAMETER(ContainerId);
  11.220    FUNCTION_ENTER();
  11.221    FUNCTION_EXIT();
  11.222 -  return STATUS_UNSUCCESSFUL;
  11.223  }
  11.224  
  11.225  static NTSTATUS
    12.1 --- a/xenvbd/xenvbd_scsiport.c	Sun Apr 15 18:57:34 2012 +1000
    12.2 +++ b/xenvbd/xenvbd_scsiport.c	Sun Apr 15 19:47:10 2012 +1000
    12.3 @@ -480,7 +480,7 @@ XenVbd_PutQueuedSrbsOnRing(PXENVBD_DEVIC
    12.4      {
    12.5        PHYSICAL_ADDRESS physical_address = MmGetPhysicalAddress(ptr);
    12.6        
    12.7 -      gref = xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context, 0,
    12.8 +      gref = xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context,
    12.9                 (ULONG)(physical_address.QuadPart >> PAGE_SHIFT), FALSE, INVALID_GRANT_REF, (ULONG)'SCSI');
   12.10        if (gref == INVALID_GRANT_REF)
   12.11        {
   12.12 @@ -1603,8 +1603,10 @@ XenVbd_HwScsiAdapterControl(PVOID Device
   12.13      KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   12.14      if (!xvdd->inactive)
   12.15      {
   12.16 -      if (XenVbd_InitFromConfig(xvdd) != SP_RETURN_FOUND)
   12.17 +      if (XenVbd_InitFromConfig(xvdd) != SP_RETURN_FOUND) {
   12.18 +        #pragma warning(suppress:28159)
   12.19          KeBugCheckEx(DATA_COHERENCY_EXCEPTION, 0, (ULONG_PTR) xvdd, 0, 0);
   12.20 +      }
   12.21        xvdd->ring_detect_state = RING_DETECT_STATE_NOT_STARTED;
   12.22      }
   12.23      break;
    13.1 --- a/xenvbd/xenvbd_storport.c	Sun Apr 15 18:57:34 2012 +1000
    13.2 +++ b/xenvbd/xenvbd_storport.c	Sun Apr 15 19:47:10 2012 +1000
    13.3 @@ -1949,8 +1949,10 @@ XenVbd_HwStorAdapterControl(PVOID Device
    13.4      }
    13.5      /* increase the tag every time we stop/start to track where the gref's came from */
    13.6      xvdd->grant_tag++;
    13.7 -    if (XenVbd_InitFromConfig(xvdd) != SP_RETURN_FOUND)
    13.8 +    if (XenVbd_InitFromConfig(xvdd) != SP_RETURN_FOUND) {
    13.9 +      #pragma warning(suppress:28159)
   13.10        KeBugCheckEx(DATA_COHERENCY_EXCEPTION, 0, (ULONG_PTR)xvdd, 0, 0);
   13.11 +    }
   13.12      xvdd->ring_detect_state = RING_DETECT_STATE_NOT_STARTED;
   13.13      
   13.14      //XenVbd_StartRingDetection(xvdd);