From 80cc22cbdea1de8d21eb406bf351a916ca2c4b43 Mon Sep 17 00:00:00 2001 From: Wei Mao Date: Wed, 15 Mar 2017 12:58:20 -0700 Subject: [PATCH] [usb] Fix Code Analysis Warnings --- usb/usbsamp/exe/testapp.c | 116 ++++---- usb/usbsamp/sys/device.c | 219 +++++++------- usb/usbsamp/sys/queue.c | 30 +- usb/usbsamp/sys/stream.c | 3 +- usb/usbview/debug.c | 3 +- usb/usbview/display.c | 352 +++++++++++------------ usb/usbview/uvcview.c | 62 ++-- usb/usbview/xmlhelper.cpp | 147 +++++----- usb/wdf_osrfx2_lab/kmdf/exe/testapp.c | 14 +- usb/wdf_osrfx2_lab/umdf/exe/testapp.c | 23 +- usb/wdf_osrfx2_lab/umdf/step1/dllsup.cpp | 50 ++-- usb/wdf_osrfx2_lab/umdf/step2/dllsup.cpp | 50 ++-- usb/wdf_osrfx2_lab/umdf/step3/dllsup.cpp | 50 ++-- usb/wdf_osrfx2_lab/umdf/step4/dllsup.cpp | 50 ++-- 14 files changed, 612 insertions(+), 557 deletions(-) diff --git a/usb/usbsamp/exe/testapp.c b/usb/usbsamp/exe/testapp.c index e4429726..41467bc7 100644 --- a/usb/usbsamp/exe/testapp.c +++ b/usb/usbsamp/exe/testapp.c @@ -21,10 +21,10 @@ Environment: --*/ - + #include -_Analysis_mode_(_Analysis_code_type_user_code_) - +_Analysis_mode_(_Analysis_code_type_user_code_) + #include #include @@ -37,7 +37,7 @@ _Analysis_mode_(_Analysis_code_type_user_code_) #include "public.h" #include "strsafe.h" -#pragma warning(disable:4200) // +#pragma warning(disable:4200) // #pragma warning(disable:4201) // nameless struct/union #pragma warning(disable:4214) // bit field types other than int @@ -48,7 +48,7 @@ _Analysis_mode_(_Analysis_code_type_user_code_) #pragma warning(default:4200) #pragma warning(default:4201) #pragma warning(default:4214) - + #define NOISY(_x_) printf _x_ ; #define MAX_LENGTH 256 @@ -160,8 +160,8 @@ Return Value: HANDLE -OpenUsbDevice( - _In_ LPGUID pGuid, +OpenUsbDevice( + _In_ LPGUID pGuid, _In_ PSTR outNameBuf ) /*++ @@ -197,10 +197,10 @@ Return Value: // // Open a handle to the plug and play dev node. - // SetupDiGetClassDevs() returns a device information set that contains + // SetupDiGetClassDevs() returns a device information set that contains // info on all installed devices of a specified class. // - hardwareDeviceInfo = + hardwareDeviceInfo = SetupDiGetClassDevs ( pGuid, NULL, // Define no enumerator (global) NULL, // Define no @@ -247,10 +247,10 @@ Return Value: } for (; i < NumberDevices; i++) { - // SetupDiEnumDeviceInterfaces() returns information about device - // interfaces exposed by one or more devices. Each call returns - // information about one interface; the routine can be called - // repeatedly to get information about several interfaces exposed + // SetupDiEnumDeviceInterfaces() returns information about device + // interfaces exposed by one or more devices. Each call returns + // information about one interface; the routine can be called + // repeatedly to get information about several interfaces exposed // by one or more devices. if (SetupDiEnumDeviceInterfaces (hardwareDeviceInfo, @@ -285,8 +285,8 @@ Return Value: BOOL -GetUsbDeviceFileName( - _In_ LPGUID pGuid, +GetUsbDeviceFileName( + _In_ LPGUID pGuid, _In_ PSTR outNameBuf ) /*++ @@ -334,14 +334,14 @@ Return Value: --*/ { - HANDLE hDEV = OpenUsbDevice( (LPGUID)&GUID_CLASS_USBSAMP_USB, + HANDLE hDEV = OpenUsbDevice( (LPGUID)&GUID_CLASS_USBSAMP_USB, completeDeviceName); if (hDEV == INVALID_HANDLE_VALUE) { printf("Failed to open (%s) = %u", completeDeviceName, GetLastError()); } else { printf("DeviceName = (%s)\n", completeDeviceName); - } + } return hDEV; @@ -349,7 +349,7 @@ Return Value: HANDLE -open_file( +open_file( _In_ PSTR filename ) /*++ @@ -378,7 +378,7 @@ Return Value: return INVALID_HANDLE_VALUE; } - (void) StringCchCat (completeDeviceName, MAX_LENGTH, "\\" ); + (void) StringCchCat (completeDeviceName, MAX_LENGTH, "\\" ); if(FAILED(StringCchCat (completeDeviceName, MAX_LENGTH, filename))) { NOISY(("Failed to open handle - possibly long filename\n")); @@ -400,7 +400,7 @@ Return Value: success = 0; } else { NOISY(("Opened successfully.\n")); - } + } return h; } @@ -445,7 +445,7 @@ Return Value: void parse( _In_ int argc, - _In_reads_(argc) char *argv[] + _In_reads_(argc) char *argv[] ) /*++ Routine Description: @@ -565,8 +565,8 @@ Return Value: BOOL compare_buffs( - _In_reads_bytes_(length) char *buff1, - _In_reads_bytes_(length) char *buff2, + _In_reads_bytes_(length) char *buff1, + _In_reads_bytes_(length) char *buff2, _In_ int length ) /*++ @@ -668,29 +668,29 @@ Return Value: case USB_CONFIGURATION_DESCRIPTOR_TYPE: return "USB_CONFIGURATION_DESCRIPTOR_TYPE"; - + case USB_STRING_DESCRIPTOR_TYPE: return "USB_STRING_DESCRIPTOR_TYPE"; - + case USB_INTERFACE_DESCRIPTOR_TYPE: return "USB_INTERFACE_DESCRIPTOR_TYPE"; - + case USB_ENDPOINT_DESCRIPTOR_TYPE: return "USB_ENDPOINT_DESCRIPTOR_TYPE"; case USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR_TYPE: return "USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR_TYPE"; - + #ifdef USB_POWER_DESCRIPTOR_TYPE // this is the older definintion which is actually obsolete // workaround for temporary bug in 98ddk, older USB100.h file case USB_POWER_DESCRIPTOR_TYPE: return "USB_POWER_DESCRIPTOR_TYPE"; #endif - + #ifdef USB_RESERVED_DESCRIPTOR_TYPE // this is the current version of USB100.h as in NT5DDK case USB_RESERVED_DESCRIPTOR_TYPE: @@ -704,7 +704,7 @@ Return Value: #endif // for current nt5ddk version of USB100.h default: - return "??? UNKNOWN!!"; + return "??? UNKNOWN!!"; } } @@ -734,16 +734,16 @@ Return Value: return "USB_ENDPOINT_TYPE_INTERRUPT"; case USB_ENDPOINT_TYPE_BULK: - return "USB_ENDPOINT_TYPE_BULK"; + return "USB_ENDPOINT_TYPE_BULK"; case USB_ENDPOINT_TYPE_ISOCHRONOUS: - return "USB_ENDPOINT_TYPE_ISOCHRONOUS"; + return "USB_ENDPOINT_TYPE_ISOCHRONOUS"; case USB_ENDPOINT_TYPE_CONTROL: - return "USB_ENDPOINT_TYPE_CONTROL"; + return "USB_ENDPOINT_TYPE_CONTROL"; default: - return "??? UNKNOWN!!"; + return "??? UNKNOWN!!"; } } @@ -775,13 +775,13 @@ Return Value: case USB_CONFIG_SELF_POWERED: return "USB_CONFIG_SELF_POWERED"; - + case USB_CONFIG_REMOTE_WAKEUP: return "USB_CONFIG_REMOTE_WAKEUP"; - + default: - return "??? UNKNOWN!!"; + return "??? UNKNOWN!!"; } } @@ -933,7 +933,7 @@ Return Value: ); } - printf( + printf( "bmAttributes= 0x%x ( %s )\n", ed->bmAttributes, usbEndPointTypeString ( ed->bmAttributes ) ); @@ -1024,7 +1024,7 @@ Return Value: NOISY(("DEV not open")); return; } - + success = DeviceIoControl(hDEV, IOCTL_USBSAMP_GET_CONFIG_DESCRIPTOR, buf, @@ -1035,7 +1035,7 @@ Return Value: NULL); NOISY(("request complete, success = %u nBytes = %d\n", success, nBytes)); - + if (success) { UINT j = 0, k = 0, n; @@ -1078,7 +1078,7 @@ Return Value: } j = 0; k = 0; - print_USB_INTERFACE_DESCRIPTOR((PUSB_INTERFACE_DESCRIPTOR)commonDesc, n++); + print_USB_INTERFACE_DESCRIPTOR((PUSB_INTERFACE_DESCRIPTOR)commonDesc, n++); break; case USB_ENDPOINT_DESCRIPTOR_TYPE: @@ -1104,7 +1104,7 @@ Return Value: default: displayUnknown = TRUE; break; - } + } if (displayUnknown) { @@ -1113,10 +1113,10 @@ Return Value: commonDesc = (PUSB_COMMON_DESCRIPTOR)((PUCHAR)commonDesc + commonDesc->bLength); - } + } + + } - } - return; } @@ -1154,8 +1154,8 @@ Return Value: -int -_cdecl +int +_cdecl main( _In_ int argc, _In_reads_(argc) char *argv[] @@ -1212,6 +1212,9 @@ Return Value: hRead = open_file( inPipe); pinBuf = (char*) malloc(ReadLen); + if (pinBuf == NULL) { + return 0; + } } @@ -1224,6 +1227,9 @@ Return Value: hWrite = open_file( outPipe); poutBuf = (char*)malloc(WriteLen); + if (poutBuf == NULL) { + return 0; + } } for (i=0; i R (%04.4u) : request %06.6d bytes -- %06.6d bytes read\n", inPipe, i, ReadLen, nBytesRead); - + if (fWrite && fCompareData) { - + // // validate the input buffer against what // we sent to the device (loopback test) // #pragma warning(suppress: 26053) ok = compare_buffs(pinBuf, poutBuf, nBytesRead); - + if( fDumpReadData ) { printf("Dumping read buffer\n"); - dump( (PUCHAR) pinBuf, nBytesRead ); + dump( (PUCHAR) pinBuf, nBytesRead ); printf("Dumping write buffer\n"); dump( (PUCHAR) poutBuf, nBytesRead ); } assert(ok); - + if(ok != 1) { fail++; } - + assert(ReadLen == WriteLen); assert(nBytesRead == ReadLen); } @@ -1301,7 +1307,7 @@ Return Value: if(hWrite != INVALID_HANDLE_VALUE) CloseHandle(hWrite); - } + } return 0; } diff --git a/usb/usbsamp/sys/device.c b/usb/usbsamp/sys/device.c index 85e825e9..f6009ec3 100644 --- a/usb/usbsamp/sys/device.c +++ b/usb/usbsamp/sys/device.c @@ -36,7 +36,6 @@ Environment: #pragma alloc_text(PAGE, RetrieveDeviceInformation) #pragma alloc_text(PAGE, UsbSamp_ValidateConfigurationDescriptor) #if (NTDDI_VERSION >= NTDDI_WIN8) -#pragma alloc_text(PAGE, UsbSamp_EvtPipeContextCleanup) #pragma alloc_text(PAGE, InitializePipeContextForSuperSpeedDevice) #pragma alloc_text(PAGE, GetEndpointDescriptorForEndpointAddress) #pragma alloc_text(PAGE, InitializePipeContextForSuperSpeedIsochPipe) @@ -199,7 +198,7 @@ Return Value: // // Register I/O callbacks to tell the framework that you are interested - // in handling WdfRequestTypeRead, WdfRequestTypeWrite, and + // in handling WdfRequestTypeRead, WdfRequestTypeWrite, and // IRP_MJ_DEVICE_CONTROL requests. // WdfIoQueueDispatchParallel means that we are capable of handling // all the I/O request simultaneously and we are responsible for protecting @@ -233,12 +232,12 @@ Return Value: // WDF_IO_QUEUE_CONFIG_INIT(&ioQueueConfig, WdfIoQueueDispatchManual); - + WDF_OBJECT_ATTRIBUTES_INIT(&attributes); attributes.SynchronizationScope=WdfSynchronizationScopeQueue; - + ioQueueConfig.EvtIoStop = UsbSamp_EvtIoStop; - + status = WdfIoQueueCreate(device, &ioQueueConfig, &attributes, @@ -255,7 +254,7 @@ Return Value: status = WdfIoQueueReadyNotify(pDevContext->IsochReadQueue, UsbSamp_EvtIoQueueReadyNotification, (WDFCONTEXT)pDevContext); - + if (!NT_SUCCESS(status)) { UsbSamp_DbgPrint(1, ("WdfIoQueueReadyNotify failed for isoch 0x%x\n", status)); return status; @@ -267,12 +266,12 @@ Return Value: // WDF_IO_QUEUE_CONFIG_INIT(&ioQueueConfig, WdfIoQueueDispatchManual); - + WDF_OBJECT_ATTRIBUTES_INIT(&attributes); attributes.SynchronizationScope=WdfSynchronizationScopeQueue; - + ioQueueConfig.EvtIoStop = UsbSamp_EvtIoStop; - + status = WdfIoQueueCreate(device, &ioQueueConfig, &attributes, @@ -289,12 +288,12 @@ Return Value: status = WdfIoQueueReadyNotify(pDevContext->IsochWriteQueue, UsbSamp_EvtIoQueueReadyNotification, (WDFCONTEXT)pDevContext); - + if (!NT_SUCCESS(status)) { UsbSamp_DbgPrint(1, ("WdfIoQueueReadyNotify failed for isoch 0x%x\n", status)); return status; - } - + } + // // Register a device interface so that app can find our device and talk to it. // @@ -306,11 +305,11 @@ Return Value: return status; } - status = USBD_CreateHandle(WdfDeviceWdmGetDeviceObject(device), - WdfDeviceWdmGetAttachedDevice(device), - USBD_CLIENT_CONTRACT_VERSION_602, - POOL_TAG, - &pDevContext->UsbdHandle); + status = USBD_CreateHandle(WdfDeviceWdmGetDeviceObject(device), + WdfDeviceWdmGetAttachedDevice(device), + USBD_CLIENT_CONTRACT_VERSION_602, + POOL_TAG, + &pDevContext->UsbdHandle); if(!NT_SUCCESS(status)){ UsbSamp_DbgPrint(1, ("USBD_CreateHandle failed 0x%x", status)); return status; @@ -470,10 +469,10 @@ Return Value: // if (pDeviceContext->WdfUsbTargetDevice == NULL) { WDF_USB_DEVICE_CREATE_CONFIG config; - + WDF_USB_DEVICE_CREATE_CONFIG_INIT(&config, USBD_CLIENT_CONTRACT_VERSION_602); - + status = WdfUsbTargetDeviceCreateWithParameters(Device, &config, WDF_NO_OBJECT_ATTRIBUTES, @@ -483,14 +482,14 @@ Return Value: return status; } } - + WdfUsbTargetDeviceGetDeviceDescriptor(pDeviceContext->WdfUsbTargetDevice, &pDeviceContext->UsbDeviceDescriptor); NT_ASSERT(pDeviceContext->UsbDeviceDescriptor.bNumConfigurations); status = ConfigureDevice(Device); - + return status; } @@ -572,9 +571,9 @@ Return Value: // // Check if the descriptors are valid - // + // status = UsbSamp_ValidateConfigurationDescriptor(configurationDescriptor, size , &Offset); - + if (!NT_SUCCESS(status)) { UsbSamp_DbgPrint(1, ("Descriptor validation failed with Status code %x and at the offset %p\n", status , Offset )); return status; @@ -624,9 +623,9 @@ Return Value: // // The device has only one interface and the interface may have multiple // alternate settings. It will try to use alternate setting zero if it has - // non-zero endpoints, otherwise it will try to search an alternate + // non-zero endpoints, otherwise it will try to search an alternate // setting with non-zero endpoints. - // + // WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE( &configParams); @@ -667,7 +666,7 @@ Return Value: numberConfiguredPipes = 0; for (i = 0; i < numberAlternateSettings && numberConfiguredPipes == 0; i++) { - + WDF_USB_INTERFACE_SELECT_SETTING_PARAMS_INIT_SETTING(&selectSettingParams, i); WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&pipeAttributes, PIPE_CONTEXT); @@ -680,19 +679,19 @@ Return Value: &pipeAttributes, &selectSettingParams ); - + if (NT_SUCCESS(status)) { - + numberConfiguredPipes = WdfUsbInterfaceGetNumConfiguredPipes(pDeviceContext->UsbInterface); if (numberConfiguredPipes > 0){ - + pDeviceContext->SelectedAlternateSetting = i; - + } - + } - + } pDeviceContext->NumberConfiguredPipes = numberConfiguredPipes; @@ -711,21 +710,21 @@ Return Value: } else if (pDeviceContext->IsDeviceHighSpeed) { status = InitializePipeContextForHighSpeedDevice(pipe); - } + } else { status = InitializePipeContextForFullSpeedDevice(pipe); } #else if (pDeviceContext->IsDeviceHighSpeed) { status = InitializePipeContextForHighSpeedDevice(pipe); - } + } else { status = InitializePipeContextForFullSpeedDevice(pipe); } #endif if (!NT_SUCCESS(status)) { UsbSamp_DbgPrint(1, ("InitializePipeContext failed %x\n", status)); - break; + break; } } @@ -822,7 +821,7 @@ Return Value: WDF_USB_PIPE_INFORMATION_INIT(&pipeInfo); WdfUsbTargetPipeGetInformation(Pipe, &pipeInfo); - + // // We only use pipe context for super speed isoch and bulk speed bulk endpoints. // @@ -839,9 +838,9 @@ Return Value: Pipe); } - + return status; - + } @@ -893,11 +892,11 @@ Return Value: *ppEndpointCompanionDescriptor = NULL; - // + // // Parse the ConfigurationDescriptor (including all Interface and // Endpoint Descriptors) and locate a Interface Descriptor which // matches the InterfaceNumber, AlternateSetting, InterfaceClass, - // InterfaceSubClass, and InterfaceProtocol parameters. + // InterfaceSubClass, and InterfaceProtocol parameters. // pInterfaceDescriptor = USBD_ParseConfigurationDescriptorEx( pConfigurationDescriptor, @@ -919,7 +918,7 @@ Return Value: startingPosition = (PUCHAR) pInterfaceDescriptor; for(index = 0; index < pInterfaceDescriptor->bNumEndpoints; index++) { - + pCommonDescriptorHeader = USBD_ParseDescriptors(pConfigurationDescriptor, pConfigurationDescriptor->wTotalLength, startingPosition, @@ -929,12 +928,12 @@ Return Value: UsbSamp_DbgPrint(1, ("USBD_ParseDescriptors failed to retrieve SuperSpeed Endpoint Descriptor unexpectedly\n")); goto End; - + } // // UsbSamp_ValidateConfigurationDescriptor validates all descriptors. - // This means that the descriptor pointed to by pCommonDescriptorHeader( received above ) is completely + // This means that the descriptor pointed to by pCommonDescriptorHeader( received above ) is completely // contained within the buffer representing ConfigurationDescriptor and // it also verifies that pCommonDescriptorHeader->bLength is equal to sizeof(USB_ENDPOINT_DESCRIPTOR). // @@ -945,18 +944,18 @@ Return Value: // Search an Endpoint Descriptor that matches the EndpointAddress // if (pEndpointDescriptor->bEndpointAddress == EndpointAddress){ - + found = TRUE; break; - + } // // Skip the current Endpoint Descriptor and search for the next. // startingPosition = (PUCHAR)pCommonDescriptorHeader + pCommonDescriptorHeader->bLength; - + } if (found) { @@ -969,26 +968,26 @@ Return Value: USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR_TYPE); if (pCommonDescriptorHeader != NULL) { - + // // UsbSamp_ValidateConfigurationDescriptor validates all descriptors. - // This means that the descriptor pointed to by pCommonDescriptorHeader( received above ) is completely + // This means that the descriptor pointed to by pCommonDescriptorHeader( received above ) is completely // contained within the buffer representing ConfigurationDescriptor and // it also verifies that pCommonDescriptorHeader->bLength is >= sizeof(USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR) // - - *ppEndpointCompanionDescriptor = + + *ppEndpointCompanionDescriptor = (PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR) pCommonDescriptorHeader; - + } else { - + UsbSamp_DbgPrint(3, ("USBD_ParseDescriptors failed to retrieve SuperSpeed Endpoint Companion Descriptor unexpectedly\n")); - + } - } + } + - End: return pEndpointDescriptor; } @@ -1018,7 +1017,7 @@ Return Value: -*/ { WDF_USB_PIPE_INFORMATION pipeInfo; - PPIPE_CONTEXT pipeContext; + PPIPE_CONTEXT pipeContext; UCHAR endpointAddress; PUSB_ENDPOINT_DESCRIPTOR pEndpointDescriptor; PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR pEndpointCompanionDescriptor; @@ -1032,7 +1031,7 @@ Return Value: WDF_USB_PIPE_INFORMATION_INIT(&pipeInfo); WdfUsbTargetPipeGetInformation(Pipe, &pipeInfo); - + // // We use the pipe context only for isoch endpoints. // @@ -1053,17 +1052,17 @@ Return Value: &pEndpointCompanionDescriptor); if (pEndpointDescriptor == NULL || pEndpointCompanionDescriptor == NULL ){ - + UsbSamp_DbgPrint(1, ("pEndpointDescriptor or pEndpointCompanionDescriptor is invalid (NULL)\n")); return STATUS_INVALID_PARAMETER; - + } // // For SuperSpeed isoch endpoint, it uses wBytesPerInterval from its // endpoint companion descriptor. If bMaxBurst field in its endpoint // companion descriptor is greater than zero, wMaxPacketSize must be - // 1024. If the value in the bMaxBurst field is set to zero then + // 1024. If the value in the bMaxBurst field is set to zero then // wMaxPacketSize can have any value from 0 to 1024. // wBytesPerInterval = pEndpointCompanionDescriptor->wBytesPerInterval; @@ -1072,7 +1071,7 @@ Return Value: bMult = pEndpointCompanionDescriptor->bmAttributes.Isochronous.Mult; if (wBytesPerInterval > (wMaxPacketSize * (bMaxBurst + 1) * (bMult + 1))){ - + UsbSamp_DbgPrint(1, ("SuperSpeed isochronouse endpoints's wBytesPerInterval value (%d) is greater than wMaxPacketSize * (bMaxBurst+1) * (Mult +1) (%d) \n", wBytesPerInterval, (wMaxPacketSize * (bMaxBurst + 1) * (bMult + 1)))); return STATUS_INVALID_PARAMETER; @@ -1081,13 +1080,13 @@ Return Value: if (bMaxBurst > 0){ - if (wMaxPacketSize != USB_ENDPOINT_SUPERSPEED_ISO_MAX_PACKET_SIZE){ - + if (wMaxPacketSize != USB_ENDPOINT_SUPERSPEED_ISO_MAX_PACKET_SIZE){ + UsbSamp_DbgPrint(1, ("SuperSpeed isochronouse endpoints must have wMaxPacketSize value of %d bytes when bMaxpBurst is %d \n", USB_ENDPOINT_SUPERSPEED_ISO_MAX_PACKET_SIZE, bMaxBurst)); return STATUS_INVALID_PARAMETER; - } + } } else { @@ -1097,24 +1096,24 @@ Return Value: USB_ENDPOINT_SUPERSPEED_ISO_MAX_PACKET_SIZE, bMaxBurst)); return STATUS_INVALID_PARAMETER; - } + } } - + // - // This sample demos how to use wBytesPerInterval from its Endpoint + // This sample demos how to use wBytesPerInterval from its Endpoint // Companion Descriptor. Actaully, for Superspeed isochronous endpoints, // MaximumPacketSize in WDF_USB_PIPE_INFORMATION and USBD_PIPE_INFORMATION // is returned with the value of wBytesPerInterval in the endpoint // companion descriptor. This is different than the true MaxPacketSize of // the endpoint descriptor. // - NT_ASSERT(pipeInfo.MaximumPacketSize == wBytesPerInterval); + NT_ASSERT(pipeInfo.MaximumPacketSize == wBytesPerInterval); pipeContext->TransferSizePerMicroframe = wBytesPerInterval; - + // - // Microsoft USB 3.0 stack only supports bInterval value of 1, 2, 3 and 4 + // Microsoft USB 3.0 stack only supports bInterval value of 1, 2, 3 and 4 // (or polling period of 1, 2, 4 and 8). // For super-speed isochronous endpoints, the bInterval value is used as // the exponent for a 2^(bInterval-1) value expressed in microframes; @@ -1157,14 +1156,14 @@ Return Value: break; } - UsbSamp_DbgPrint(1, ("MaxPacketSize = %d, bInterval = %d\n", + UsbSamp_DbgPrint(1, ("MaxPacketSize = %d, bInterval = %d\n", pipeInfo.MaximumPacketSize, pipeInfo.Interval)); - UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d, TransferSizePerMicroframe = %d\n", - pipeContext->TransferSizePerFrame, - pipeContext->TransferSizePerMicroframe)); - + UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d, TransferSizePerMicroframe = %d\n", + pipeContext->TransferSizePerFrame, + pipeContext->TransferSizePerMicroframe)); + return STATUS_SUCCESS; } @@ -1198,23 +1197,23 @@ Return Value: WDF_USB_PIPE_INFORMATION_INIT(&pipeInfo); WdfUsbTargetPipeGetInformation(Pipe, &pipeInfo); - + // // We use the pipe context only for isoch endpoints. // if ((WdfUsbPipeTypeIsochronous != pipeInfo.PipeType)) { return STATUS_SUCCESS; } - + pipeContext = GetPipeContext(Pipe); - + if (pipeInfo.MaximumPacketSize == 0) { UsbSamp_DbgPrint(1, ("MaximumPacketSize in the pipeInfo is invalid (zero)\n")); return STATUS_INVALID_PARAMETER; } - + // - // Universal Serial Bus Specification Revision 2.0 5.6.3 Isochronous Transfer + // Universal Serial Bus Specification Revision 2.0 5.6.3 Isochronous Transfer // Packet Size Constraints: High-speed endpoints are allowed up to 1024-byte data // payloads per microframe and allowed up to a maximum of 3 transactions per microframe. // @@ -1225,7 +1224,7 @@ Return Value: // 10 - 2 additional (3 per microframe) // 11 - Reserved. // - // Note: MaximumPacketSize of WDF_USB_PIPE_INFORMATION is already adjusted to include + // Note: MaximumPacketSize of WDF_USB_PIPE_INFORMATION is already adjusted to include // additional transactions if it is a high bandwidth pipe. // @@ -1236,7 +1235,7 @@ Return Value: // // Microsoft USB stack only supports bInterval value of 1, 2, 3 and 4 (or polling period of 1, 2, 4 and 8). - // + // if (pipeInfo.Interval == 0 || pipeInfo.Interval > 4) { UsbSamp_DbgPrint(1, ("bInterval value in pipeInfo is invalid (0 or > 4)\n")); return STATUS_INVALID_PARAMETER; @@ -1282,14 +1281,14 @@ Return Value: break; } - UsbSamp_DbgPrint(1, ("MaxPacketSize = %d, bInterval = %d\n", + UsbSamp_DbgPrint(1, ("MaxPacketSize = %d, bInterval = %d\n", pipeInfo.MaximumPacketSize, pipeInfo.Interval)); - UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d, TransferSizePerMicroframe = %d\n", - pipeContext->TransferSizePerFrame, - pipeContext->TransferSizePerMicroframe)); - + UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d, TransferSizePerMicroframe = %d\n", + pipeContext->TransferSizePerFrame, + pipeContext->TransferSizePerMicroframe)); + return STATUS_SUCCESS; } @@ -1321,14 +1320,14 @@ Return Value: WDF_USB_PIPE_INFORMATION_INIT(&pipeInfo); WdfUsbTargetPipeGetInformation(Pipe, &pipeInfo); - + // // We use the pipe context only for isoch endpoints. // if ((WdfUsbPipeTypeIsochronous != pipeInfo.PipeType)) { return STATUS_SUCCESS; } - + pipeContext = GetPipeContext(Pipe); if (pipeInfo.MaximumPacketSize == 0) { @@ -1351,7 +1350,7 @@ Return Value: // // Microsoft USB stack only supports bInterval value of 1 for // full-speed isochronous endpoints. - // + // if (pipeInfo.Interval != 1) { UsbSamp_DbgPrint(1, ("bInterval value in endpoint descriptor is invalid\n")); return STATUS_INVALID_PARAMETER; @@ -1360,8 +1359,8 @@ Return Value: pipeContext->TransferSizePerFrame = pipeInfo.MaximumPacketSize; pipeContext->TransferSizePerMicroframe = 0; - UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d\n", pipeContext->TransferSizePerFrame)); - + UsbSamp_DbgPrint(1, ("TransferSizePerFrame = %d\n", pipeContext->TransferSizePerFrame)); + return STATUS_SUCCESS; } @@ -1428,13 +1427,13 @@ RetrieveDeviceInformation( if (pDeviceContext->IsStaticStreamsSupported) { UsbSamp_DbgPrint(3, ("Number of Streams supported by the controller: %d\n", numberOfStreams)); - } + } } return STATUS_SUCCESS; } - + NTSTATUS ReadFdoRegistryKeyValue( _In_ WDFDRIVER Driver, @@ -1457,7 +1456,7 @@ Arguments: Return Value: - NTSTATUS + NTSTATUS --*/ { @@ -1513,6 +1512,11 @@ Return Value: WDFDEVICE device; PDEVICE_CONTEXT pDevContext; + // + // EvtCleanupCallback for WDFDEVICE is always called at PASSIVE_LEVEL + // + _Analysis_assume_(KeGetCurrentIrql() == PASSIVE_LEVEL); + PAGED_CODE(); device = (WDFDEVICE)WdfDevice; @@ -1526,7 +1530,7 @@ Return Value: } USBD_STATUS -UsbSamp_ValidateConfigurationDescriptor( +UsbSamp_ValidateConfigurationDescriptor( _In_reads_bytes_(BufferLength) PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, _In_ ULONG BufferLength, _Inout_ PUCHAR *Offset @@ -1539,13 +1543,13 @@ Routine Description: Parameters: - ConfigDesc: Pointer to the entire USB Configuration descriptor returned by + ConfigDesc: Pointer to the entire USB Configuration descriptor returned by the device BufferLength: Known size of buffer pointed to by ConfigDesc (Not wTotalLength) Offset: if the USBD_STATUS returned is not USBD_STATUS_SUCCESS, offet will - be set to the address within the ConfigDesc buffer where the failure + be set to the address within the ConfigDesc buffer where the failure occured. Return Value: @@ -1568,7 +1572,7 @@ Return Value: // It also checks for interface numbers, number of endpoints in an interface etc. // Please refer to msdn documentation for this function for more information. // - + status = USBD_ValidateConfigurationDescriptor( ConfigDesc, BufferLength , ValidationLevel , Offset , POOL_TAG ); if (!(NT_SUCCESS (status)) ){ return status; @@ -1576,12 +1580,12 @@ Return Value: // // TODO: You should validate the correctness of other descriptors which are not taken care by USBD_ValidateConfigurationDescriptor - // The below code loops through the configuration descriptor and verifies that all instances of + // The below code loops through the configuration descriptor and verifies that all instances of // USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR have a size of >= USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR // You should put in more validations as per requirement - // - - + // + + offset = ((PUCHAR)ConfigDesc) + ConfigDesc->bLength; end = ((PUCHAR)ConfigDesc) + ConfigDesc->wTotalLength; @@ -1590,12 +1594,12 @@ Return Value: // // Ensure the descriptor header is in bounds. We always // need to ensure we have enough data to look at the descriptor - // header fields. Sometimes descriptors are zeroed at the end, + // header fields. Sometimes descriptors are zeroed at the end, // this is OK. // commonDesc = (PUSB_COMMON_DESCRIPTOR)offset; - + switch(commonDesc->bDescriptorType){ case USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR_TYPE: @@ -1621,7 +1625,7 @@ Return Value: } ValidateConfigurationDescriptor_Done: - + if(!USBD_SUCCESS(status)){ NT_ASSERT(index); *Offset = index; @@ -1657,8 +1661,6 @@ Return Value: PPIPE_CONTEXT pPipeContext = NULL; PUSBSAMP_STREAM_INFO pStreamInfo = NULL; - PAGED_CODE(); - pipe = (WDFUSBPIPE)WdfObject; pPipeContext = GetPipeContext(pipe); @@ -1669,6 +1671,5 @@ Return Value: ExFreePool(pStreamInfo->StreamList); pStreamInfo->StreamList = NULL; } - } #endif diff --git a/usb/usbsamp/sys/queue.c b/usb/usbsamp/sys/queue.c index 5047d24c..c635adb6 100644 --- a/usb/usbsamp/sys/queue.c +++ b/usb/usbsamp/sys/queue.c @@ -101,7 +101,7 @@ Return Value: WdfUsbTargetPipeSetNoMaximumPacketSizeCheck(pipe); status = STATUS_SUCCESS; - } + } else { status = STATUS_INVALID_DEVICE_REQUEST; } @@ -161,6 +161,12 @@ Return Value: UsbSamp_DbgPrint(3, ("Entered UsbSamp_DispatchDevCtrl\n")); + // + // If your driver is at the top of its driver stack, EvtIoDeviceControl is called + // at IRQL = PASSIVE_LEVEL. + // + _Analysis_assume_(KeGetCurrentIrql() == PASSIVE_LEVEL); + PAGED_CODE(); // @@ -257,6 +263,12 @@ Return Value: WDFUSBPIPE pipe; WDF_USB_PIPE_INFORMATION pipeInfo; + // + // If your driver is at the top of its driver stack, EvtIoRead is called + // at IRQL = PASSIVE_LEVEL. + // + _Analysis_assume_(KeGetCurrentIrql() == PASSIVE_LEVEL); + PAGED_CODE(); // @@ -278,7 +290,7 @@ Return Value: ReadWriteBulkEndPoints(Queue, Request, (ULONG) Length, WdfRequestTypeRead); return; - } + } else if (WdfUsbPipeTypeIsochronous == pipeInfo.PipeType){ #if !defined(BUFFERED_READ_WRITE) // if doing DIRECT_IO @@ -325,6 +337,12 @@ Return Value: WDFUSBPIPE pipe; WDF_USB_PIPE_INFORMATION pipeInfo; + // + // If your driver is at the top of its driver stack, EvtIoWrite is called + // at IRQL = PASSIVE_LEVEL. + // + _Analysis_assume_(KeGetCurrentIrql() == PASSIVE_LEVEL); + PAGED_CODE(); // @@ -346,7 +364,7 @@ Return Value: ReadWriteBulkEndPoints(Queue, Request, (ULONG) Length, WdfRequestTypeWrite); return; - } + } else if (WdfUsbPipeTypeIsochronous == pipeInfo.PipeType){ #if !defined(BUFFERED_READ_WRITE) // if doing DIRECT_IO @@ -565,7 +583,7 @@ Return Value: PAGED_CODE(); pDeviceContext = GetDeviceContext(Device); - + // // A reset-device // request will be stuck in the USB until the pending transactions @@ -576,7 +594,7 @@ Return Value: // continuous reader (by calling WdfIoTargetStart) after the request completes. // StopAllPipes(pDeviceContext); - + // // It may not be necessary to check whether device is connected before // resetting the port. @@ -588,7 +606,7 @@ Return Value: } StartAllPipes(pDeviceContext); - + UsbSamp_DbgPrint(3, ("ResetDevice - ends\n")); return status; diff --git a/usb/usbsamp/sys/stream.c b/usb/usbsamp/sys/stream.c index 55243d06..ee434b35 100644 --- a/usb/usbsamp/sys/stream.c +++ b/usb/usbsamp/sys/stream.c @@ -200,7 +200,7 @@ Return Value: pStreamInfo->NumberOfStreams = supportedStreams; pStreamInfo->StreamList = ExAllocatePoolWithTag( - NonPagedPool, + NonPagedPoolNx, supportedStreams * sizeof(USBD_STREAM_INFORMATION), POOL_TAG); @@ -230,6 +230,7 @@ Return Value: pUrb->UrbOpenStaticStreams.Streams = pStreamInfo->StreamList; // Send the URB down the stack + #pragma prefast(suppress:__WARNING_WRITE_OVERRUN, "SAL noise") status = WdfUsbTargetPipeSendUrbSynchronously( Pipe, NULL, diff --git a/usb/usbview/debug.c b/usb/usbview/debug.c index bdd25589..1031cc5b 100644 --- a/usb/usbview/debug.c +++ b/usb/usbview/debug.c @@ -116,7 +116,7 @@ MyReAlloc ( { return NULL; } - + header = (PALLOCHEADER)hMem; header--; @@ -135,6 +135,7 @@ MyReAlloc ( // and the original handle and pointer are still valid. // Add the old address back to the allocation list. // + #pragma prefast(suppress:__WARNING_USING_UNINIT_VAR, "SAL noise") InsertTailList(&AllocListHead, &header->ListEntry); } else diff --git a/usb/usbview/display.c b/usb/usbview/display.c index 3191d97f..6d7846ee 100644 --- a/usb/usbview/display.c +++ b/usb/usbview/display.c @@ -248,7 +248,7 @@ VOID DisplayEndpointDescriptor ( _In_ PUSB_ENDPOINT_DESCRIPTOR EndpointDesc, - _In_opt_ PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR + _In_opt_ PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR EpCompDesc, _In_opt_ PUSB_SUPERSPEEDPLUS_ISOCH_ENDPOINT_COMPANION_DESCRIPTOR SspIsochCompDesc, @@ -367,19 +367,19 @@ GetNextDescriptor() *****************************************************************************/ PUSB_COMMON_DESCRIPTOR GetNextDescriptor( - _In_reads_bytes_(TotalLength) + _In_reads_bytes_(TotalLength) PUSB_COMMON_DESCRIPTOR FirstDescriptor, _In_ ULONG TotalLength, - _In_ + _In_ PUSB_COMMON_DESCRIPTOR StartDescriptor, - _In_ long + _In_ long DescriptorType ) { PUSB_COMMON_DESCRIPTOR currentDescriptor = NULL; PUSB_COMMON_DESCRIPTOR endDescriptor = NULL; - + endDescriptor = (PUSB_COMMON_DESCRIPTOR)((PUCHAR)FirstDescriptor + TotalLength); if (StartDescriptor >= endDescriptor || @@ -537,7 +537,7 @@ AppendTextBuffer ( return; } - + TextBufferTmp = REALLOC(TextBuffer, uNewTextBufferLen); if (TextBufferTmp != NULL) @@ -639,7 +639,7 @@ ULONG GetEhciDebugPort(ULONG vendorId, ULONG deviceId) // // hTreeItem - Handle of selected TreeView item for which information should // be added to the TextBuffer global -// +// // The functions returns error status if AppendTextBuffer() used in Display*() functions // fails. The display text would be missing or truncated in such cases. //***************************************************************************** @@ -703,13 +703,13 @@ UpdateTreeItemDeviceInfo( PUSB_NODE_CONNECTION_INFORMATION_EX ConnectionInfo = NULL; PUSB_DESCRIPTOR_REQUEST ConfigDesc = NULL; PSTRING_DESCRIPTOR_NODE StringDescs = NULL; - PUSB_HUB_INFORMATION_EX HubInfoEx = NULL; + PUSB_HUB_INFORMATION_EX HubInfoEx = NULL; PUSB_HUB_CAPABILITIES_EX HubCapabilityEx = NULL; PUSB_PORT_CONNECTOR_PROPERTIES PortConnectorProps = NULL; PUSB_NODE_CONNECTION_INFORMATION_EX_V2 ConnectionInfoV2 = NULL; PUSB_DESCRIPTOR_REQUEST BosDesc = NULL; PDEVICE_INFO_NODE DeviceInfoNode = NULL; - + // The TextBuffer has the TreeView name; add 2 lines for display AppendTextBuffer("\r\n\r\n"); @@ -737,10 +737,10 @@ UpdateTreeItemDeviceInfo( // // Search for the debug port number. If running on Win8 or later, - // the USB_PORT_CONNECTOR_PROPERTIES structure will contain the - // port number. If that fails, the list of known host controllers + // the USB_PORT_CONNECTOR_PROPERTIES structure will contain the + // port number. If that fails, the list of known host controllers // with debug ports will be searched. - // + // AppendTextBuffer("\r\nDebug Port Number: "); @@ -751,7 +751,7 @@ UpdateTreeItemDeviceInfo( HTREEITEM portItem = NULL; PVOID portInfo; - portItem = TreeView_GetChild(hTreeWnd, rootHubItem); + portItem = TreeView_GetChild(hTreeWnd, rootHubItem); while (portItem != NULL) { @@ -767,7 +767,7 @@ UpdateTreeItemDeviceInfo( // // Note that an empty port is a port without a device attached // is still a DeviceInfo instance. - // + // if ((*(PUSBDEVICEINFOTYPE)portInfo) == DeviceInfo) { @@ -778,7 +778,7 @@ UpdateTreeItemDeviceInfo( { ConnectionInfo = ((PUSBEXTERNALHUBINFO)portInfo)->ConnectionInfo; PortConnectorProps = ((PUSBEXTERNALHUBINFO)portInfo)->PortConnectorProps; - + } if (ConnectionInfo != NULL && @@ -787,7 +787,7 @@ UpdateTreeItemDeviceInfo( { dbgPortFound = TRUE; AppendTextBuffer("%d\r\n", ((PUSBDEVICEINFO)portInfo)->ConnectionInfo->ConnectionIndex); - break; + break; } portItem = TreeView_GetNextSibling(hTreeWnd, portItem); } @@ -796,7 +796,7 @@ UpdateTreeItemDeviceInfo( // Resetting ConnectionInfo and PortConnectorProps to NULL so that they won't be erroneously // be displayed below. // - + ConnectionInfo = NULL; PortConnectorProps = NULL; } @@ -831,7 +831,7 @@ UpdateTreeItemDeviceInfo( ((PUSBHOSTCONTROLLERINFO)info)->BusDevice, ((PUSBHOSTCONTROLLERINFO)info)->BusFunction); } - + // Display the USB Host Controller Power State Info { PUSB_POWER_INFO pUPI = (PUSB_POWER_INFO) &((PUSBHOSTCONTROLLERINFO)info)->USBPowerInfo[0]; @@ -840,7 +840,7 @@ UpdateTreeItemDeviceInfo( AppendTextBuffer("\r\nHost Controller Power State Mappings\r\n"); AppendTextBuffer("System State\t\tHost Controller\t\tRoot Hub\tUSB wakeup\tPowered\r\n"); - for ( ; nPowerState < WdmUsbPowerSystemShutdown; nIndex++, nPowerState++, pUPI++) + for ( ; nPowerState < WdmUsbPowerSystemShutdown; nIndex++, nPowerState++, pUPI++) { DisplayPowerState(pUPI); } @@ -935,7 +935,7 @@ UpdateTreeItemDeviceInfo( if (BosDesc) { - DisplayBosDescriptor((PUSBDEVICEINFO) info, + DisplayBosDescriptor((PUSBDEVICEINFO) info, (PUSB_BOS_DESCRIPTOR) (BosDesc + 1), StringDescs); } @@ -946,7 +946,7 @@ UpdateTreeItemDeviceInfo( FREE(tviName); } - // AppendTextBuffer() which is used in Display*() functions uses GlobalRealloc() which can fail if realloc fails. + // AppendTextBuffer() which is used in Display*() functions uses GlobalRealloc() which can fail if realloc fails. // Obtain last error code from GetLastError() and propagate the error to caller. hr = HRESULT_FROM_WIN32(GetLastError()); @@ -1008,11 +1008,11 @@ DisplayPortConnectorProperties ( ) { AppendTextBuffer("Is Port User Connectable: %s\r\n", - PortConnectorProps->UsbPortProperties.PortIsUserConnectable + PortConnectorProps->UsbPortProperties.PortIsUserConnectable ? "yes" : "no"); - + AppendTextBuffer("Is Port Debug Capable: %s\r\n", - PortConnectorProps->UsbPortProperties.PortIsDebugCapable + PortConnectorProps->UsbPortProperties.PortIsDebugCapable ? "yes" : "no"); AppendTextBuffer("Companion Port Number: %d\r\n", PortConnectorProps->CompanionPortNumber); @@ -1022,17 +1022,17 @@ DisplayPortConnectorProperties ( { AppendTextBuffer("Protocols Supported:\r\n"); AppendTextBuffer(" USB 1.1: %s\r\n", - ConnectionInfoV2->SupportedUsbProtocols.Usb110 + ConnectionInfoV2->SupportedUsbProtocols.Usb110 ? "yes" : "no"); AppendTextBuffer(" USB 2.0: %s\r\n", - ConnectionInfoV2->SupportedUsbProtocols.Usb200 + ConnectionInfoV2->SupportedUsbProtocols.Usb200 ? "yes" : "no"); AppendTextBuffer(" USB 3.0: %s\r\n", - ConnectionInfoV2->SupportedUsbProtocols.Usb300 - ? "yes" : "no"); + ConnectionInfoV2->SupportedUsbProtocols.Usb300 + ? "yes" : "no"); } - AppendTextBuffer("\r\n"); + AppendTextBuffer("\r\n"); } /***************************************************************************** @@ -1048,7 +1048,7 @@ DisplayDevicePowerState ( _In_ PDEVICE_INFO_NODE DeviceInfoNode ) { - + DEVICE_POWER_STATE powerState; powerState = AcquireDevicePowerState(DeviceInfoNode); @@ -1062,8 +1062,8 @@ DisplayDevicePowerState ( { AppendTextBuffer("Invalid Device Power State Value %d\r\n", powerState); } - - AppendTextBuffer("\r\n"); + + AppendTextBuffer("\r\n"); } @@ -1071,7 +1071,7 @@ DisplayDevicePowerState ( DisplayHubDescriptorBase() -HubDescriptor - hub descriptor, could also be PUSB_30_HUB_DESCRIPTOR which has +HubDescriptor - hub descriptor, could also be PUSB_30_HUB_DESCRIPTOR which has these field in common at the beginning of the data structure: - UCHAR bLength; @@ -1158,7 +1158,7 @@ DisplayHubInfo ( HubInfo->HubIsBusPowered ? "Bus Power" : "Self Power"); - if (DisplayDescriptor == TRUE) + if (DisplayDescriptor == TRUE) { DisplayHubDescriptorBase(&HubInfo->HubDescriptor); } @@ -1179,19 +1179,19 @@ DisplayHubInfoEx ( ) { AppendTextBuffer("Hub type: "); - + switch (HubInfoEx->HubType) { - - case UsbRootHub: - AppendTextBuffer("USB Root Hub\r\n"); + + case UsbRootHub: + AppendTextBuffer("USB Root Hub\r\n"); break; - - case Usb20Hub: - AppendTextBuffer("USB 2.0 Hub\r\n"); + + case Usb20Hub: + AppendTextBuffer("USB 2.0 Hub\r\n"); DisplayHubDescriptorBase((PUSB_HUB_DESCRIPTOR)&HubInfoEx->u.UsbHubDescriptor); break; - - case Usb30Hub: + + case Usb30Hub: AppendTextBuffer("USB 3.0 Hub\r\n"); // @@ -1199,18 +1199,18 @@ DisplayHubInfoEx ( // the legacy hub descriptor and the USB 3.0 descriptor which have the same // offset // - + DisplayHubDescriptorBase((PUSB_HUB_DESCRIPTOR)&HubInfoEx->u.UsbHubDescriptor); AppendTextBuffer("Packet Header Decode Latency: 0x%x\r\n", HubInfoEx->u.Usb30HubDescriptor.bHubHdrDecLat); AppendTextBuffer("Delay: 0x%x ns\r\n", HubInfoEx->u.Usb30HubDescriptor.wHubDelay); - + break; - - default: + + default: AppendTextBuffer("ERROR: Unknown hub type %d\r\n", HubInfoEx->HubType); break; } - + AppendTextBuffer("\r\n"); } @@ -1232,22 +1232,22 @@ DisplayHubCapabilityEx ( if(HubCapabilityEx != NULL) { AppendTextBuffer("High speed capable: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsHighSpeedCapable + HubCapabilityEx->CapabilityFlags.HubIsHighSpeedCapable ? "Yes" : "No"); AppendTextBuffer("High speed: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsHighSpeed + HubCapabilityEx->CapabilityFlags.HubIsHighSpeed ? "Yes" : "No"); AppendTextBuffer("Multiple transaction translations capable: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsMultiTtCapable + HubCapabilityEx->CapabilityFlags.HubIsMultiTtCapable ? "Yes" : "No"); AppendTextBuffer("Performs multiple transaction translations simultaneously: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsMultiTt + HubCapabilityEx->CapabilityFlags.HubIsMultiTt ? "Yes" : "No"); AppendTextBuffer("Hub wakes when device is connected: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsArmedWakeOnConnect + HubCapabilityEx->CapabilityFlags.HubIsArmedWakeOnConnect ? "Yes" : "No"); AppendTextBuffer("Hub is bus powered: %s\r\n", - HubCapabilityEx->CapabilityFlags.HubIsBusPowered + HubCapabilityEx->CapabilityFlags.HubIsBusPowered ? "Yes" : "No"); AppendTextBuffer("Hub is root: %s\r\n", HubCapabilityEx->CapabilityFlags.HubIsRoot @@ -1297,17 +1297,17 @@ DisplayConnectionInfo ( // This is the entry point to the device display functions. // First, save this device's PUSBDEVICEINFO address - // In a future version of this test, we will keep track of the the + // In a future version of this test, we will keep track of the the // descriptor that we're parsing (# of bytes from beginning of info->configuration descriptor) // Then we can linked descriptors by reading forward through the remaining descriptors // while still keeping our place in this main DisplayConnectionInfo() and called // functions. // - // We also initialize some global flags in uvcview.h that are used to + // We also initialize some global flags in uvcview.h that are used to // verify items in MJPEG, Uncompressed and Vendor Frame descriptors // InitializePerDeviceSettings(info); - + if(gDoAnnotation) { @@ -1333,13 +1333,13 @@ DisplayConnectionInfo ( { AppendTextBuffer(" -> Device Bus Speed: Low\r\n"); } - else + else { AppendTextBuffer("\r\n"); } gDeviceSpeed = UsbLowSpeed; break; - + case UsbFullSpeed: if(gDoAnnotation) { @@ -1364,7 +1364,7 @@ DisplayConnectionInfo ( AppendTextBuffer("\r\n"); } } - else + else { AppendTextBuffer("\r\n"); } @@ -1394,13 +1394,13 @@ DisplayConnectionInfo ( AppendTextBuffer("\r\n"); } } - else + else { AppendTextBuffer("\r\n"); } gDeviceSpeed = UsbHighSpeed; break; - + case UsbSuperSpeed: if(gDoAnnotation) { @@ -1409,7 +1409,7 @@ DisplayConnectionInfo ( ? "SpeedPlus" : "Speed"); } - else + else { AppendTextBuffer("\r\n"); } @@ -1428,7 +1428,7 @@ DisplayConnectionInfo ( AppendTextBuffer("Open Pipes: %2d\r\n", ConnectInfo->NumberOfOpenPipes); } - + // No open pipes means the USB stack has not loaded the device if (ConnectInfo->NumberOfOpenPipes == 0) { @@ -1443,7 +1443,7 @@ DisplayConnectionInfo ( //@@TestCase A1.1 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to the + //@@The declared length in the device descriptor is not equal to the //@@ required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d incorrect, should be %d\r\n", ConnectInfo->DeviceDescriptor.bLength, @@ -1468,7 +1468,7 @@ DisplayConnectionInfo ( ConnectInfo->DeviceDescriptor.bDeviceClass); // Quit on these device failures - if ((ConnectInfo->ConnectionStatus == DeviceFailedEnumeration) || + if ((ConnectInfo->ConnectionStatus == DeviceFailedEnumeration) || (ConnectInfo->ConnectionStatus == DeviceGeneralFailure)) { AppendTextBuffer("\r\n*!*ERROR: Device enumeration failure\r\n"); @@ -1488,7 +1488,7 @@ DisplayConnectionInfo ( { AppendTextBuffer(" -> This is a Multi-interface Function Code Device\r\n"); } - else + else { AppendTextBuffer("\r\n"); } @@ -1499,8 +1499,8 @@ DisplayConnectionInfo ( } // Is this a UVC device? g_chUVCversion = IsUVCDevice((PUSBDEVICEINFO) info); - } - else + } + else { // this is not an IAD device switch (ConnectInfo->DeviceDescriptor.bDeviceClass) @@ -1590,12 +1590,12 @@ DisplayConnectionInfo ( if (gDoAnnotation) { AppendTextBuffer(" -> This is the Common Class Sub Class\r\n"); - } else + } else { AppendTextBuffer("\r\n"); } - } - else + } + else { //@@TestCase A1.5 //@@ERROR @@ -1606,11 +1606,11 @@ DisplayConnectionInfo ( USB_COMMON_SUB_CLASS); OOPS(); } - } - else + } + else { // Not an IAD device, so all subclass values are invalid - if(ConnectInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && + if(ConnectInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && ConnectInfo->DeviceDescriptor.bDeviceSubClass < 0xFF) { //@@TestCase A1.6 @@ -1620,7 +1620,7 @@ DisplayConnectionInfo ( AppendTextBuffer("\r\n*!*ERROR: bDeviceSubClass of %d is invalid\r\n", ConnectInfo->DeviceDescriptor.bDeviceSubClass); OOPS(); - } else + } else { AppendTextBuffer("\r\n"); } @@ -1638,13 +1638,13 @@ DisplayConnectionInfo ( if (gDoAnnotation) { AppendTextBuffer(" -> This is the Interface Association Descriptor protocol\r\n"); - } - else + } + else { AppendTextBuffer("\r\n"); } - } - else + } + else { //@@TestCase A1.7 //@@ERROR @@ -1655,11 +1655,11 @@ DisplayConnectionInfo ( USB_IAD_PROTOCOL); OOPS(); } - } - else + } + else { // Not an IAD device, so all subclass values are invalid - if(ConnectInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && + if(ConnectInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && ConnectInfo->DeviceDescriptor.bDeviceProtocol < 0xFF && tog==1) { //@@TestCase A1.8 @@ -1669,7 +1669,7 @@ DisplayConnectionInfo ( AppendTextBuffer("\r\n*!*ERROR: bDeviceProtocol of %d is invalid\r\n", ConnectInfo->DeviceDescriptor.bDeviceProtocol); OOPS(); - } + } else { AppendTextBuffer("\r\n"); @@ -1683,8 +1683,8 @@ DisplayConnectionInfo ( { AppendTextBuffer(" = (%d) Bytes\r\n", ConnectInfo->DeviceDescriptor.bMaxPacketSize0); - } - else + } + else { AppendTextBuffer("\r\n"); } @@ -1860,7 +1860,7 @@ Returns the descriptive string for given power state *****************************************************************************/ PCHAR GetPowerStateString(WDMUSB_POWER_STATE powerState) { - return(GetStringFromList(slPowerState, + return(GetStringFromList(slPowerState, sizeof(slPowerState) / sizeof(STRINGLIST), powerState, STR_INVALID_POWER_STATE)); @@ -1880,9 +1880,9 @@ DisplayPowerState( ) { AppendTextBuffer("%s\t%s\t%s%s\t\t%s\r\n", - GetPowerStateString(pUPI->SystemState), - GetPowerStateString(pUPI->HcDevicePowerState), - GetPowerStateString(pUPI->RhDevicePowerState), + GetPowerStateString(pUPI->SystemState), + GetPowerStateString(pUPI->HcDevicePowerState), + GetPowerStateString(pUPI->RhDevicePowerState), pUPI->CanWakeup ? "Yes" : "", pUPI->IsPowered ? "Yes" : "" ); @@ -1938,7 +1938,7 @@ DisplayConfigDesc ( BOOL isSS; - isSS = info->ConnectionInfoV2 + isSS = info->ConnectionInfoV2 && info->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedOrHigher ? TRUE : FALSE; @@ -1952,7 +1952,7 @@ DisplayConfigDesc ( AppendTextBuffer("\r\n ---===>Full Configuration Descriptor<===---\r\n"); - do + do { displayUnknown = FALSE; @@ -1965,7 +1965,7 @@ DisplayConfigDesc ( //@@TestCase A2.1 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to the + //@@The declared length in the device descriptor is not equal to the //@@ required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d for Device Qualifier incorrect, "\ "should be %d\r\n", @@ -1985,7 +1985,7 @@ DisplayConfigDesc ( //@@TestCase A2.2 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to the + //@@The declared length in the device descriptor is not equal to the //@@ required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d for Other Speed Configuration "\ "incorrect, should be %d\r\n", @@ -2007,7 +2007,7 @@ DisplayConfigDesc ( //@@TestCase A2.3 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to the + //@@The declared length in the device descriptor is not equal to the //@@required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d for Configuration incorrect, "\ "should be %d\r\n", @@ -2030,7 +2030,7 @@ DisplayConfigDesc ( //@@TestCase A2.4 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to the + //@@The declared length in the device descriptor is not equal to the //@@required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d for Interface incorrect, "\ "should be %d or %d\r\n", @@ -2046,7 +2046,7 @@ DisplayConfigDesc ( bInterfaceProtocol = ((PUSB_INTERFACE_DESCRIPTOR)commonDesc)->bInterfaceProtocol; DisplayInterfaceDescriptor( - (PUSB_INTERFACE_DESCRIPTOR)commonDesc, + (PUSB_INTERFACE_DESCRIPTOR)commonDesc, StringDescs, info->DeviceInfoNode != NULL? info->DeviceInfoNode->LatestDevicePowerState: PowerDeviceUnspecified); @@ -2058,7 +2058,7 @@ DisplayConfigDesc ( PUSB_SUPERSPEEDPLUS_ISOCH_ENDPOINT_COMPANION_DESCRIPTOR sspIsochCompDesc = NULL; - + //@@DisplayConfigDesc - Endpoint Descriptor if ((commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR)) && (commonDesc->bLength != sizeof(USB_ENDPOINT_DESCRIPTOR2))) @@ -2066,7 +2066,7 @@ DisplayConfigDesc ( //@@TestCase A2.5 //@@ERROR //@@Descriptor Field - bLength - //@@The declared length in the device descriptor is not equal to + //@@The declared length in the device descriptor is not equal to //@@ the required length in the USB Device Specification AppendTextBuffer("*!*ERROR: bLength of %d for Endpoint incorrect, "\ "should be %d or %d\r\n", @@ -2139,7 +2139,7 @@ DisplayConfigDesc ( displayUnknown = TRUE; break; } - DisplayIADDescriptor((PUSB_IAD_DESCRIPTOR)commonDesc, StringDescs, + DisplayIADDescriptor((PUSB_IAD_DESCRIPTOR)commonDesc, StringDescs, ConfigDesc->bNumInterfaces, info->DeviceInfoNode != NULL? info->DeviceInfoNode->LatestDevicePowerState: PowerDeviceUnspecified); break; @@ -2318,11 +2318,11 @@ DisplayConfigDesc ( { DisplayUnknownDescriptor(commonDesc); } - } while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR)ConfigDesc, - ConfigDesc->wTotalLength, - commonDesc, + } while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR)ConfigDesc, + ConfigDesc->wTotalLength, + commonDesc, -1)) != NULL); - + #ifdef H264_SUPPORT DoAdditionalErrorChecks(); #endif @@ -2551,7 +2551,7 @@ DisplaySuperSpeedCapabilityExtensionDescriptor ( } AppendTextBuffer("wSpeedsSupported: 0x%02X\r\n", ssCapDesc->wSpeedsSupported); - + if (ssCapDesc->wSpeedsSupported & USB_DEVICE_CAPABILITY_SUPERSPEED_SPEEDS_SUPPORTED_LOW) { if(gDoAnnotation) @@ -2618,7 +2618,7 @@ DisplaySuperSpeedCapabilityExtensionDescriptor ( { AppendTextBuffer("\r\n"); } - + AppendTextBuffer("bU1DevExitLat: 0x%02X", ssCapDesc->bU1DevExitLat); if(gDoAnnotation) @@ -2655,17 +2655,17 @@ DisplaySuperSpeedCapabilityExtensionDescriptor ( else { AppendTextBuffer("\r\n"); - } + } } - + VOID DisplayContainerIdCapabilityExtensionDescriptor ( PUSB_DEVICE_CAPABILITY_CONTAINER_ID_DESCRIPTOR containerIdCapDesc ) { LPGUID pGuid; - + AppendTextBuffer("\r\n ===>Container ID Capability Descriptor<===\r\n"); AppendTextBuffer("bLength: 0x%02X\r\n", @@ -2751,7 +2751,7 @@ DisplayBillboardCapabilityDescriptor ( } else { - switch (billboardCapDesc->VconnPower.VConnPowerNeededForFullFunctionality) + switch (billboardCapDesc->VconnPower.VConnPowerNeededForFullFunctionality) { case 0: AppendTextBuffer(" -> 1W needed by adapter for full functionality\r\n"); @@ -2789,8 +2789,8 @@ DisplayBillboardCapabilityDescriptor ( for (i = 0; i < bNumAlternateModes; i++) { alternateModeConfiguration = ((billboardCapDesc->bmConfigured[i / 4]) >> ((i % 4) * 2)) & 0x3; - AppendTextBuffer("wSVID - 0x%04X bAlternateMode - 0x%02X ->", - billboardCapDesc->AlternateMode[i].wSVID, + AppendTextBuffer("wSVID - 0x%04X bAlternateMode - 0x%02X ->", + billboardCapDesc->AlternateMode[i].wSVID, billboardCapDesc->AlternateMode[i].bAlternateMode, billboardCapDesc->AlternateMode[i].iAlternateModeSetting); @@ -2810,7 +2810,7 @@ DisplayBillboardCapabilityDescriptor ( break; } AppendTextBuffer("iAlternateModeString - 0x%02X ", billboardCapDesc->AlternateMode[i].iAlternateModeSetting); - if (billboardCapDesc->AlternateMode[i].iAlternateModeSetting && gDoAnnotation) + if (billboardCapDesc->AlternateMode[i].iAlternateModeSetting && gDoAnnotation) { DisplayStringDescriptor(billboardCapDesc->AlternateMode[i].iAlternateModeSetting, StringDescs, @@ -2856,9 +2856,9 @@ DisplayBosDescriptor ( commonDesc = (PUSB_COMMON_DESCRIPTOR)BosDesc; - while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR)BosDesc, - BosDesc->wTotalLength, - commonDesc, + while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR)BosDesc, + BosDesc->wTotalLength, + commonDesc, -1)) != NULL) { switch (commonDesc->bDescriptorType) @@ -2866,8 +2866,8 @@ DisplayBosDescriptor ( case USB_DEVICE_CAPABILITY_DESCRIPTOR_TYPE: capDesc = (PUSB_DEVICE_CAPABILITY_DESCRIPTOR)commonDesc; - - switch (capDesc->bDevCapabilityType) + + switch (capDesc->bDevCapabilityType) { case USB_DEVICE_CAPABILITY_USB20_EXTENSION: DisplayUsb20CapabilityExtensionDescriptor((PUSB_DEVICE_CAPABILITY_USB20_EXTENSION_DESCRIPTOR)capDesc); @@ -2883,13 +2883,13 @@ DisplayBosDescriptor ( break; default: AppendTextBuffer("\r\n ===>Unknown Capability Descriptor<===\r\n"); - + AppendTextBuffer("bLength: 0x%02X\r\n", - capDesc->bLength); + capDesc->bLength); AppendTextBuffer("bType: 0x%02X\r\n", - capDesc->bLength); + capDesc->bLength); AppendTextBuffer("bDevCapabilityType: 0x%02X\r\n", - capDesc->bDevCapabilityType); + capDesc->bDevCapabilityType); DisplayRemainingUnknownDescriptor((PUCHAR)commonDesc, (ULONG)sizeof(USB_DEVICE_CAPABILITY_DESCRIPTOR), @@ -2897,7 +2897,7 @@ DisplayBosDescriptor ( break; } break; - + default: DisplayUnknownDescriptor(commonDesc); break; @@ -2920,10 +2920,10 @@ DisplayConfigurationDescriptor ( ) { UINT uCount = 0; - BOOL isSS; + BOOL isSS; - isSS = info->ConnectionInfoV2 + isSS = info->ConnectionInfoV2 && (info->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedOrHigher || info->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedPlusOrHigher) ? TRUE @@ -3013,7 +3013,7 @@ DisplayConfigurationDescriptor ( AppendTextBuffer(" -> Bus Powered\r\n"); } } - } + } else { if (ConfigDesc->bmAttributes & USB_CONFIG_SELF_POWERED) @@ -3036,7 +3036,7 @@ DisplayConfigurationDescriptor ( OOPS(); } } - + if (ConfigDesc->bmAttributes & USB_CONFIG_REMOTE_WAKEUP) { if(gDoAnnotation) @@ -3044,7 +3044,7 @@ DisplayConfigurationDescriptor ( AppendTextBuffer(" -> Remote Wakeup\r\n"); } } - + if (ConfigDesc->bmAttributes & USB_CONFIG_RESERVED) { //@@TestCase A4.4 @@ -3366,10 +3366,10 @@ DisplayInterfaceDescriptor ( InterfaceDesc->bInterfaceProtocol); //This is basically the check for PC_PROTOCOL_UNDEFINED - if ((InterfaceDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || + if ((InterfaceDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || (InterfaceDesc->bInterfaceClass == USB_DEVICE_CLASS_AUDIO)) { - if(InterfaceDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) + if(InterfaceDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) { //@@TestCase A5.10 //@@WARNING @@ -3414,9 +3414,9 @@ DisplayEndpointDescriptor() VOID DisplayEndpointDescriptor ( - _In_ PUSB_ENDPOINT_DESCRIPTOR + _In_ PUSB_ENDPOINT_DESCRIPTOR EndpointDesc, - _In_opt_ PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR + _In_opt_ PUSB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR EpCompDesc, _In_opt_ PUSB_SUPERSPEEDPLUS_ISOCH_ENDPOINT_COMPANION_DESCRIPTOR SspIsochEpCompDesc, @@ -3599,7 +3599,7 @@ DisplayEndpointDescriptor ( } break; } - } + } else { AppendTextBuffer("\r\n"); @@ -3629,7 +3629,7 @@ DisplayEndpointDescriptor ( AppendTextBuffer("\r\n"); } break; - + case USB_ENDPOINT_TYPE_CONTROL: if (EndpointDesc->wMaxPacketSize != USB_ENDPOINT_SUPERSPEED_CONTROL_MAX_PACKET_SIZE) { @@ -3641,9 +3641,9 @@ DisplayEndpointDescriptor ( AppendTextBuffer("\r\n"); } break; - + case USB_ENDPOINT_TYPE_ISOCHRONOUS: - + if (EpCompDesc != NULL) { if (EpCompDesc->bMaxBurst > 0) @@ -3673,7 +3673,7 @@ DisplayEndpointDescriptor ( AppendTextBuffer("\r\n"); } break; - + case USB_ENDPOINT_TYPE_INTERRUPT: if (EpCompDesc != NULL) @@ -3707,7 +3707,7 @@ DisplayEndpointDescriptor ( break; } break; - + case UsbHighSpeed: hsMaxPacket = (PUSB_HIGH_SPEED_MAXPACKET)&EndpointDesc->wMaxPacketSize; @@ -3717,26 +3717,26 @@ DisplayEndpointDescriptor ( case USB_ENDPOINT_TYPE_INTERRUPT: switch (hsMaxPacket->HSmux) { case 0: - if ((hsMaxPacket->MaxPacket < 1) || (hsMaxPacket->MaxPacket >1024)) + if ((hsMaxPacket->MaxPacket < 1) || (hsMaxPacket->MaxPacket >1024)) { AppendTextBuffer("*!*ERROR: Invalid maximum packet size, should be between 1 and 1024\r\n"); } break; case 1: - if ((hsMaxPacket->MaxPacket < 513) || (hsMaxPacket->MaxPacket >1024)) + if ((hsMaxPacket->MaxPacket < 513) || (hsMaxPacket->MaxPacket >1024)) { AppendTextBuffer("*!*ERROR: Invalid maximum packet size, should be between 513 and 1024\r\n"); } break; case 2: - if ((hsMaxPacket->MaxPacket < 683) || (hsMaxPacket->MaxPacket >1024)) + if ((hsMaxPacket->MaxPacket < 683) || (hsMaxPacket->MaxPacket >1024)) { AppendTextBuffer("*!*ERROR: Invalid maximum packet size, should be between 683 and 1024\r\n"); } break; - + case 3: AppendTextBuffer("*!*ERROR: Bits 12-11 set to Reserved value in wMaxPacketSize\r\n"); break; @@ -3744,14 +3744,14 @@ DisplayEndpointDescriptor ( AppendTextBuffer(" = %d transactions per microframe, 0x%02X max bytes\r\n", hsMaxPacket->HSmux + 1, hsMaxPacket->MaxPacket); break; - + case USB_ENDPOINT_TYPE_BULK: case USB_ENDPOINT_TYPE_CONTROL: AppendTextBuffer(" = 0x%02X max bytes\r\n", hsMaxPacket->MaxPacket); break; } break; - + case UsbFullSpeed: // full speed AppendTextBuffer(" = 0x%02X bytes\r\n", @@ -3770,12 +3770,12 @@ DisplayEndpointDescriptor ( break; } } - else + else { AppendTextBuffer("\r\n"); } - if (EndpointDesc->wMaxPacketSize & 0xE000) + if (EndpointDesc->wMaxPacketSize & 0xE000) { //@@TestCase A6.4 //@@Priority 1 @@ -3885,7 +3885,7 @@ DisplayEndointCompanionDescriptor ( { AppendTextBuffer("*!*ERROR: Control/Interrupt SuperSpeed endpoints do not support streams\r\n"); } - else + else { AppendTextBuffer("\r\n"); } @@ -3927,7 +3927,7 @@ DisplayEndointCompanionDescriptor ( } else { - if (EpCompDesc->bMaxBurst != 0) + if (EpCompDesc->bMaxBurst != 0 && SspIsochEpCompDesc != NULL) { AppendTextBuffer(" = %d maximum number of packets within a service interval\r\n", (SspIsochEpCompDesc->dwBytesPerInterval*USB_ENDPOINT_SUPERSPEED_ISO_MAX_PACKET_SIZE) / @@ -3939,7 +3939,7 @@ DisplayEndointCompanionDescriptor ( { AppendTextBuffer("*!*ERROR: bmAttributes bits 7-2 should be 0\r\n"); } - else + else { AppendTextBuffer("\r\n"); } @@ -4081,7 +4081,7 @@ InitializePerDeviceSettings ( // (Update this in the descriptor parsing routines) dwConfigIndex = 0; - // Flags used in dispvid.c to display default Frame descriptor for MJPEG, + // Flags used in dispvid.c to display default Frame descriptor for MJPEG, // Uncompressed, Vendor and FrameBased Formats g_chMJPEGFrameDefault = 0; g_chUNCFrameDefault = 0; @@ -4096,9 +4096,9 @@ InitializePerDeviceSettings ( g_pStringDescs = NULL; g_descEnd = NULL; - // + // // The GetConfigDescriptor() function in enum.c does not always work - // If that fails, the Configuration descriptor will be NULL + // If that fails, the Configuration descriptor will be NULL // and we can only display the device descriptor // CurrentConfigDesc = NULL; @@ -4139,11 +4139,11 @@ IsUVCDevice ( PUCHAR descEnd = NULL; UINT uUVCversion = 0; - // + // // The GetConfigDescriptor() function in enum.c does not always work - // If that fails, the Configuration descriptor will be NULL + // If that fails, the Configuration descriptor will be NULL // and we can only display the device descriptor - // + // if (NULL == info) { return 0; @@ -4166,10 +4166,10 @@ IsUVCDevice ( while ((PUCHAR)commonDesc + sizeof(USB_COMMON_DESCRIPTOR) < descEnd && (PUCHAR)commonDesc + commonDesc->bLength <= descEnd) { - if ((commonDesc->bDescriptorType == CS_INTERFACE) && + if ((commonDesc->bDescriptorType == CS_INTERFACE) && (commonDesc->bLength > sizeof(VIDEO_CONTROL_HEADER_UNIT))) { - // Right type, size. Now check subtype + // Right type, size. Now check subtype PVIDEO_CONTROL_HEADER_UNIT pCSVC = NULL; pCSVC = (PVIDEO_CONTROL_HEADER_UNIT) commonDesc; if (VC_HEADER == pCSVC->bDescriptorSubtype) @@ -4203,11 +4203,11 @@ IsIADDevice ( PUCHAR descEnd = NULL; UINT uIADcount = 0; - // + // // The GetConfigDescriptor() function in enum.c does not always work - // If that fails, the Configuration descriptor will be NULL + // If that fails, the Configuration descriptor will be NULL // and we can only display the device descriptor - // + // if (NULL == info) { return 0; @@ -4538,7 +4538,7 @@ DisplayIADDescriptor ( if ((IADDesc->bFunctionClass == USB_DEVICE_CLASS_VIDEO)) { // USB Video Class - if(IADDesc->bFunctionProtocol == PC_PROTOCOL_UNDEFINED) + if(IADDesc->bFunctionProtocol == PC_PROTOCOL_UNDEFINED) { // correct protocol for UVC if(gDoAnnotation) @@ -4586,11 +4586,11 @@ GetConfigurationSize ( PUSBDEVICEINFO info ) { - PUSB_CONFIGURATION_DESCRIPTOR + PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc = (PUSB_CONFIGURATION_DESCRIPTOR)(info->ConfigDesc + 1); - PUSB_COMMON_DESCRIPTOR + PUSB_COMMON_DESCRIPTOR commonDesc = (PUSB_COMMON_DESCRIPTOR)ConfigDesc; - PUCHAR + PUCHAR descEnd = (PUCHAR)ConfigDesc + ConfigDesc->wTotalLength; UINT uCount = 0; @@ -4615,7 +4615,7 @@ GetInterfaceCount ( PUSBDEVICEINFO info ) { - // how do we handle composite devices? + // how do we handle composite devices? PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc = (PUSB_CONFIGURATION_DESCRIPTOR)(info->ConfigDesc + 1); PUSB_COMMON_DESCRIPTOR @@ -4695,7 +4695,7 @@ DisplayUSEnglishStringDescriptor ( { AppendTextBuffer("*!*ERROR: No String Descriptor for index %d!\r\n", Index); OOPS(); - } + } else { AppendTextBuffer("String Descriptor for index %d not available while device is in low power state.\r\n", Index); @@ -4760,7 +4760,7 @@ DisplayStringDescriptor ( } memset(pString, 0, 512); - if (StringDescs->StringDescriptor->bLength > sizeof(USHORT)) + if (StringDescs->StringDescriptor->bLength > sizeof(USHORT)) { nBytes = WideCharToMultiByte( CP_ACP, // CodePage @@ -4771,16 +4771,16 @@ DisplayStringDescriptor ( 512, NULL, // lpDefaultChar NULL); // pUsedDefaultChar - if (nBytes) + if (nBytes) { AppendTextBuffer("%s\"\r\n", pString); } - else + else { AppendTextBuffer("\"\r\n"); } } - else + else { // // This is NULL string which is invalid @@ -4797,7 +4797,7 @@ DisplayStringDescriptor ( { AppendTextBuffer("*!*ERROR: No String Descriptor for index %d!\r\n", Index); OOPS(); - } + } else { AppendTextBuffer("String Descriptor for index %d not available while device is in low power state.\r\n", Index); @@ -4834,7 +4834,7 @@ DisplayRemainingUnknownDescriptor( ) { ULONG i; - + for (i = Start; i < Stop; i++) { AppendTextBuffer("%02X ", @@ -4932,7 +4932,7 @@ GetStringFromList() PSTRINGLIST slList, - pointer to STRINGLIST used -ULONG ulNumElements, - +ULONG ulNumElements, - number of elements in that STRINGLIST calc before call with sizeof(slList) / sizeof(STRINGLIST), ULONG or ULONGLONG (if H264_SUPPORT is defined)ulFlag - - flag to look for PCHAR szDefault - string to return if no match @@ -4940,9 +4940,9 @@ PCHAR szDefault - string to return if no match Return a string associated with a value from a stringtable. example: - GetStringFromList(slPowerState, + GetStringFromList(slPowerState, sizeof(slPowerState) / sizeof(STRINGLIST), - pUPI->SystemState, + pUPI->SystemState, "Invalid Power State") *****************************************************************************/ @@ -4979,4 +4979,4 @@ GetStringFromList( return szDefault; } - + diff --git a/usb/usbview/uvcview.c b/usb/usbview/uvcview.c index f5600175..fb2e1f0c 100644 --- a/usb/usbview/uvcview.c +++ b/usb/usbview/uvcview.c @@ -200,7 +200,7 @@ AddItemInformationToFile( DWORD DisplayLastError( - _Inout_updates_bytes_(count) char *szString, + _Inout_updates_bytes_(count) char *szString, int count); VOID AddItemInformationToXmlView( @@ -221,7 +221,7 @@ HRESULT SaveAllInformationAsText(LPTSTR lpstrTextFileName, DWORD dwCreationDispo HRESULT SaveAllInformationAsXml(LPTSTR lpstrTextFileName , DWORD dwCreationDisposition); /***************************************************************************** -G L O B A L S +G L O B A L S *****************************************************************************/ BOOL gDoConfigDesc = TRUE; BOOL gDoAnnotation = TRUE; @@ -345,7 +345,7 @@ WinMain ( ProcessCommandLine() -Parses the command line and takes appropriate actions. Returns FALSE If there is no action to +Parses the command line and takes appropriate actions. Returns FALSE If there is no action to perform *****************************************************************************/ BOOL ProcessCommandLine() @@ -354,7 +354,7 @@ BOOL ProcessCommandLine() LPTSTR szArg = NULL; LPTSTR szAnsiArg= NULL; BOOL quietMode = FALSE; - + HRESULT hr = S_OK; DWORD dwCreationDisposition = CREATE_NEW; USBVIEW_SAVE_FILE_TYPE fileType = UsbViewNone; @@ -667,7 +667,7 @@ VOID DisplayMessage(DWORD dwResId, ...) } dwLen = FormatMessage( - FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER, + FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER, szFormat, dwResId, 0, @@ -749,7 +749,7 @@ VOID PrintString(LPTSTR lpszString) return; } - if (gbConsoleFile) + if (gbConsoleFile) { // Console has been redirected to a file, ex: `usbview /savexml:xx > test.txt`. We need to use WriteFile instead of // WriteConsole for text output. @@ -1042,7 +1042,7 @@ USBView_OnInitDialog ( ghEditWnd = GetDlgItem(hWnd, IDC_EDIT); -#ifdef H264_SUPPORT +#ifdef H264_SUPPORT // set the edit control to have a max text limit size SendMessage(ghEditWnd, EM_LIMITTEXT, 0 /* USE DEFAULT MAX*/, 0); #endif @@ -1101,7 +1101,7 @@ USBView_OnClose ( AddItemInformationToFile() -Saves the information about the current item to the list +Saves the information about the current item to the list *****************************************************************************/ VOID AddItemInformationToFile( @@ -1140,7 +1140,7 @@ SaveAllInformationAsText() Saves the entire USB tree as a text file *****************************************************************************/ -HRESULT +HRESULT SaveAllInformationAsText( LPTSTR lpstrTextFileName, DWORD dwCreationDisposition @@ -1154,7 +1154,7 @@ SaveAllInformationAsText( 0, NULL, dwCreationDisposition, - FILE_ATTRIBUTE_NORMAL, + FILE_ATTRIBUTE_NORMAL, NULL); if (hf == INVALID_HANDLE_VALUE) @@ -1702,10 +1702,10 @@ AboutDlgProc ( if (hItem != NULL) { - hr = StringCbPrintfA(TextBuffer, + hr = StringCbPrintfA(TextBuffer, sizeof(TextBuffer), - "USBView version: %d.%d", - USBVIEW_MAJOR_VERSION, + "USBView version: %d.%d", + USBVIEW_MAJOR_VERSION, USBVIEW_MINOR_VERSION); if (SUCCEEDED(hr)) { @@ -1717,10 +1717,10 @@ AboutDlgProc ( if (hItem != NULL) { - hr = StringCbPrintfA(TextBuffer, + hr = StringCbPrintfA(TextBuffer, sizeof(TextBuffer), - "USB Video Class Spec version: %d.%d", - UVC_SPEC_MAJOR_VERSION, + "USB Video Class Spec version: %d.%d", + UVC_SPEC_MAJOR_VERSION, UVC_SPEC_MINOR_VERSION); if (SUCCEEDED(hr)) { @@ -1735,7 +1735,7 @@ AboutDlgProc ( { case IDOK: case IDCANCEL: - + EndDialog (hwnd, 0); break; } @@ -1820,7 +1820,7 @@ AddLeaf ( tvins.item.iImage = giGoodSsDevice; tvins.item.iSelectedImage = giGoodSsDevice; break; - + case NoSsDeviceIcon: tvins.item.iImage = giNoSsDevice; tvins.item.iSelectedImage = giNoSsDevice; @@ -1886,7 +1886,7 @@ WalkTreeTopDown( } else { - // If there are no more siblings, we have reached the end of + // If there are no more siblings, we have reached the end of // list of child nodes. Call notify function if (lpfnTreeNotifyCallback != NULL) { @@ -1959,7 +1959,7 @@ SaveAllInformationAsXML() Saves the entire USB tree as an XML file *****************************************************************************/ -HRESULT +HRESULT SaveAllInformationAsXml( LPTSTR lpstrTextFileName, DWORD dwCreationDisposition @@ -2070,8 +2070,8 @@ DisplayLastError() DWORD DisplayLastError( - _Inout_updates_bytes_(count) char *szString, - int count) + _Inout_updates_bytes_(count) char *szString, + int count) { LPVOID lpMsgBuf; @@ -2079,9 +2079,9 @@ DisplayLastError( DWORD dwError = GetLastError(); // get the system message for this error code - if (FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | + if (FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwError, @@ -2122,8 +2122,8 @@ Oops memset(szBuf, 0, sizeof(szBuf)); // get the system message for this error code - if (FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | + if (FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwGLE, @@ -2132,14 +2132,14 @@ Oops 0, NULL)) { - StringCchPrintf(szBuf, sizeof(szBuf), - "File: %s, Line %d\r\nGetLastError 0x%x %u %s\n", + StringCchPrintf(szBuf, sizeof(szBuf), + "File: %s, Line %d\r\nGetLastError 0x%x %u %s\n", File, Line, dwGLE, dwGLE, lpMsgBuf); } else { - StringCchPrintf(szBuf, sizeof(szBuf), - "File: %s, Line %d\r\nGetLastError 0x%x %u\r\n", + StringCchPrintf(szBuf, sizeof(szBuf), + "File: %s, Line %d\r\nGetLastError 0x%x %u\r\n", File, Line, dwGLE, dwGLE); } OutputDebugString(szBuf); diff --git a/usb/usbview/xmlhelper.cpp b/usb/usbview/xmlhelper.cpp index fc58840e..f67c9587 100644 --- a/usb/usbview/xmlhelper.cpp +++ b/usb/usbview/xmlhelper.cpp @@ -27,7 +27,7 @@ Revision History: #include "h264.h" #include "xmlhelper.h" -// usbschema.hpp is autogenerated from schema during build PASS0 +// usbschema.hpp is autogenerated from schema during build PASS0 #include "usbschema.hpp" // Include code analysis suppressions @@ -56,7 +56,7 @@ Revision History: #define USB_GENERIC "USB GENERIC (UNKNOWN)" /***************************************************************************** - N A M E S P A C E S + N A M E S P A C E S *****************************************************************************/ using namespace System; @@ -148,7 +148,7 @@ void XmlAddPipeInformation( ULONG numPipes, UCHAR connectionSpeed); void XmlAddUsbDeviceDescriptor( - UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, + UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, PUSB_DEVICE_DESCRIPTOR usbDeviceDescriptor); void XmlAddConfigurationDescriptor( UsbConfigurationDescriptorType ^ confXmlDesc, @@ -176,7 +176,7 @@ bool XmlAddDeviceClassDetails( PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo); void XmlAddConnectionInfo( - NodeConnectionInfoExType ^xmlConnectionInfo, + NodeConnectionInfoExType ^xmlConnectionInfo, PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo, PSTRING_DESCRIPTOR_NODE stringDesc, @@ -223,13 +223,13 @@ UsbBillboardCapabilityDescriptorType ^ XmlGetBillboardCapabilityDescriptor( ); /***************************************************************************** - D E F I N I T I O N S + D E F I N I T I O N S *****************************************************************************/ /***************************************************************************** XmlNotifyEndOfNodeList - This function is called back by WalkTreeTopDown() function to notify us + This function is called back by WalkTreeTopDown() function to notify us that there are no more children to add for the current parent *****************************************************************************/ @@ -302,7 +302,7 @@ HRESULT XmlAddHostController(PSTR hcName, PUSBHOSTCONTROLLERINFO hcInfo) else { // Create a new array every time as Array.Resize does not seem to work in our case (CLI) - // We do this using ArrayList. + // We do this using ArrayList. ArrayList ^hcList = gcnew ArrayList; hcList->AddRange(gXmlView->UsbTree); hc = gcnew HostControllerType(); @@ -325,20 +325,31 @@ HRESULT XmlAddHostController(PSTR hcName, PUSBHOSTCONTROLLERINFO hcInfo) hc->DeviceName = PACHAR_TO_STRING(hcInfo->UsbDeviceProperties->DeviceDesc); hc->DeviceClass = PACHAR_TO_STRING(hcInfo->UsbDeviceProperties->DeviceClass); - if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_OHCI) == 0) + bool foundUsbProtocol = false; + if (hcInfo->UsbDeviceProperties->Service != NULL) { - hc->UsbProtocol = gcnew String(USB_1_1); + foundUsbProtocol = true; + + if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_OHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_1_1); + } + else if(_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_EHCI) == 0 || + _stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_UHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_2_0); + } + else if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_XHCI) == 0) + { + hc->UsbProtocol = gcnew String(USB_3_0); + } + else + { + foundUsbProtocol = false; + } } - else if(_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_EHCI) == 0 || - _stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_UHCI) == 0) - { - hc->UsbProtocol = gcnew String(USB_2_0); - } - else if (_stricmp(hcInfo->UsbDeviceProperties->Service, SERVICE_XHCI) == 0) - { - hc->UsbProtocol = gcnew String(USB_3_0); - } - else + + if (!foundUsbProtocol) { // If protocol lookup failed based on service name, try Controller flavor if(NULL != hcInfo->ControllerInfo) @@ -488,10 +499,10 @@ void XmlAddConnectionInfoV2(NodeConnectionInfoExV2Type ^ connectionXmlInfo, PUSB connectionXmlInfo->Usb200Supported = connectionInfo->SupportedUsbProtocols.Usb200? true:false; connectionXmlInfo->Usb300Supported = connectionInfo->SupportedUsbProtocols.Usb300? true:false; - connectionXmlInfo->DeviceIsOperatingAtSuperSpeedOrHigher = + connectionXmlInfo->DeviceIsOperatingAtSuperSpeedOrHigher = connectionInfo->Flags.DeviceIsOperatingAtSuperSpeedOrHigher; - connectionXmlInfo->DeviceIsSuperSpeedCapableOrHigher = + connectionXmlInfo->DeviceIsSuperSpeedCapableOrHigher = connectionInfo->Flags.DeviceIsSuperSpeedCapableOrHigher; connectionXmlInfo->DeviceIsOperatingAtSuperSpeedPlusOrHigher = @@ -499,7 +510,7 @@ void XmlAddConnectionInfoV2(NodeConnectionInfoExV2Type ^ connectionXmlInfo, PUSB connectionXmlInfo->DeviceIsSuperSpeedPlusCapableOrHigher = connectionInfo->Flags.DeviceIsSuperSpeedPlusCapableOrHigher; - + } return; } @@ -655,7 +666,7 @@ ExternalHubType ^ AddExternalHub(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try root hub first @@ -736,7 +747,7 @@ NoDeviceType ^ AddDisconnectedPort(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try RH first @@ -818,7 +829,7 @@ UsbDeviceType ^ AddUsbDevice(Object ^parent) boolean arrayCreated = false; // An external hub can be connected to a Root Hub or another External Hub - // We need to determine the type of the object. + // We need to determine the type of the object. // Try RH first @@ -937,9 +948,9 @@ void XmlAddIADDescriptor( iadDesc->bFunctionProtocol); // Protocol check - if (iadDesc->bFunctionClass == USB_DEVICE_CLASS_VIDEO) + if (iadDesc->bFunctionClass == USB_DEVICE_CLASS_VIDEO) { - if (iadDesc->bFunctionProtocol != PC_PROTOCOL_UNDEFINED) + if (iadDesc->bFunctionProtocol != PC_PROTOCOL_UNDEFINED) { iadXmlDesc->Protocol= gcnew String("WARNING: Protocol must be set to PC_PROTOCOL_UNDEFINED"); iadXmlDesc->Protocol+= " for this class but is set to: "; @@ -949,7 +960,7 @@ void XmlAddIADDescriptor( { iadXmlDesc->Protocol = gcnew String("PC_PROTOCOL_UNDEFINED protocol"); } - } + } if (iadDesc->iFunction) { @@ -1084,7 +1095,7 @@ UsbDeviceUnknownDescriptorType ^ XmlGetUnknownDescriptor( void XmlAddEndpointDescriptor( EndpointDescriptorType ^usbXmlEndpointDescriptor, PUSB_ENDPOINT_DESCRIPTOR endPointDescriptor, - UCHAR connectionSpeed + UCHAR connectionSpeed ) { EndpointDescriptorType ^ue = usbXmlEndpointDescriptor; @@ -1172,10 +1183,10 @@ void XmlAddEndpointDescriptor( } // Add validation - if (endPointDescriptor->wMaxPacketSize & 0xE000) + if (endPointDescriptor->wMaxPacketSize & 0xE000) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: wMaxPacketSize bits 15-13 should be 0"); - } else if (connectionSpeed==UsbHighSpeed) + } else if (connectionSpeed==UsbHighSpeed) { USHORT hsMux; @@ -1187,26 +1198,26 @@ void XmlAddEndpointDescriptor( case USB_ENDPOINT_TYPE_INTERRUPT: switch (hsMux) { case 0: - if ((maxBytes < 1) || (maxBytes > 1024)) + if ((maxBytes < 1) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 1 and 1024"); } break; case 1: - if ((maxBytes < 513) || (maxBytes > 1024)) + if ((maxBytes < 513) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 513 and 1024"); } break; case 2: - if ((maxBytes < 683) || (maxBytes > 1024)) + if ((maxBytes < 683) || (maxBytes > 1024)) { ue->EndpointPacketSizeValidation = gcnew String("ERROR: Invalid maximum packet size, should be between 683 and 1024"); } break; - + case 3: ue->EndpointPacketSizeValidation = gcnew String("ERROR: Bits 12-11 set to reserved value\r\n"); break; @@ -1264,7 +1275,7 @@ void XmlAddPipeInformation( This routine adds usb device descriptor *****************************************************************************/ void XmlAddUsbDeviceDescriptor( - UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, + UsbDeviceDescriptorType ^usbXmlDeviceDescriptor, PUSB_DEVICE_DESCRIPTOR usbDeviceDescriptor) { UsbDeviceDescriptorType ^ud = usbXmlDeviceDescriptor; @@ -1310,7 +1321,7 @@ void XmlAddConfigurationDescriptor( return; } - if(deviceInfo->ConnectionInfoV2 && + if(deviceInfo->ConnectionInfoV2 && (deviceInfo->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedOrHigher || deviceInfo->ConnectionInfoV2->Flags.DeviceIsOperatingAtSuperSpeedPlusOrHigher)) { @@ -1328,9 +1339,9 @@ void XmlAddConfigurationDescriptor( uCount = GetConfigurationSize(deviceInfo); - if (uCount != configDesc->wTotalLength) + if (uCount != configDesc->wTotalLength) { - confXmlDesc->ConfigDescError = gcnew String("ERROR: Invalid total configuration size " + + confXmlDesc->ConfigDescError = gcnew String("ERROR: Invalid total configuration size " + configDesc->wTotalLength + ", should be " + uCount); } @@ -1432,7 +1443,7 @@ UsbDeviceClassType ^ XmlGetDeviceClass(UCHAR bInterfaceClass, UCHAR bInterfaceSu case USB_DEVICE_CLASS_VENDOR_SPECIFIC: deviceClass = gcnew String("Vendor Specific Device"); break; - + case USB_DEVICE_CLASS_HUMAN_INTERFACE: deviceClass = gcnew String("HID Interface"); @@ -1547,7 +1558,7 @@ UsbDeviceClassType ^ XmlGetDeviceClass(UCHAR bInterfaceClass, UCHAR bInterfaceSu default: deviceClass = gcnew String("Interface Class unknown : "); - deviceClass += bInterfaceClass; + deviceClass += bInterfaceClass; break; } @@ -1588,15 +1599,15 @@ void XmlAddDeviceInterfaceDescriptor( // Update class and sub class ifXmlDesc->InterfaceDetails = XmlGetDeviceClass( - ifDesc->bInterfaceClass, + ifDesc->bInterfaceClass, ifDesc->bInterfaceSubClass, ifDesc->bInterfaceProtocol); //This is basically the check for PC_PROTOCOL_UNDEFINED - if ((ifDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || - (ifDesc->bInterfaceClass == USB_DEVICE_CLASS_AUDIO)) + if ((ifDesc->bInterfaceClass == USB_DEVICE_CLASS_VIDEO) || + (ifDesc->bInterfaceClass == USB_DEVICE_CLASS_AUDIO)) { - if (ifDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) + if (ifDesc->bInterfaceProtocol != PC_PROTOCOL_UNDEFINED) { ifXmlDesc->ProtocolError = gcnew String("WARNING: Protocol must be set to PC_PROTOCOL_UNDEFINED"); ifXmlDesc->ProtocolError += " for this class but is set to: "; @@ -2087,9 +2098,9 @@ String ^ XmlGetStringDescriptor(UCHAR index, PSTRING_DESCRIPTOR_NODE stringDesc, if ((foundDescriptor == false) && (foundNonEnglishDescriptor == false)) { // If no descriptor was found, return error message in field - desc = gcnew String("ERROR: No String descriptor for index " + + desc = gcnew String("ERROR: No String descriptor for index " + index); - } + } else if ((foundDescriptor == false) && (foundNonEnglishDescriptor == true) && (enOnly)) { desc = gcnew String("ERROR: The index " + index + " does not support English(US)"); @@ -2196,9 +2207,9 @@ bool XmlAddDeviceClassDetails( { deviceDetails->DeviceProtocol = gcnew String("Interface Association Descriptor protocol"); } - else + else { - deviceDetails->DeviceProtocolError = gcnew String("ERROR: device Protocol should be USB IAD Protocol " + + deviceDetails->DeviceProtocolError = gcnew String("ERROR: device Protocol should be USB IAD Protocol " + USB_IAD_PROTOCOL + " when IAD descriptor is used"); } @@ -2208,7 +2219,7 @@ bool XmlAddDeviceClassDetails( { deviceDetails->DeviceType = XmlGetDeviceClassString(connectionInfo->DeviceDescriptor.bDeviceClass); - if (connectionInfo->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_BILLBOARD && + if (connectionInfo->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_BILLBOARD && (connectionInfo->DeviceDescriptor.bDeviceSubClass != 0x0 || connectionInfo->DeviceDescriptor.bDeviceProtocol != 0x0)) { @@ -2233,7 +2244,7 @@ bool XmlAddDeviceClassDetails( } // Not an IAD device, so all subclass values are invalid - if (connectionInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && + if (connectionInfo->DeviceDescriptor.bDeviceSubClass > 0x00 && connectionInfo->DeviceDescriptor.bDeviceSubClass < 0xFF) { deviceDetails->SubclassTypeError = gcnew String("ERROR: bDeviceSubClass is invalid - " + @@ -2241,7 +2252,7 @@ bool XmlAddDeviceClassDetails( } // Not an IAD device, so all subclass values are invalid, check protocol - if (connectionInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && + if (connectionInfo->DeviceDescriptor.bDeviceProtocol > 0x00 && connectionInfo->DeviceDescriptor.bDeviceProtocol < 0xFF && tog==1) { deviceDetails->DeviceProtocolError = gcnew String("ERROR: bDeviceProtocol is invalid - " + @@ -2259,7 +2270,7 @@ bool XmlAddDeviceClassDetails( This routine adds connection information for the device *****************************************************************************/ void XmlAddConnectionInfo( - NodeConnectionInfoExType ^xmlConnectionInfo, + NodeConnectionInfoExType ^xmlConnectionInfo, PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfo, PUSBDEVICEINFO deviceInfo, PSTRING_DESCRIPTOR_NODE stringDesc, @@ -2281,7 +2292,7 @@ void XmlAddConnectionInfo( if (connectionInfo->DeviceDescriptor.iProduct) { - // Add EN version of string descriptor + // Add EN version of string descriptor nc->IProductStringDescEn = XmlGetStringDescriptor( connectionInfo->DeviceDescriptor.iProduct, @@ -2298,7 +2309,7 @@ void XmlAddConnectionInfo( // Check device descriptor length if (connectionInfo->DeviceDescriptor.bLength != DEVICE_DESCRIPTOR_LENGTH) { - nc->LengthError = gcnew String("ERROR: bLength " + + nc->LengthError = gcnew String("ERROR: bLength " + connectionInfo->DeviceDescriptor.bLength + " incorrect, should be " + DEVICE_DESCRIPTOR_LENGTH @@ -2306,7 +2317,7 @@ void XmlAddConnectionInfo( } // Check for device error - if ((connectionInfo->ConnectionStatus == DeviceFailedEnumeration) || + if ((connectionInfo->ConnectionStatus == DeviceFailedEnumeration) || (connectionInfo->ConnectionStatus == DeviceGeneralFailure)) { nc->DeviceError = gcnew String("ERROR: Device enumeration failure"); @@ -2447,7 +2458,7 @@ HRESULT XmlAddExternalHub(PSTR ehName, PUSBEXTERNALHUBINFO ehInfo) exHub->PortConnector = gcnew PortConnectorType(); XmlAddPortConnectorProps( - exHub->PortConnector, + exHub->PortConnector, ehInfo->PortConnectorProps ); } @@ -2518,16 +2529,16 @@ UsbBosDescriptorType ^ XmlGetBosDescriptor( commonDesc = (PUSB_COMMON_DESCRIPTOR) bosDesc; - while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR) bosDesc, - bosDesc->wTotalLength, - commonDesc, + while ((commonDesc = GetNextDescriptor((PUSB_COMMON_DESCRIPTOR) bosDesc, + bosDesc->wTotalLength, + commonDesc, -1)) != NULL) { switch (commonDesc->bDescriptorType) { case USB_DEVICE_CAPABILITY_DESCRIPTOR_TYPE: capDesc = (PUSB_DEVICE_CAPABILITY_DESCRIPTOR)commonDesc; - switch (capDesc->bDevCapabilityType) + switch (capDesc->bDevCapabilityType) { case USB_DEVICE_CAPABILITY_USB20_EXTENSION: usb20CapExtDescList->Add( @@ -2591,7 +2602,7 @@ UsbBosDescriptorType ^ XmlGetBosDescriptor( ); return bosXmlDesc; -} +} /***************************************************************************** @@ -2980,7 +2991,7 @@ HRESULT XmlAddUsbDevice(PSTR devName, PUSBDEVICEINFO deviceInfo) deviceInfo->DeviceInfoNode ); - // Add port connector + // Add port connector if (NULL != deviceInfo->PortConnectorProps) { usbDevice->PortConnector = gcnew PortConnectorType(); @@ -3049,7 +3060,7 @@ HRESULT XmlAddRootHub(PSTR rhName, PUSBROOTHUBINFO rhInfo) if (hcParent != nullptr) { RootHubType ^ rh = nullptr; - hcParent = (HostControllerType ^) parent; + hcParent = (HostControllerType ^) parent; hcParent->RootHub = gcnew RootHubType(); rh = hcParent->RootHub; @@ -3116,7 +3127,7 @@ VOID XmlSetVersion( InitXmlHelper() - Initialize XML helper + Initialize XML helper *****************************************************************************/ HRESULT InitXmlHelper() { @@ -3132,9 +3143,9 @@ HRESULT InitXmlHelper() (XmlGlobal::Instance())->ViewAll->UvcView->UsbTree = nullptr; XmlSetVersion( - UVC_SPEC_MAJOR_VERSION, - UVC_SPEC_MINOR_VERSION, - USBVIEW_MAJOR_VERSION, + UVC_SPEC_MAJOR_VERSION, + UVC_SPEC_MINOR_VERSION, + USBVIEW_MAJOR_VERSION, USBVIEW_MINOR_VERSION ); diff --git a/usb/wdf_osrfx2_lab/kmdf/exe/testapp.c b/usb/wdf_osrfx2_lab/kmdf/exe/testapp.c index fce915b5..b8de16e3 100644 --- a/usb/wdf_osrfx2_lab/kmdf/exe/testapp.c +++ b/usb/wdf_osrfx2_lab/kmdf/exe/testapp.c @@ -21,10 +21,10 @@ Environment: --*/ - + #include -_Analysis_mode_(_Analysis_code_type_user_code_) - +_Analysis_mode_(_Analysis_code_type_user_code_) + #include #include #include @@ -117,6 +117,7 @@ GetDevicePath( deviceInterfaceList = (PWSTR)malloc(deviceInterfaceListLength * sizeof(WCHAR)); if (deviceInterfaceList == NULL) { + bRet = FALSE; printf("Error allocating memory for device interface list.\n"); goto clean0; } @@ -157,7 +158,9 @@ clean0: return bRet; } - +_Check_return_ +_Ret_notnull_ +_Success_(return != INVALID_HANDLE_VALUE) HANDLE OpenDevice( _In_ BOOL Synchronous @@ -1201,10 +1204,9 @@ exit: } if (hWrite != INVALID_HANDLE_VALUE) { + _Analysis_assume_(hWrite != NULL); CloseHandle(hWrite); } return retValue; } - - diff --git a/usb/wdf_osrfx2_lab/umdf/exe/testapp.c b/usb/wdf_osrfx2_lab/umdf/exe/testapp.c index 4aecf4c7..48f49492 100644 --- a/usb/wdf_osrfx2_lab/umdf/exe/testapp.c +++ b/usb/wdf_osrfx2_lab/umdf/exe/testapp.c @@ -211,7 +211,9 @@ GetDevicePath( } - +_Check_return_ +_Ret_notnull_ +_Success_(return != INVALID_HANDLE_VALUE) HANDLE OpenDevice( _In_ BOOL Synchronous @@ -905,7 +907,7 @@ SendFileToDevice( { HANDLE deviceHandle; - struct + struct { USHORT delay; WCHAR buffer[MAX_PATH + 1]; @@ -934,14 +936,14 @@ SendFileToDevice( // Convert the file name from relative to absolute. // - bufferCch = GetFullPathName(FileName, + bufferCch = GetFullPathName(FileName, countof(playback.buffer), playback.buffer, NULL); if (bufferCch == 0) { - wprintf(L"Error getting full path name for %s - %d\n", + wprintf(L"Error getting full path name for %s - %d\n", FileName, GetLastError()); goto Error; @@ -1241,6 +1243,10 @@ Return Value: } pinBuf = malloc(G_ReadLen); + if (pinBuf == 0) { + retValue = 1; + goto exit; + } } if (G_fWrite) { @@ -1260,6 +1266,10 @@ Return Value: } poutBuf = malloc(G_WriteLen); + if (poutBuf == 0) { + retValue = 1; + goto exit; + } } for (i = 0; i < G_IterationCount; i++) { @@ -1349,12 +1359,9 @@ exit: } if (hWrite != INVALID_HANDLE_VALUE) { + _Analysis_assume_(hWrite != NULL); CloseHandle(hWrite); } return retValue; } - - - - diff --git a/usb/wdf_osrfx2_lab/umdf/step1/dllsup.cpp b/usb/wdf_osrfx2_lab/umdf/step1/dllsup.cpp index e8bad81b..bd681ac2 100644 --- a/usb/wdf_osrfx2_lab/umdf/step1/dllsup.cpp +++ b/usb/wdf_osrfx2_lab/umdf/step1/dllsup.cpp @@ -1,5 +1,5 @@ /*++ - + Copyright (C) Microsoft Corporation, All Rights Reserved. Module Name: @@ -8,24 +8,24 @@ Module Name: Abstract: - This module contains the implementation of the UMDF Skeleton Sample + This module contains the implementation of the UMDF Skeleton Sample Driver's entry point and its exported functions for providing COM support. This module can be copied without modification to a new UMDF driver. It - depends on some of the code in comsup.cpp & comsup.h to handle DLL + depends on some of the code in comsup.cpp & comsup.h to handle DLL registration and creating the first class factory. This module is dependent on the following defines: - MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing - tracing. For example the skeleton uses + MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing + tracing. For example the skeleton uses L"Microsoft\\UMDF\\Skeleton" - MYDRIVER_CLASS_ID - A GUID encoded in struct format used to - initialize the driver's ClassID. + MYDRIVER_CLASS_ID - A GUID encoded in struct format used to + initialize the driver's ClassID. These are defined in internal.h for the skeleton sample. If you choose - to use a different primary include file, you should ensure they are + to use a different primary include file, you should ensure they are defined there as well. Environment: @@ -50,10 +50,10 @@ DllMain( Routine Description: - This is the entry point and exit point for the I/O trace driver. This + This is the entry point and exit point for the I/O trace driver. This does very little as the I/O trace driver has minimal global data. - This method initializes tracing, and saves the module handle away in a + This method initializes tracing, and saves the module handle away in a global variable so that it can be referenced should the COM registration code (Dll[Un]RegisterServer) be called. @@ -72,7 +72,7 @@ DllMain( --*/ { UNREFERENCED_PARAMETER(ModuleHandle); - + if (DLL_PROCESS_ATTACH == Reason) { // @@ -93,6 +93,7 @@ DllMain( return TRUE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllCanUnloadNow( @@ -100,7 +101,7 @@ DllCanUnloadNow( ) /*++ - Routine Description: + Routine Description: Called by the COM runtime when determining whether or not this module can be unloaded. Our answer is always "no". @@ -118,18 +119,19 @@ DllCanUnloadNow( return S_FALSE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllGetClassObject( - _In_ REFCLSID ClassId, - _In_ REFIID InterfaceId, - _Outptr_ LPVOID *Interface + REFCLSID ClassId, + REFIID InterfaceId, + LPVOID *Interface ) /*++ Routine Description: - This routine is called by COM in order to instantiate the + This routine is called by COM in order to instantiate the skeleton driver callback object and do an initial query interface on it. This method only creates an instance of the driver's class factory, as this @@ -145,7 +147,7 @@ DllGetClassObject( Return Value: - S_OK if the function succeeds or error indicating the cause of the + S_OK if the function succeeds or error indicating the cause of the failure. --*/ @@ -157,9 +159,9 @@ DllGetClassObject( *Interface = NULL; // - // If the CLSID doesn't match that of our "coclass" (defined in the IDL - // file) then we can't create the object the caller wants. This may - // indicate that the COM registration is incorrect, and another CLSID + // If the CLSID doesn't match that of our "coclass" (defined in the IDL + // file) then we can't create the object the caller wants. This may + // indicate that the COM registration is incorrect, and another CLSID // is referencing this drvier. // @@ -180,19 +182,19 @@ DllGetClassObject( factory = new CClassFactory(); - if (NULL == factory) + if (NULL == factory) { hr = E_OUTOFMEMORY; } - // + // // Query the object we created for the interface the caller wants. After - // that we release the object. This will drive the reference count to + // that we release the object. This will drive the reference count to // 1 (if the QI succeeded an referenced the object) or 0 (if the QI failed). // In the later case the object is automatically deleted. // - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { hr = factory->QueryInterface(InterfaceId, Interface); factory->Release(); diff --git a/usb/wdf_osrfx2_lab/umdf/step2/dllsup.cpp b/usb/wdf_osrfx2_lab/umdf/step2/dllsup.cpp index e8bad81b..bd681ac2 100644 --- a/usb/wdf_osrfx2_lab/umdf/step2/dllsup.cpp +++ b/usb/wdf_osrfx2_lab/umdf/step2/dllsup.cpp @@ -1,5 +1,5 @@ /*++ - + Copyright (C) Microsoft Corporation, All Rights Reserved. Module Name: @@ -8,24 +8,24 @@ Module Name: Abstract: - This module contains the implementation of the UMDF Skeleton Sample + This module contains the implementation of the UMDF Skeleton Sample Driver's entry point and its exported functions for providing COM support. This module can be copied without modification to a new UMDF driver. It - depends on some of the code in comsup.cpp & comsup.h to handle DLL + depends on some of the code in comsup.cpp & comsup.h to handle DLL registration and creating the first class factory. This module is dependent on the following defines: - MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing - tracing. For example the skeleton uses + MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing + tracing. For example the skeleton uses L"Microsoft\\UMDF\\Skeleton" - MYDRIVER_CLASS_ID - A GUID encoded in struct format used to - initialize the driver's ClassID. + MYDRIVER_CLASS_ID - A GUID encoded in struct format used to + initialize the driver's ClassID. These are defined in internal.h for the skeleton sample. If you choose - to use a different primary include file, you should ensure they are + to use a different primary include file, you should ensure they are defined there as well. Environment: @@ -50,10 +50,10 @@ DllMain( Routine Description: - This is the entry point and exit point for the I/O trace driver. This + This is the entry point and exit point for the I/O trace driver. This does very little as the I/O trace driver has minimal global data. - This method initializes tracing, and saves the module handle away in a + This method initializes tracing, and saves the module handle away in a global variable so that it can be referenced should the COM registration code (Dll[Un]RegisterServer) be called. @@ -72,7 +72,7 @@ DllMain( --*/ { UNREFERENCED_PARAMETER(ModuleHandle); - + if (DLL_PROCESS_ATTACH == Reason) { // @@ -93,6 +93,7 @@ DllMain( return TRUE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllCanUnloadNow( @@ -100,7 +101,7 @@ DllCanUnloadNow( ) /*++ - Routine Description: + Routine Description: Called by the COM runtime when determining whether or not this module can be unloaded. Our answer is always "no". @@ -118,18 +119,19 @@ DllCanUnloadNow( return S_FALSE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllGetClassObject( - _In_ REFCLSID ClassId, - _In_ REFIID InterfaceId, - _Outptr_ LPVOID *Interface + REFCLSID ClassId, + REFIID InterfaceId, + LPVOID *Interface ) /*++ Routine Description: - This routine is called by COM in order to instantiate the + This routine is called by COM in order to instantiate the skeleton driver callback object and do an initial query interface on it. This method only creates an instance of the driver's class factory, as this @@ -145,7 +147,7 @@ DllGetClassObject( Return Value: - S_OK if the function succeeds or error indicating the cause of the + S_OK if the function succeeds or error indicating the cause of the failure. --*/ @@ -157,9 +159,9 @@ DllGetClassObject( *Interface = NULL; // - // If the CLSID doesn't match that of our "coclass" (defined in the IDL - // file) then we can't create the object the caller wants. This may - // indicate that the COM registration is incorrect, and another CLSID + // If the CLSID doesn't match that of our "coclass" (defined in the IDL + // file) then we can't create the object the caller wants. This may + // indicate that the COM registration is incorrect, and another CLSID // is referencing this drvier. // @@ -180,19 +182,19 @@ DllGetClassObject( factory = new CClassFactory(); - if (NULL == factory) + if (NULL == factory) { hr = E_OUTOFMEMORY; } - // + // // Query the object we created for the interface the caller wants. After - // that we release the object. This will drive the reference count to + // that we release the object. This will drive the reference count to // 1 (if the QI succeeded an referenced the object) or 0 (if the QI failed). // In the later case the object is automatically deleted. // - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { hr = factory->QueryInterface(InterfaceId, Interface); factory->Release(); diff --git a/usb/wdf_osrfx2_lab/umdf/step3/dllsup.cpp b/usb/wdf_osrfx2_lab/umdf/step3/dllsup.cpp index e8bad81b..bd681ac2 100644 --- a/usb/wdf_osrfx2_lab/umdf/step3/dllsup.cpp +++ b/usb/wdf_osrfx2_lab/umdf/step3/dllsup.cpp @@ -1,5 +1,5 @@ /*++ - + Copyright (C) Microsoft Corporation, All Rights Reserved. Module Name: @@ -8,24 +8,24 @@ Module Name: Abstract: - This module contains the implementation of the UMDF Skeleton Sample + This module contains the implementation of the UMDF Skeleton Sample Driver's entry point and its exported functions for providing COM support. This module can be copied without modification to a new UMDF driver. It - depends on some of the code in comsup.cpp & comsup.h to handle DLL + depends on some of the code in comsup.cpp & comsup.h to handle DLL registration and creating the first class factory. This module is dependent on the following defines: - MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing - tracing. For example the skeleton uses + MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing + tracing. For example the skeleton uses L"Microsoft\\UMDF\\Skeleton" - MYDRIVER_CLASS_ID - A GUID encoded in struct format used to - initialize the driver's ClassID. + MYDRIVER_CLASS_ID - A GUID encoded in struct format used to + initialize the driver's ClassID. These are defined in internal.h for the skeleton sample. If you choose - to use a different primary include file, you should ensure they are + to use a different primary include file, you should ensure they are defined there as well. Environment: @@ -50,10 +50,10 @@ DllMain( Routine Description: - This is the entry point and exit point for the I/O trace driver. This + This is the entry point and exit point for the I/O trace driver. This does very little as the I/O trace driver has minimal global data. - This method initializes tracing, and saves the module handle away in a + This method initializes tracing, and saves the module handle away in a global variable so that it can be referenced should the COM registration code (Dll[Un]RegisterServer) be called. @@ -72,7 +72,7 @@ DllMain( --*/ { UNREFERENCED_PARAMETER(ModuleHandle); - + if (DLL_PROCESS_ATTACH == Reason) { // @@ -93,6 +93,7 @@ DllMain( return TRUE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllCanUnloadNow( @@ -100,7 +101,7 @@ DllCanUnloadNow( ) /*++ - Routine Description: + Routine Description: Called by the COM runtime when determining whether or not this module can be unloaded. Our answer is always "no". @@ -118,18 +119,19 @@ DllCanUnloadNow( return S_FALSE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllGetClassObject( - _In_ REFCLSID ClassId, - _In_ REFIID InterfaceId, - _Outptr_ LPVOID *Interface + REFCLSID ClassId, + REFIID InterfaceId, + LPVOID *Interface ) /*++ Routine Description: - This routine is called by COM in order to instantiate the + This routine is called by COM in order to instantiate the skeleton driver callback object and do an initial query interface on it. This method only creates an instance of the driver's class factory, as this @@ -145,7 +147,7 @@ DllGetClassObject( Return Value: - S_OK if the function succeeds or error indicating the cause of the + S_OK if the function succeeds or error indicating the cause of the failure. --*/ @@ -157,9 +159,9 @@ DllGetClassObject( *Interface = NULL; // - // If the CLSID doesn't match that of our "coclass" (defined in the IDL - // file) then we can't create the object the caller wants. This may - // indicate that the COM registration is incorrect, and another CLSID + // If the CLSID doesn't match that of our "coclass" (defined in the IDL + // file) then we can't create the object the caller wants. This may + // indicate that the COM registration is incorrect, and another CLSID // is referencing this drvier. // @@ -180,19 +182,19 @@ DllGetClassObject( factory = new CClassFactory(); - if (NULL == factory) + if (NULL == factory) { hr = E_OUTOFMEMORY; } - // + // // Query the object we created for the interface the caller wants. After - // that we release the object. This will drive the reference count to + // that we release the object. This will drive the reference count to // 1 (if the QI succeeded an referenced the object) or 0 (if the QI failed). // In the later case the object is automatically deleted. // - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { hr = factory->QueryInterface(InterfaceId, Interface); factory->Release(); diff --git a/usb/wdf_osrfx2_lab/umdf/step4/dllsup.cpp b/usb/wdf_osrfx2_lab/umdf/step4/dllsup.cpp index e8bad81b..bd681ac2 100644 --- a/usb/wdf_osrfx2_lab/umdf/step4/dllsup.cpp +++ b/usb/wdf_osrfx2_lab/umdf/step4/dllsup.cpp @@ -1,5 +1,5 @@ /*++ - + Copyright (C) Microsoft Corporation, All Rights Reserved. Module Name: @@ -8,24 +8,24 @@ Module Name: Abstract: - This module contains the implementation of the UMDF Skeleton Sample + This module contains the implementation of the UMDF Skeleton Sample Driver's entry point and its exported functions for providing COM support. This module can be copied without modification to a new UMDF driver. It - depends on some of the code in comsup.cpp & comsup.h to handle DLL + depends on some of the code in comsup.cpp & comsup.h to handle DLL registration and creating the first class factory. This module is dependent on the following defines: - MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing - tracing. For example the skeleton uses + MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing + tracing. For example the skeleton uses L"Microsoft\\UMDF\\Skeleton" - MYDRIVER_CLASS_ID - A GUID encoded in struct format used to - initialize the driver's ClassID. + MYDRIVER_CLASS_ID - A GUID encoded in struct format used to + initialize the driver's ClassID. These are defined in internal.h for the skeleton sample. If you choose - to use a different primary include file, you should ensure they are + to use a different primary include file, you should ensure they are defined there as well. Environment: @@ -50,10 +50,10 @@ DllMain( Routine Description: - This is the entry point and exit point for the I/O trace driver. This + This is the entry point and exit point for the I/O trace driver. This does very little as the I/O trace driver has minimal global data. - This method initializes tracing, and saves the module handle away in a + This method initializes tracing, and saves the module handle away in a global variable so that it can be referenced should the COM registration code (Dll[Un]RegisterServer) be called. @@ -72,7 +72,7 @@ DllMain( --*/ { UNREFERENCED_PARAMETER(ModuleHandle); - + if (DLL_PROCESS_ATTACH == Reason) { // @@ -93,6 +93,7 @@ DllMain( return TRUE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllCanUnloadNow( @@ -100,7 +101,7 @@ DllCanUnloadNow( ) /*++ - Routine Description: + Routine Description: Called by the COM runtime when determining whether or not this module can be unloaded. Our answer is always "no". @@ -118,18 +119,19 @@ DllCanUnloadNow( return S_FALSE; } +_Use_decl_annotations_ HRESULT STDAPICALLTYPE DllGetClassObject( - _In_ REFCLSID ClassId, - _In_ REFIID InterfaceId, - _Outptr_ LPVOID *Interface + REFCLSID ClassId, + REFIID InterfaceId, + LPVOID *Interface ) /*++ Routine Description: - This routine is called by COM in order to instantiate the + This routine is called by COM in order to instantiate the skeleton driver callback object and do an initial query interface on it. This method only creates an instance of the driver's class factory, as this @@ -145,7 +147,7 @@ DllGetClassObject( Return Value: - S_OK if the function succeeds or error indicating the cause of the + S_OK if the function succeeds or error indicating the cause of the failure. --*/ @@ -157,9 +159,9 @@ DllGetClassObject( *Interface = NULL; // - // If the CLSID doesn't match that of our "coclass" (defined in the IDL - // file) then we can't create the object the caller wants. This may - // indicate that the COM registration is incorrect, and another CLSID + // If the CLSID doesn't match that of our "coclass" (defined in the IDL + // file) then we can't create the object the caller wants. This may + // indicate that the COM registration is incorrect, and another CLSID // is referencing this drvier. // @@ -180,19 +182,19 @@ DllGetClassObject( factory = new CClassFactory(); - if (NULL == factory) + if (NULL == factory) { hr = E_OUTOFMEMORY; } - // + // // Query the object we created for the interface the caller wants. After - // that we release the object. This will drive the reference count to + // that we release the object. This will drive the reference count to // 1 (if the QI succeeded an referenced the object) or 0 (if the QI failed). // In the later case the object is automatically deleted. // - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { hr = factory->QueryInterface(InterfaceId, Interface); factory->Release();