From: Thomas Faber Date: Sat, 4 Mar 2017 16:01:59 +0000 (+0000) Subject: [NTOS:PNP] X-Git-Tag: ReactOS-0.4.4-CLT2017~38 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=16b4b0a87486e26633bb5a7e0d81f6a3d913ebfa [NTOS:PNP] - Make device instance paths unique if necessary (by adding the parent ID prefix), regardless of the return status from IRP_MN_QUERY_ID/BusQueryInstanceID. Support for this IRP is optional in most cases, and a failure status just indicates no instance id information is needed by the driver stack. Major thanks to Vadim Galyant for debugging this and identifying the root cause. CORE-12732 CORE-12818 CORE-12745 CORE-12733 CORE-12717 CORE-12735 svn path=/trunk/; revision=74053 --- diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c index 88d1bae7d2b..ee4d66d436e 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -1950,59 +1950,57 @@ IopCreateDeviceInstancePath( &IoStatusBlock, IRP_MN_QUERY_ID, &Stack); - if (NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - RtlInitUnicodeString(&InstanceId, - (PWSTR)IoStatusBlock.Information); - - InstancePath->Length = 0; - InstancePath->MaximumLength = DeviceId.Length + sizeof(WCHAR) + - ParentIdPrefix.Length + - InstanceId.Length + - sizeof(UNICODE_NULL); - if (ParentIdPrefix.Length && InstanceId.Length) - { - InstancePath->MaximumLength += sizeof(WCHAR); - } - - InstancePath->Buffer = ExAllocatePoolWithTag(PagedPool, - InstancePath->MaximumLength, - TAG_IO); - if (!InstancePath->Buffer) - { - RtlFreeUnicodeString(&InstanceId); - RtlFreeUnicodeString(&ParentIdPrefix); - RtlFreeUnicodeString(&DeviceId); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* Start with the device id */ - RtlCopyUnicodeString(InstancePath, &DeviceId); - RtlAppendUnicodeToString(InstancePath, L"\\"); - - /* Add information from parent bus device to InstancePath */ - RtlAppendUnicodeStringToString(InstancePath, &ParentIdPrefix); - if (ParentIdPrefix.Length && InstanceId.Length) - { - RtlAppendUnicodeToString(InstancePath, L"&"); - } + DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %lx)\n", Status); + ASSERT(IoStatusBlock.Information == 0); + } - /* Finally, add the id returned by the driver stack */ - RtlAppendUnicodeStringToString(InstancePath, &InstanceId); + RtlInitUnicodeString(&InstanceId, + (PWSTR)IoStatusBlock.Information); - /* - * FIXME: Check for valid characters, if there is invalid characters - * then bugcheck - */ + InstancePath->Length = 0; + InstancePath->MaximumLength = DeviceId.Length + sizeof(WCHAR) + + ParentIdPrefix.Length + + InstanceId.Length + + sizeof(UNICODE_NULL); + if (ParentIdPrefix.Length && InstanceId.Length) + { + InstancePath->MaximumLength += sizeof(WCHAR); + } + InstancePath->Buffer = ExAllocatePoolWithTag(PagedPool, + InstancePath->MaximumLength, + TAG_IO); + if (!InstancePath->Buffer) + { RtlFreeUnicodeString(&InstanceId); + RtlFreeUnicodeString(&ParentIdPrefix); RtlFreeUnicodeString(&DeviceId); + return STATUS_INSUFFICIENT_RESOURCES; } - else + + /* Start with the device id */ + RtlCopyUnicodeString(InstancePath, &DeviceId); + RtlAppendUnicodeToString(InstancePath, L"\\"); + + /* Add information from parent bus device to InstancePath */ + RtlAppendUnicodeStringToString(InstancePath, &ParentIdPrefix); + if (ParentIdPrefix.Length && InstanceId.Length) { - DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %x)\n", Status); - *InstancePath = DeviceId; + RtlAppendUnicodeToString(InstancePath, L"&"); } + + /* Finally, add the id returned by the driver stack */ + RtlAppendUnicodeStringToString(InstancePath, &InstanceId); + + /* + * FIXME: Check for valid characters, if there is invalid characters + * then bugcheck + */ + + RtlFreeUnicodeString(&InstanceId); + RtlFreeUnicodeString(&DeviceId); RtlFreeUnicodeString(&ParentIdPrefix); return STATUS_SUCCESS;