[ros-diffs] [cgutman] 54816: [NDISUIO] - Fix a race condition during adapter context destruction - Add missing IRP completion in IRP_MJ_READ and IRP_MJ_WRITE handlers - Create an adapter context in response to...

cgutman at svn.reactos.org cgutman at svn.reactos.org
Tue Jan 3 16:08:27 UTC 2012


Author: cgutman
Date: Tue Jan  3 16:08:24 2012
New Revision: 54816

URL: http://svn.reactos.org/svn/reactos?rev=54816&view=rev
Log:
[NDISUIO]
- Fix a race condition during adapter context destruction
- Add missing IRP completion in IRP_MJ_READ and IRP_MJ_WRITE handlers
- Create an adapter context in response to PnP events

Modified:
    branches/wlan-bringup/drivers/network/ndisuio/ioctl.c
    branches/wlan-bringup/drivers/network/ndisuio/protocol.c
    branches/wlan-bringup/drivers/network/ndisuio/readwrite.c

Modified: branches/wlan-bringup/drivers/network/ndisuio/ioctl.c
URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/ndisuio/ioctl.c?rev=54816&r1=54815&r2=54816&view=diff
==============================================================================
--- branches/wlan-bringup/drivers/network/ndisuio/ioctl.c [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/ndisuio/ioctl.c [iso-8859-1] Tue Jan  3 16:08:24 2012
@@ -126,6 +126,7 @@
     NTSTATUS Status;
     PNDISUIO_ADAPTER_CONTEXT AdapterContext;
     PNDISUIO_OPEN_ENTRY OpenEntry;
+    KIRQL OldIrql;
 
     NameLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
     if (NameLength != 0)
@@ -135,16 +136,17 @@
 
         /* Check if this already has a context */
         AdapterContext = FindAdapterContextByName(&DeviceName);
-        if (AdapterContext == NULL)
-        {
-            /* Create a new context */
-            Status = BindAdapterByName(&DeviceName, &AdapterContext);
+        if (AdapterContext != NULL)
+        {
+            /* Reference the adapter context */
+            KeAcquireSpinLock(&AdapterContext->Spinlock, &OldIrql);
+            ReferenceAdapterContext(AdapterContext);
+            Status = STATUS_SUCCESS;
         }
         else
         {
-            /* Reference the existing context */
-            ReferenceAdapterContext(AdapterContext, FALSE);
-            Status = STATUS_SUCCESS;
+            /* Invalid device name */
+            Status = STATUS_INVALID_PARAMETER;
         }
 
         /* Check that the bind succeeded */
@@ -161,24 +163,25 @@
                 FileObject->FsContext2 = OpenEntry;
 
                 /* Add it to the adapter's list */
-                ExInterlockedInsertTailList(&AdapterContext->OpenEntryList,
-                                            &OpenEntry->ListEntry,
-                                            &AdapterContext->Spinlock);
+                InsertTailList(&AdapterContext->OpenEntryList,
+                               &OpenEntry->ListEntry);
 
                 /* Success */
+                KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
                 Status = STATUS_SUCCESS;
             }
             else
             {
                 /* Remove the reference we added */
+                KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
                 DereferenceAdapterContext(AdapterContext, NULL);
-
                 Status = STATUS_NO_MEMORY;
             }
         }
     }
     else
     {
+        /* Invalid device name */
         Status = STATUS_INVALID_PARAMETER;
     }
     

Modified: branches/wlan-bringup/drivers/network/ndisuio/protocol.c
URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/ndisuio/protocol.c?rev=54816&r1=54815&r2=54816&view=diff
==============================================================================
--- branches/wlan-bringup/drivers/network/ndisuio/protocol.c [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/ndisuio/protocol.c [iso-8859-1] Tue Jan  3 16:08:24 2012
@@ -135,6 +135,11 @@
     PLIST_ENTRY CurrentOpenEntry;
     PNDISUIO_OPEN_ENTRY OpenEntry;
 
+    /* Remove the adapter context from the global list */
+    KeAcquireSpinLock(&GlobalAdapterListLock, &OldIrql);
+    RemoveEntryList(&AdapterContext->ListEntry);
+    KeReleaseSpinLock(&GlobalAdapterListLock, OldIrql);
+
     /* Invalidate all handles to this adapter */
     CurrentOpenEntry = AdapterContext->OpenEntryList.Flink;
     while (CurrentOpenEntry != &AdapterContext->OpenEntryList)
@@ -163,11 +168,6 @@
     /* If this fails, we have a refcount mismatch somewhere */
     ASSERT(AdapterContext->OpenCount == 0);
 
-    /* Remove the adapter context from the global list */
-    KeAcquireSpinLock(&GlobalAdapterListLock, &OldIrql);
-    RemoveEntryList(&AdapterContext->ListEntry);
-    KeReleaseSpinLock(&GlobalAdapterListLock, OldIrql);
-    
     /* Send the close request */
     NdisCloseAdapter(Status,
                      AdapterContext->BindingHandle);
@@ -209,7 +209,7 @@
     KeInitializeSpinLock(&AdapterContext->Spinlock);
     InitializeListHead(&AdapterContext->PacketList);
     InitializeListHead(&AdapterContext->OpenEntryList);
-    AdapterContext->OpenCount = 1;
+    AdapterContext->OpenCount = 0;
 
     /* Send the open request */
     NdisOpenAdapter(&Status,
@@ -261,8 +261,8 @@
                PVOID SystemSpecific1,
                PVOID SystemSpecific2)
 {
-    /* We don't bind like this */
-    *Status = NDIS_STATUS_SUCCESS;
+    /* Use our helper function to create a context for this adapter */
+    *Status = BindAdapterByName(DeviceName);
 }
 
 VOID

Modified: branches/wlan-bringup/drivers/network/ndisuio/readwrite.c
URL: http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/ndisuio/readwrite.c?rev=54816&r1=54815&r2=54816&view=diff
==============================================================================
--- branches/wlan-bringup/drivers/network/ndisuio/readwrite.c [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/ndisuio/readwrite.c [iso-8859-1] Tue Jan  3 16:08:24 2012
@@ -17,11 +17,13 @@
                 PIRP Irp)
 {
     ASSERT(DeviceObject == GlobalDeviceObject);
-    
+
     /* FIXME: Not implemented */
     Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
     Irp->IoStatus.Information = 0;
-    
+
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
     return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -35,6 +37,8 @@
     /* FIXME: Not implemented */
     Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
     Irp->IoStatus.Information = 0;
-    
+
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
     return STATUS_NOT_IMPLEMENTED;
 }




More information about the Ros-diffs mailing list