[NTOSKRNL]
authorPierre Schweitzer <pierre@reactos.org>
Tue, 22 Jun 2010 18:47:22 +0000 (18:47 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 22 Jun 2010 18:47:22 +0000 (18:47 +0000)
Add a macro to check for a valid PDO and use it in IoOpenDeviceRegistryKey().
Requested by sir_richard.

svn path=/trunk/; revision=47828

reactos/ntoskrnl/include/internal/io.h
reactos/ntoskrnl/io/pnpmgr/pnpmgr.c

index 326f19c..bec9be6 100644 (file)
     (_DeviceTreeTraverseContext)->Action = (_Action);   \
     (_DeviceTreeTraverseContext)->Context = (_Context); }
 
     (_DeviceTreeTraverseContext)->Action = (_Action);   \
     (_DeviceTreeTraverseContext)->Context = (_Context); }
 
+/*
+ * BOOLEAN
+ * IopIsValidPhysicalDeviceObject(
+ *   IN PDEVICE_OBJECT PhysicalDeviceObject);
+ */
+#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)                                                            \
+        (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject) &&                                                          \
+        (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode) &&                      \
+        (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode->Flags & DNF_ENUMERATED))
+
 //
 // Device List Operations
 //
 //
 // Device List Operations
 //
index 06f1405..055f935 100644 (file)
@@ -3527,9 +3527,9 @@ IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject,
    }
    else
    {
    }
    else
    {
-      DeviceNode = IopGetDeviceNode(DeviceObject);
-      if (!DeviceNode)
+      if (!IopIsValidPhysicalDeviceObject(DeviceObject))
           return STATUS_INVALID_DEVICE_REQUEST;
           return STATUS_INVALID_DEVICE_REQUEST;
+      DeviceNode = IopGetDeviceNode(DeviceObject);
       KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
                        DeviceNode->InstancePath.Length;
    }
       KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
                        DeviceNode->InstancePath.Length;
    }