summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Mao <[email protected]>2017-03-13 15:43:02 -0700
committerWei Mao <[email protected]>2017-03-13 15:43:02 -0700
commit49bcea929f7eb4a417de16abc8be5d2d172181b7 (patch)
tree1100d2317d0a15ede65459835c4fb391b00fcf8f
parent6f54e0945a4deffb6d129a79374f8788769ab090 (diff)
[usb/kmdf_fx2] Fix Code Analysis Warnings
-rw-r--r--usb/kmdf_fx2/driver/driver.c9
-rw-r--r--usb/kmdf_fx2/driver/ioctl.c58
-rw-r--r--usb/kmdf_fx2/exe/testapp.c13
3 files changed, 47 insertions, 33 deletions
diff --git a/usb/kmdf_fx2/driver/driver.c b/usb/kmdf_fx2/driver/driver.c
index 44939a3b..18905851 100644
--- a/usb/kmdf_fx2/driver/driver.c
+++ b/usb/kmdf_fx2/driver/driver.c
@@ -132,7 +132,7 @@ Return Value:
//
// Register with ETW (unified tracing)
- //
+ //
EventRegisterOSRUSBFX2();
//
@@ -207,6 +207,11 @@ Return Value:
--*/
{
+ //
+ // EvtCleanupCallback for WDFDRIVER is always called at PASSIVE_LEVEL
+ //
+ _Analysis_assume_(KeGetCurrentIrql() == PASSIVE_LEVEL);
+
PAGED_CODE ();
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
@@ -215,7 +220,7 @@ Return Value:
WPP_CLEANUP( WdfDriverWdmGetDriverObject( (WDFDRIVER)Driver ));
UNREFERENCED_PARAMETER(Driver); // For the case when WPP is not being used.
-
+
EventUnregisterOSRUSBFX2();
}
diff --git a/usb/kmdf_fx2/driver/ioctl.c b/usb/kmdf_fx2/driver/ioctl.c
index 0f29dc8c..2cb4fcb1 100644
--- a/usb/kmdf_fx2/driver/ioctl.c
+++ b/usb/kmdf_fx2/driver/ioctl.c
@@ -43,7 +43,7 @@ OsrFxEvtIoDeviceControl(
_In_ WDFREQUEST Request,
_In_ size_t OutputBufferLength,
_In_ size_t InputBufferLength,
- _In_ ULONG IoControlCode
+ _In_ ULONG IoControlCode
)
/*++
@@ -83,6 +83,12 @@ Return Value:
UNREFERENCED_PARAMETER(InputBufferLength);
UNREFERENCED_PARAMETER(OutputBufferLength);
+ //
+ // 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();
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_IOCTL, "--> OsrFxEvtIoDeviceControl\n");
@@ -384,9 +390,9 @@ StopAllPipes(
)
{
WdfIoTargetStop(WdfUsbTargetPipeGetIoTarget(DeviceContext->InterruptPipe),
- WdfIoTargetCancelSentIo);
+ WdfIoTargetCancelSentIo);
WdfIoTargetStop(WdfUsbTargetPipeGetIoTarget(DeviceContext->BulkReadPipe),
- WdfIoTargetCancelSentIo);
+ WdfIoTargetCancelSentIo);
WdfIoTargetStop(WdfUsbTargetPipeGetIoTarget(DeviceContext->BulkWritePipe),
WdfIoTargetCancelSentIo);
}
@@ -440,9 +446,9 @@ Return Value:
{
PDEVICE_CONTEXT pDeviceContext;
NTSTATUS status;
-
+
PAGED_CODE();
-
+
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_IOCTL, "--> ResetDevice\n");
pDeviceContext = GetDeviceContext(Device);
@@ -457,17 +463,17 @@ Return Value:
}
StopAllPipes(pDeviceContext);
-
+
status = WdfUsbTargetDeviceResetPortSynchronously(pDeviceContext->UsbDevice);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL, "ResetDevice failed - 0x%x\n", status);
}
-
+
status = StartAllPipes(pDeviceContext);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL, "Failed to start all pipes - 0x%x\n", status);
}
-
+
WdfWaitLockRelease(pDeviceContext->ResetDeviceWaitLock);
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_IOCTL, "<-- ResetDevice\n");
@@ -475,7 +481,7 @@ Return Value:
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
ReenumerateDevice(
_In_ PDEVICE_CONTEXT DevContext
)
@@ -499,7 +505,7 @@ Return Value:
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
WDF_REQUEST_SEND_OPTIONS sendOptions;
GUID activity;
-
+
PAGED_CODE();
TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL,"--> ReenumerateDevice\n");
@@ -513,7 +519,7 @@ Return Value:
&sendOptions,
DEFAULT_CONTROL_TRANSFER_TIMEOUT
);
-
+
WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
BmRequestHostToDevice,
BmRequestToDevice,
@@ -546,15 +552,15 @@ Return Value:
DevContext->DeviceName,
DevContext->Location,
status);
-
+
return status;
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
GetBarGraphState(
- _In_ PDEVICE_CONTEXT DevContext,
+ _In_ PDEVICE_CONTEXT DevContext,
_Out_ PBAR_GRAPH_STATE BarGraphState
)
/*++
@@ -638,9 +644,9 @@ Return Value:
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
SetBarGraphState(
- _In_ PDEVICE_CONTEXT DevContext,
+ _In_ PDEVICE_CONTEXT DevContext,
_In_ PBAR_GRAPH_STATE BarGraphState
)
/*++
@@ -718,9 +724,9 @@ Return Value:
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
GetSevenSegmentState(
- _In_ PDEVICE_CONTEXT DevContext,
+ _In_ PDEVICE_CONTEXT DevContext,
_Out_ PUCHAR SevenSegment
)
/*++
@@ -752,7 +758,7 @@ Return Value:
NTSTATUS status;
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
WDF_REQUEST_SEND_OPTIONS sendOptions;
-
+
WDF_MEMORY_DESCRIPTOR memDesc;
ULONG bytesTransferred;
@@ -811,9 +817,9 @@ Return Value:
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
SetSevenSegmentState(
- _In_ PDEVICE_CONTEXT DevContext,
+ _In_ PDEVICE_CONTEXT DevContext,
_In_ PUCHAR SevenSegment
)
/*++
@@ -892,9 +898,9 @@ Return Value:
}
_IRQL_requires_(PASSIVE_LEVEL)
-NTSTATUS
+NTSTATUS
GetSwitchState(
- _In_ PDEVICE_CONTEXT DevContext,
+ _In_ PDEVICE_CONTEXT DevContext,
_In_ PSWITCH_STATE SwitchState
)
/*++
@@ -1034,11 +1040,11 @@ Return Value:
}
//
- // Complete the request. If we failed to get the output buffer then
+ // Complete the request. If we failed to get the output buffer then
// complete with that status. Otherwise complete with the status from the reader.
//
- WdfRequestCompleteWithInformation(request,
- NT_SUCCESS(status) ? ReaderStatus : status,
+ WdfRequestCompleteWithInformation(request,
+ NT_SUCCESS(status) ? ReaderStatus : status,
bytesReturned);
status = STATUS_SUCCESS;
diff --git a/usb/kmdf_fx2/exe/testapp.c b/usb/kmdf_fx2/exe/testapp.c
index fce915b5..43b6c7a2 100644
--- a/usb/kmdf_fx2/exe/testapp.c
+++ b/usb/kmdf_fx2/exe/testapp.c
@@ -21,10 +21,10 @@ Environment:
--*/
-
+
#include <DriverSpecs.h>
-_Analysis_mode_(_Analysis_code_type_user_code_)
-
+_Analysis_mode_(_Analysis_code_type_user_code_)
+
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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;
}
@@ -158,6 +159,9 @@ clean0:
}
+_Check_return_
+_Ret_notnull_
+_Success_(return != INVALID_HANDLE_VALUE)
HANDLE
OpenDevice(
_In_ BOOL Synchronous
@@ -1201,10 +1205,9 @@ exit:
}
if (hWrite != INVALID_HANDLE_VALUE) {
+ _Analysis_assume_(hWrite != NULL);
CloseHandle(hWrite);
}
return retValue;
}
-
-