Author: tfaber Date: Sat Mar 4 16:01:59 2017 New Revision: 74053
URL: http://svn.reactos.org/svn/reactos?rev=74053&view=rev Log: [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
Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c... ============================================================================== --- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] Sat Mar 4 16:01:59 2017 @@ -1950,59 +1950,57 @@ &IoStatusBlock, IRP_MN_QUERY_ID, &Stack); - 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"&"); - } - - /* Finally, add the id returned by the driver stack */ - RtlAppendUnicodeStringToString(InstancePath, &InstanceId); - - /* - * FIXME: Check for valid characters, if there is invalid characters - * then bugcheck - */ - + if (!NT_SUCCESS(Status)) + { + DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %lx)\n", Status); + ASSERT(IoStatusBlock.Information == 0); + } + + 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); - } - else - { - DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %x)\n", Status); - *InstancePath = 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"&"); + } + + /* 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;