From 2103cf341f229e0bcc6a5bd2be6c3c487c9da8ae Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Thu, 15 Jun 2017 13:25:26 +0000 Subject: [PATCH] [NTOS:IO] - Pass Enum subkey handle to IopAttachFilterDrivers, since we've already opened it in PipCallDriverAddDevice. CORE-13336 svn path=/trunk/; revision=75046 --- reactos/ntoskrnl/io/iomgr/driver.c | 36 +++------------------------- reactos/ntoskrnl/io/pnpmgr/pnpinit.c | 13 +++++----- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/reactos/ntoskrnl/io/iomgr/driver.c b/reactos/ntoskrnl/io/iomgr/driver.c index 70ce6b703b3..08d8f86020f 100644 --- a/reactos/ntoskrnl/io/iomgr/driver.c +++ b/reactos/ntoskrnl/io/iomgr/driver.c @@ -640,42 +640,16 @@ NTSTATUS FASTCALL IopAttachFilterDrivers( PDEVICE_NODE DeviceNode, + HANDLE EnumSubKey, BOOLEAN Lower) { RTL_QUERY_REGISTRY_TABLE QueryTable[2] = { { NULL, 0, NULL, NULL, 0, NULL, 0 }, }; UNICODE_STRING Class; WCHAR ClassBuffer[40]; - UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT); UNICODE_STRING ControlClass = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class"); - HANDLE EnumRootKey, SubKey; HANDLE ControlKey, ClassKey; NTSTATUS Status; - /* Open enumeration root key */ - Status = IopOpenRegistryKeyEx(&EnumRootKey, - NULL, - &EnumRoot, - KEY_READ); - if (!NT_SUCCESS(Status)) - { - DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n", - &EnumRoot, Status); - return Status; - } - - /* Open subkey */ - Status = IopOpenRegistryKeyEx(&SubKey, - EnumRootKey, - &DeviceNode->InstancePath, - KEY_READ); - ZwClose(EnumRootKey); - if (!NT_SUCCESS(Status)) - { - DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n", - &DeviceNode->InstancePath, Status); - return Status; - } - /* * First load the device filters */ @@ -688,7 +662,7 @@ IopAttachFilterDrivers( QueryTable[0].DefaultType = REG_NONE; Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE, - (PWSTR)SubKey, + (PWSTR)EnumSubKey, QueryTable, DeviceNode, NULL); @@ -696,7 +670,6 @@ IopAttachFilterDrivers( { DPRINT1("Failed to load device %s filters: %08X\n", Lower ? "lower" : "upper", Status); - ZwClose(SubKey); return Status; } @@ -712,14 +685,11 @@ IopAttachFilterDrivers( QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED | RTL_QUERY_REGISTRY_DIRECT; Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE, - (PWSTR)SubKey, + (PWSTR)EnumSubKey, QueryTable, DeviceNode, NULL); - /* Close subkey */ - ZwClose(SubKey); - /* If there is no class GUID, we're done */ if (!NT_SUCCESS(Status)) { diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpinit.c b/reactos/ntoskrnl/io/pnpmgr/pnpinit.c index b66d9a180d2..1cf62a06a66 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpinit.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpinit.c @@ -290,7 +290,6 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode, Status = IopGetRegistryValue(SubKey, REGSTR_VAL_CLASSGUID, &KeyValueInformation); - ZwClose(SubKey); if (NT_SUCCESS(Status)) { /* Convert to unicode string */ @@ -356,26 +355,28 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode, } /* Do ReactOS-style setup */ - Status = IopAttachFilterDrivers(DeviceNode, TRUE); + Status = IopAttachFilterDrivers(DeviceNode, SubKey, TRUE); if (!NT_SUCCESS(Status)) { IopRemoveDevice(DeviceNode); - return Status; + goto Exit; } Status = IopInitializeDevice(DeviceNode, DriverObject); if (NT_SUCCESS(Status)) { - Status = IopAttachFilterDrivers(DeviceNode, FALSE); + Status = IopAttachFilterDrivers(DeviceNode, SubKey, FALSE); if (!NT_SUCCESS(Status)) { IopRemoveDevice(DeviceNode); - return Status; + goto Exit; } Status = IopStartDevice(DeviceNode); } - /* Return status */ +Exit: + /* Close key and return status */ + ZwClose(SubKey); return Status; }