[NTOS:PNP]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 4 Mar 2017 16:01:59 +0000 (16:01 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 4 Mar 2017 16:01:59 +0000 (16:01 +0000)
- 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

reactos/ntoskrnl/io/pnpmgr/pnpmgr.c

index 88d1bae..ee4d66d 100644 (file)
@@ -1950,59 +1950,57 @@ IopCreateDeviceInstancePath(
                                &IoStatusBlock,
                                IRP_MN_QUERY_ID,
                                &Stack);
                                &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(&InstanceId);
+        RtlFreeUnicodeString(&ParentIdPrefix);
         RtlFreeUnicodeString(&DeviceId);
         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;
     RtlFreeUnicodeString(&ParentIdPrefix);
 
     return STATUS_SUCCESS;