[ros-diffs] [cgutman] 54035: [HALACPI] - Work around a race condition related to devices reported before the I/O subsystem is fully up - Fixes bug #6271

cgutman at svn.reactos.org cgutman at svn.reactos.org
Thu Oct 6 21:50:09 UTC 2011


Author: cgutman
Date: Thu Oct  6 21:50:07 2011
New Revision: 54035

URL: http://svn.reactos.org/svn/reactos?rev=54035&view=rev
Log:
[HALACPI]
- Work around a race condition related to devices reported before the I/O subsystem is fully up
- Fixes bug #6271

Modified:
    trunk/reactos/hal/halx86/acpi/halpnpdd.c

Modified: trunk/reactos/hal/halx86/acpi/halpnpdd.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/acpi/halpnpdd.c?rev=54035&r1=54034&r2=54035&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/acpi/halpnpdd.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/acpi/halpnpdd.c [iso-8859-1] Thu Oct  6 21:50:07 2011
@@ -50,6 +50,59 @@
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
+VOID
+NTAPI
+HalpReportDetectedDevices(IN PDRIVER_OBJECT DriverObject,
+                          IN PVOID Context,
+                          IN ULONG Count)
+{
+    PFDO_EXTENSION FdoExtension = Context;
+    PPDO_EXTENSION PdoExtension;
+    PDEVICE_OBJECT PdoDeviceObject;
+    NTSTATUS Status;
+    PDESCRIPTION_HEADER Wdrt;
+
+    /* Create the PDO */
+    Status = IoCreateDevice(DriverObject,
+                            sizeof(PDO_EXTENSION),
+                            NULL,
+                            FILE_DEVICE_BUS_EXTENDER,
+                            FILE_AUTOGENERATED_DEVICE_NAME,
+                            FALSE,
+                            &PdoDeviceObject);
+    if (!NT_SUCCESS(Status))
+    {
+        /* Fail */
+        DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
+        return;
+    }
+
+    /* Setup the PDO device extension */
+    PdoExtension = PdoDeviceObject->DeviceExtension;
+    PdoExtension->ExtensionType = PdoExtensionType;
+    PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
+    PdoExtension->ParentFdoExtension = FdoExtension;
+    PdoExtension->PdoType = AcpiPdo;
+    
+    /* Add the PDO to the head of the list */
+    PdoExtension->Next = FdoExtension->ChildPdoList;
+    FdoExtension->ChildPdoList = PdoExtension;
+    
+    /* Initialization is finished */
+    PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
+
+    /* Find the ACPI watchdog table */
+    Wdrt = HalAcpiGetTable(0, 'TRDW');
+    if (Wdrt)
+    {
+        /* FIXME: TODO */
+        DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n");
+    }
+
+    /* Invalidate device relations since we added a new device */
+    IoInvalidateDeviceRelations(FdoExtension->PhysicalDeviceObject, BusRelations);
+}
+
 NTSTATUS
 NTAPI
 HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
@@ -57,9 +110,7 @@
 {
     NTSTATUS Status;
     PFDO_EXTENSION FdoExtension;
-    PPDO_EXTENSION PdoExtension;
-    PDEVICE_OBJECT DeviceObject, PdoDeviceObject, AttachedDevice;
-    PDESCRIPTION_HEADER Wdrt;
+    PDEVICE_OBJECT DeviceObject, AttachedDevice;
     DPRINT("HAL: PnP Driver ADD!\n");
 
     /* Create the FDO */
@@ -95,49 +146,14 @@
         IoDeleteDevice(DeviceObject);
         return STATUS_NO_SUCH_DEVICE;
     }
-    
+
     /* Save the attachment */
     FdoExtension->AttachedDeviceObject = AttachedDevice;
-    
-    /* Create the PDO */
-    Status = IoCreateDevice(DriverObject,
-                            sizeof(PDO_EXTENSION),
-                            NULL,
-                            FILE_DEVICE_BUS_EXTENDER,
-                            FILE_AUTOGENERATED_DEVICE_NAME,
-                            FALSE,
-                            &PdoDeviceObject);
-    if (!NT_SUCCESS(Status))
-    {
-        /* Fail */
-        DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
-        return Status;
-    }
-    
-    /* Setup the PDO device extension */
-    PdoExtension = PdoDeviceObject->DeviceExtension;
-    PdoExtension->ExtensionType = PdoExtensionType;
-    PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
-    PdoExtension->ParentFdoExtension = FdoExtension;
-    PdoExtension->PdoType = AcpiPdo;
-    
-    /* Add the PDO to the head of the list */
-    PdoExtension->Next = FdoExtension->ChildPdoList;
-    FdoExtension->ChildPdoList = PdoExtension;
-    
-    /* Initialization is finished */
-    PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-
-    /* Find the ACPI watchdog table */
-    Wdrt = HalAcpiGetTable(0, 'TRDW');
-    if (Wdrt)
-    {
-        /* FIXME: TODO */
-        DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n");
-    }
-
-    /* Invalidate device relations since we added a new device */
-    IoInvalidateDeviceRelations(TargetDevice, BusRelations);
+
+    /* Register for reinitialization to report devices later */
+    IoRegisterDriverReinitialization(DriverObject,
+                                     HalpReportDetectedDevices,
+                                     FdoExtension);
 
     /* Return status */
     DPRINT("Device added %lx\n", Status);




More information about the Ros-diffs mailing list