mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 09:52:56 +00:00
[NTOS:PNP] Avoid recursion when walking the device tree.
This commit is contained in:
parent
3dd3d10531
commit
c0e7eaf403
1 changed files with 33 additions and 24 deletions
|
@ -18,6 +18,12 @@ typedef struct _PNP_EVENT_ENTRY
|
||||||
PLUGPLAY_EVENT_BLOCK Event;
|
PLUGPLAY_EVENT_BLOCK Event;
|
||||||
} PNP_EVENT_ENTRY, *PPNP_EVENT_ENTRY;
|
} PNP_EVENT_ENTRY, *PPNP_EVENT_ENTRY;
|
||||||
|
|
||||||
|
typedef struct _IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT
|
||||||
|
{
|
||||||
|
PCUNICODE_STRING InstancePath;
|
||||||
|
PDEVICE_OBJECT DeviceObject;
|
||||||
|
} IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT, *PIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT;
|
||||||
|
|
||||||
|
|
||||||
/* GLOBALS *******************************************************************/
|
/* GLOBALS *******************************************************************/
|
||||||
|
|
||||||
|
@ -88,39 +94,32 @@ IopQueueTargetDeviceEvent(const GUID *Guid,
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
static PDEVICE_OBJECT
|
IopFindDeviceInstanceTraverse(
|
||||||
IopTraverseDeviceNode(PDEVICE_NODE Node, PUNICODE_STRING DeviceInstance)
|
_In_ PDEVICE_NODE DeviceNode,
|
||||||
|
_Inout_ PVOID Context)
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PIOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext = Context;
|
||||||
PDEVICE_NODE ChildNode;
|
|
||||||
|
|
||||||
if (RtlEqualUnicodeString(&Node->InstancePath,
|
if (RtlEqualUnicodeString(&DeviceNode->InstancePath,
|
||||||
DeviceInstance, TRUE))
|
DeviceInstanceContext->InstancePath, TRUE))
|
||||||
{
|
{
|
||||||
ObReferenceObject(Node->PhysicalDeviceObject);
|
ObReferenceObject(DeviceNode->PhysicalDeviceObject);
|
||||||
return Node->PhysicalDeviceObject;
|
DeviceInstanceContext->DeviceObject = DeviceNode->PhysicalDeviceObject;
|
||||||
|
|
||||||
|
/* Stop enumeration */
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Traversal of all children nodes */
|
return STATUS_SUCCESS;
|
||||||
for (ChildNode = Node->Child;
|
|
||||||
ChildNode != NULL;
|
|
||||||
ChildNode = ChildNode->Sibling)
|
|
||||||
{
|
|
||||||
DeviceObject = IopTraverseDeviceNode(ChildNode, DeviceInstance);
|
|
||||||
if (DeviceObject != NULL)
|
|
||||||
{
|
|
||||||
return DeviceObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PDEVICE_OBJECT
|
PDEVICE_OBJECT
|
||||||
IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
|
IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
|
||||||
{
|
{
|
||||||
|
DEVICETREE_TRAVERSE_CONTEXT Context;
|
||||||
|
IOP_FIND_DEVICE_INSTANCE_TRAVERSE_CONTEXT DeviceInstanceContext;
|
||||||
|
|
||||||
if (IopRootDeviceNode == NULL)
|
if (IopRootDeviceNode == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -136,7 +135,17 @@ IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IopTraverseDeviceNode(IopRootDeviceNode, DeviceInstance);
|
/* Traverse the device tree to find the matching device node */
|
||||||
|
DeviceInstanceContext.InstancePath = DeviceInstance;
|
||||||
|
DeviceInstanceContext.DeviceObject = NULL;
|
||||||
|
IopInitDeviceTreeTraverseContext(&Context,
|
||||||
|
IopRootDeviceNode,
|
||||||
|
IopFindDeviceInstanceTraverse,
|
||||||
|
&DeviceInstanceContext);
|
||||||
|
(void)IopTraverseDeviceTree(&Context);
|
||||||
|
|
||||||
|
/* In case of error or instance not found, this will still be NULL from above. */
|
||||||
|
return DeviceInstanceContext.DeviceObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue