winmad: fix crash and handle mads > 256 correctly
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 24 Feb 2009 23:04:49 +0000 (23:04 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 24 Feb 2009 23:04:49 +0000 (23:04 +0000)
Fix crash if driver is loaded, but does not go active (power D0) before being unloaded.  Also handle mads > 256 bytes by checking against STATUS_SUCCESS, rather than for a successful status.  STATUS_MORE_ENTRIES is a successful status, but not what we're interested in.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1983 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/winmad/kernel/wm_driver.c
core/winmad/kernel/wm_provider.c
core/winmad/user/SOURCES

index 8ac92b6..52245ab 100644 (file)
@@ -46,9 +46,6 @@ static LIST_ENTRY             DevList;
 static LIST_ENTRY              ProvList;\r
 static KGUARDED_MUTEX  Lock;\r
 \r
-static EVT_WDF_DRIVER_DEVICE_ADD                       WmIbDeviceAdd;\r
-static EVT_WDF_OBJECT_CONTEXT_CLEANUP          WmIbDeviceCleanup;\r
-static EVT_WDF_DEVICE_D0_ENTRY                         WmPowerD0Entry;\r
 static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL      WmIoDeviceControl;\r
 static EVT_WDF_IO_QUEUE_IO_READ                                WmIoRead;\r
 static EVT_WDF_IO_QUEUE_IO_WRITE                       WmIoWrite;\r
@@ -296,6 +293,10 @@ static NTSTATUS WmPowerD0Entry(WDFDEVICE Device, WDF_POWER_DEVICE_STATE Previous
        NTSTATUS                status;\r
 \r
        dev = WmIbDeviceGetContext(Device);\r
+       RtlZeroMemory(dev, sizeof *dev);\r
+       dev->Ref = 1;\r
+       KeInitializeEvent(&dev->Event, NotificationEvent, FALSE);\r
+\r
        status = WdfFdoQueryForInterface(Device, &GUID_RDMA_INTERFACE_VERBS,\r
                                                                         (PINTERFACE) &dev->VerbsInterface,\r
                                                                         sizeof(dev->VerbsInterface), VerbsVersion(2, 0),\r
@@ -332,37 +333,7 @@ static NTSTATUS WmPowerD0Entry(WDFDEVICE Device, WDF_POWER_DEVICE_STATE Previous
        return STATUS_SUCCESS;\r
 }\r
 \r
-static NTSTATUS WmIbDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)\r
-{\r
-       WDF_OBJECT_ATTRIBUTES                   attr;\r
-       WDF_PNPPOWER_EVENT_CALLBACKS    power;\r
-       WDFDEVICE                                               dev;\r
-       WM_IB_DEVICE                                    *pdev;\r
-       NTSTATUS                                                status;\r
-\r
-       WdfFdoInitSetFilter(DeviceInit);\r
-\r
-       WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attr, WM_IB_DEVICE);\r
-       attr.EvtCleanupCallback = WmIbDeviceCleanup;\r
-\r
-       WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&power);\r
-       power.EvtDeviceD0Entry = WmPowerD0Entry;\r
-       WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &power);\r
-\r
-       status = WdfDeviceCreate(&DeviceInit, &attr, &dev);\r
-       if (!NT_SUCCESS(status)) {\r
-               return status;\r
-       }\r
-\r
-       pdev = WmIbDeviceGetContext(dev);\r
-       RtlZeroMemory(pdev, sizeof *pdev);\r
-       pdev->Ref = 1;\r
-       KeInitializeEvent(&pdev->Event, NotificationEvent, FALSE);\r
-\r
-       return STATUS_SUCCESS;\r
-}\r
-\r
-static VOID WmIbDeviceCleanup(WDFDEVICE Device)\r
+static NTSTATUS WmPowerD0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)\r
 {\r
        WM_PROVIDER                     *prov;\r
        WM_IB_DEVICE            *pdev;\r
@@ -371,7 +342,7 @@ static VOID WmIbDeviceCleanup(WDFDEVICE Device)
        BOOLEAN                         destroy;\r
        WDFDEVICE                       ctrldev;\r
 \r
-       pdev = (WmIbDeviceGetContext(Device));\r
+       pdev = WmIbDeviceGetContext(Device);\r
 \r
        KeAcquireGuardedMutex(&Lock);\r
        RemoveEntryList(&pdev->Entry);\r
@@ -396,6 +367,31 @@ static VOID WmIbDeviceCleanup(WDFDEVICE Device)
        if (destroy) {\r
                WdfObjectDelete(ctrldev);\r
        }\r
+\r
+       return STATUS_SUCCESS;\r
+}\r
+\r
+static NTSTATUS WmIbDeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)\r
+{\r
+       WDF_OBJECT_ATTRIBUTES                   attr;\r
+       WDF_PNPPOWER_EVENT_CALLBACKS    power;\r
+       WDFDEVICE                                               dev;\r
+       NTSTATUS                                                status;\r
+\r
+       WdfFdoInitSetFilter(DeviceInit);\r
+\r
+       WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attr, WM_IB_DEVICE);\r
+       WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&power);\r
+       power.EvtDeviceD0Entry = WmPowerD0Entry;\r
+       power.EvtDeviceD0Exit = WmPowerD0Exit;\r
+       WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &power);\r
+\r
+       status = WdfDeviceCreate(&DeviceInit, &attr, &dev);\r
+       if (!NT_SUCCESS(status)) {\r
+               return status;\r
+       }\r
+\r
+       return STATUS_SUCCESS;\r
 }\r
 \r
 NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)\r
index 7efdba3..2970c88 100644 (file)
@@ -277,7 +277,7 @@ void WmProviderRead(WM_PROVIDER *pProvider, WDFREQUEST Request)
 \r
        len = outlen;\r
        status = WmCopyRead(pProvider, wmad, pProvider->MadHead, &len);\r
-       if (NT_SUCCESS(status)) {\r
+       if (status == STATUS_SUCCESS) {\r
                reg = (WM_REGISTRATION *) pProvider->MadHead->send_context1;\r
                reg->pDevice->IbInterface.put_mad(WmRemoveMad(pProvider));\r
        }\r
@@ -389,7 +389,7 @@ void WmReceiveHandler(ib_mad_svc_handle_t hService, void *Context,
        }\r
 \r
        status = WmCopyRead(prov, wmad, pMad, &len);\r
-       if (NT_SUCCESS(status)) {\r
+       if (status == STATUS_SUCCESS) {\r
                reg = (WM_REGISTRATION *) pMad->send_context1;\r
                reg->pDevice->IbInterface.put_mad(pMad);\r
        } else {\r
index f66b99c..7d3d7c5 100644 (file)
@@ -14,12 +14,9 @@ DLLDEF = $(OBJ_PATH)\$O\wm_exports.def
 !endif\r
 \r
 DLLENTRY = DllMain\r
-USE_MSVCRT=1\r
+USE_NTDLL = 1\r
 \r
-SOURCES = \\r
-       winmad.rc               \\r
-       wm_main.cpp             \\r
-       wm_provider.cpp\r
+SOURCES = winmad.rc    wm_main.cpp wm_provider.cpp\r
 \r
 INCLUDES = ..;..\..\..\inc;..\..\..\inc\user;\r
 \r