[NTOS:PO]
authorThomas Faber <thomas.faber@reactos.org>
Wed, 27 Jul 2016 11:15:52 +0000 (11:15 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Wed, 27 Jul 2016 11:15:52 +0000 (11:15 +0000)
- Send power IRPs to the top of the device stack instead of the PDO
CORE-10110 #resolve

svn path=/trunk/; revision=72017

reactos/ntoskrnl/po/power.c

index 07e92b7..38bc67d 100644 (file)
@@ -153,6 +153,7 @@ PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
                                  PVOID Context)
 {
     PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
                                  PVOID Context)
 {
     PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
+    PDEVICE_OBJECT TopDeviceObject;
     NTSTATUS Status;
 
     DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
     NTSTATUS Status;
 
     DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
@@ -163,13 +164,16 @@ PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
     if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
         return STATUS_SUCCESS;
 
     if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
         return STATUS_SUCCESS;
 
-    Status = PopSendQuerySystemPowerState(DeviceNode->PhysicalDeviceObject,
+    TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
+
+    Status = PopSendQuerySystemPowerState(TopDeviceObject,
                                           PowerStateContext->SystemPowerState,
                                           PowerStateContext->PowerAction);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
     }
                                           PowerStateContext->SystemPowerState,
                                           PowerStateContext->PowerAction);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
     }
+    ObDereferenceObject(TopDeviceObject);
 
 #if 0
     return Status;
 
 #if 0
     return Status;
@@ -183,6 +187,7 @@ PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
                                PVOID Context)
 {
     PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
                                PVOID Context)
 {
     PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
+    PDEVICE_OBJECT TopDeviceObject;
     NTSTATUS Status;
 
     DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
     NTSTATUS Status;
 
     DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
@@ -196,7 +201,14 @@ PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
     if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
         return STATUS_SUCCESS;
 
     if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
         return STATUS_SUCCESS;
 
-    Status = PopSendSetSystemPowerState(DeviceNode->PhysicalDeviceObject,
+    TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
+    if (TopDeviceObject == PowerStateContext->PowerDevice)
+    {
+        ObDereferenceObject(TopDeviceObject);
+        return STATUS_SUCCESS;
+    }
+
+    Status = PopSendSetSystemPowerState(TopDeviceObject,
                                         PowerStateContext->SystemPowerState,
                                         PowerStateContext->PowerAction);
     if (!NT_SUCCESS(Status))
                                         PowerStateContext->SystemPowerState,
                                         PowerStateContext->PowerAction);
     if (!NT_SUCCESS(Status))
@@ -204,6 +216,8 @@ PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
         DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
     }
 
         DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
     }
 
+    ObDereferenceObject(TopDeviceObject);
+
 #if 0
     return Status;
 #else
 #if 0
     return Status;
 #else