[ofw] Add Assert to debug BS while deleteding WDF device
Uri Habusha
urih at mellanox.co.il
Tue Nov 16 12:11:36 PST 2010
I got a BS while disabling the IPoIB driver, the reason for that is trying to delete WDF device that is invalid. I guess that the object already deleted but I'm not sure.
Is WmPowerD0Exit and WmPowerD0Entry functions are thread safe? In other words is only one instance of the function can be run in same time?
In order to catch the problem I added some ASSERT in the code and set the pointer to NULL after deleting the object.
Attached is the patch
Index: winmad/kernel/wm_driver.c
===================================================================
--- winmad/kernel/wm_driver.c (revision 6842)
+++ winmad/kernel/wm_driver.c (working copy)
@@ -41,7 +41,7 @@
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WM_IB_DEVICE, WmIbDeviceGetContext)
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WM_PROVIDER, WmProviderGetContext)
-WDFDEVICE ControlDevice;
+WDFDEVICE ControlDevice = NULL;
static LIST_ENTRY DevList;
static LIST_ENTRY ProvList;
static KGUARDED_MUTEX Lock;
@@ -195,11 +195,14 @@
WdfDeviceInitSetFileObjectConfig(pinit, &fileconfig, &attr);
WDF_OBJECT_ATTRIBUTES_INIT(&attr);
+ ASSERT(ControlDevice == NULL);
status = WdfDeviceCreate(&pinit, &attr, &ControlDevice);
if (!NT_SUCCESS(status)) {
goto err1;
}
+
+ ASSERT(ControlDevice != NULL);
status = WdfDeviceCreateSymbolicLink(ControlDevice, &symlink);
if (!NT_SUCCESS(status)) {
goto err2;
@@ -220,6 +223,7 @@
err2:
WdfObjectDelete(ControlDevice);
+ ControlDevice = NULL;
return;
err1:
WdfDeviceInitFree(pinit);
@@ -340,14 +344,12 @@
WM_REGISTRATION *reg;
LIST_ENTRY *entry;
BOOLEAN destroy;
- WDFDEVICE ctrldev;
pdev = WmIbDeviceGetContext(Device);
KeAcquireGuardedMutex(&Lock);
RemoveEntryList(&pdev->Entry);
destroy = IsListEmpty(&DevList);
- ctrldev = ControlDevice;
for (entry = ProvList.Flink; entry != &ProvList; entry = entry->Flink) {
prov = CONTAINING_RECORD(entry, WM_PROVIDER, Entry);
@@ -365,7 +367,8 @@
}
if (destroy) {
- WdfObjectDelete(ctrldev);
+ ASSERT(ControlDevice != NULL);
+ WdfObjectDelete(ControlDevice);
}
return STATUS_SUCCESS;
Index: winmad/kernel/wm_provider.c
===================================================================
--- winmad/kernel/wm_provider.c (revision 6842)
+++ winmad/kernel/wm_provider.c (working copy)
@@ -64,6 +64,8 @@
pProvider->Exclusive = 0;
KeInitializeEvent(&pProvider->ExclusiveEvent, SynchronizationEvent, FALSE);
+ ASSERT(ControlDevice != NULL);
+
WDF_IO_QUEUE_CONFIG_INIT(&config, WdfIoQueueDispatchManual);
status = WdfIoQueueCreate(ControlDevice, &config,
WDF_NO_OBJECT_ATTRIBUTES, &pProvider->ReadQueue);
Index: winverbs/kernel/wv_cq.c
===================================================================
--- winverbs/kernel/wv_cq.c (revision 6842)
+++ winverbs/kernel/wv_cq.c (working copy)
@@ -97,6 +97,8 @@
cq->Ref = 1;
KeInitializeEvent(&cq->Event, NotificationEvent, FALSE);
+ ASSERT(ControlDevice != NULL);
+
WDF_IO_QUEUE_CONFIG_INIT(&config, WdfIoQueueDispatchManual);
status = WdfIoQueueCreate(ControlDevice, &config,
WDF_NO_OBJECT_ATTRIBUTES, &cq->Queue);
Index: winverbs/kernel/wv_device.c
===================================================================
--- winverbs/kernel/wv_device.c (revision 6842)
+++ winverbs/kernel/wv_device.c (working copy)
@@ -216,6 +216,8 @@
return STATUS_NO_MEMORY;
}
+ ASSERT(ControlDevice != NULL);
+
WDF_IO_QUEUE_CONFIG_INIT(&config, WdfIoQueueDispatchManual);
for (i = 0; i < pDevice->PortCount; i++) {
pDevice->pPorts[i].Flags = 0;
Index: winverbs/kernel/wv_driver.c
===================================================================
--- winverbs/kernel/wv_driver.c (revision 6842)
+++ winverbs/kernel/wv_driver.c (working copy)
@@ -48,7 +48,7 @@
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WV_RDMA_DEVICE, WvRdmaDeviceGetContext)
-WDFDEVICE ControlDevice;
+WDFDEVICE ControlDevice = NULL;
static LIST_ENTRY DevList;
static LIST_ENTRY ProvList;
static KGUARDED_MUTEX Lock;
@@ -565,6 +565,8 @@
ifc.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
ifc.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceReferenceNoOp;
+ ASSERT(ControlDevice != NULL);
+
ifc.WdfDevice = (ULONG_PTR)ControlDevice;
ifc.WdmDevice = WdfDeviceWdmGetDeviceObject(ControlDevice);
@@ -608,12 +610,16 @@
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attr, WV_PROVIDER);
WdfDeviceInitSetFileObjectConfig(pinit, &fileconfig, &attr);
+ ASSERT(ControlDevice == NULL);
+
WDF_OBJECT_ATTRIBUTES_INIT(&attr);
status = WdfDeviceCreate(&pinit, &attr, &ControlDevice);
if (!NT_SUCCESS(status)) {
goto err1;
}
+ ASSERT(ControlDevice != NULL);
+
status = WdfDeviceCreateSymbolicLink(ControlDevice, &symlink);
if (!NT_SUCCESS(status)) {
goto err2;
@@ -633,6 +639,7 @@
err2:
WdfObjectDelete(ControlDevice);
+ ControlDevice = NULL;
return;
err1:
WdfDeviceInitFree(pinit);
@@ -723,7 +730,6 @@
KeAcquireGuardedMutex(&Lock);
RemoveEntryList(&pdev->Entry);
destroy = IsListEmpty(&DevList);
- ctrldev = ControlDevice;
for (entry = ProvList.Flink; entry != &ProvList; entry = entry->Flink) {
prov = CONTAINING_RECORD(entry, WV_PROVIDER, Entry);
@@ -744,7 +750,10 @@
IbCmInterface.InterfaceHeader.InterfaceDereference(IbCmInterface.
InterfaceHeader.Context);
}
- WdfObjectDelete(ctrldev);
+
+ ASSERT(ControlDevice !+ NULL);
+ WdfObjectDelete(ControlDevice);
+ ControlDevice = NULL;
}
}
Index: winverbs/kernel/wv_ep.c
===================================================================
--- winverbs/kernel/wv_ep.c (revision 6842)
+++ winverbs/kernel/wv_ep.c (working copy)
@@ -101,6 +101,8 @@
KeInitializeEvent(&ep->Event, NotificationEvent, FALSE);
InitializeListHead(&ep->Entry);
+ ASSERT(ControlDevice != NULL);
+
WDF_IO_QUEUE_CONFIG_INIT(&config, WdfIoQueueDispatchManual);
status = WdfIoQueueCreate(ControlDevice, &config,
WDF_NO_OBJECT_ATTRIBUTES, &ep->Queue);
Index: winverbs/kernel/wv_srq.c
===================================================================
--- winverbs/kernel/wv_srq.c (revision 6842)
+++ winverbs/kernel/wv_srq.c (working copy)
@@ -109,6 +109,8 @@
srq->Ref = 1;
KeInitializeEvent(&srq->Event, NotificationEvent, FALSE);
+ ASSERT(ControlDevice != NULL);
+
WDF_IO_QUEUE_CONFIG_INIT(&config, WdfIoQueueDispatchManual);
status = WdfIoQueueCreate(ControlDevice, &config,
WDF_NO_OBJECT_ATTRIBUTES, &srq->Queue);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20101116/46bc2812/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add_assert.patch
Type: application/octet-stream
Size: 6191 bytes
Desc: add_assert.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20101116/46bc2812/attachment.obj>
More information about the ofw
mailing list