https://git.reactos.org/?p=reactos.git;a=commitdiff;h=426687becf36fb4c9a51e…
commit 426687becf36fb4c9a51e7dc64e65ad0d969391b
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Mon Apr 18 12:59:41 2022 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Apr 18 12:59:41 2022 +0200
[UMPNPMGR] PNP_CreateDevInst: Do not create a new device while generating a device id
---
base/services/umpnpmgr/rpcserver.c | 41 +++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/base/services/umpnpmgr/rpcserver.c b/base/services/umpnpmgr/rpcserver.c
index 1262e46d661..be39d95c4c2 100644
--- a/base/services/umpnpmgr/rpcserver.c
+++ b/base/services/umpnpmgr/rpcserver.c
@@ -3012,39 +3012,38 @@ PNP_CreateDevInst(
{
WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
DWORD dwInstanceNumber;
+ DWORD dwError = ERROR_SUCCESS;
+ HKEY hKey;
/* Generated ID is: Root\<Device ID>\<Instance number> */
dwInstanceNumber = 0;
- do
+ while (dwError == ERROR_SUCCESS)
{
swprintf(szGeneratedInstance, L"Root\\%ls\\%04lu",
pszDeviceID, dwInstanceNumber);
- /* Try to create a device instance with this ID */
- ret = CreateDeviceInstance(szGeneratedInstance);
-
- dwInstanceNumber++;
+ /* Try to open the enum key of the device instance */
+ dwError = RegOpenKeyEx(hEnumKey, szGeneratedInstance, 0, KEY_QUERY_VALUE,
&hKey);
+ if (dwError == ERROR_SUCCESS)
+ {
+ RegCloseKey(hKey);
+ dwInstanceNumber++;
+ }
}
- while (ret == CR_ALREADY_SUCH_DEVINST);
- if (ret == CR_SUCCESS)
+ /* pszDeviceID is an out parameter too for generated IDs */
+ if (wcslen(szGeneratedInstance) > ulLength)
{
- /* pszDeviceID is an out parameter too for generated IDs */
- if (wcslen(szGeneratedInstance) > ulLength)
- {
- ret = CR_BUFFER_SMALL;
- }
- else
- {
- wcscpy(pszDeviceID, szGeneratedInstance);
- }
+ ret = CR_BUFFER_SMALL;
+ }
+ else
+ {
+ wcscpy(pszDeviceID, szGeneratedInstance);
}
}
- else
- {
- /* Create the device instance */
- ret = CreateDeviceInstance(pszDeviceID);
- }
+
+ /* Create the device instance */
+ ret = CreateDeviceInstance(pszDeviceID);
DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret);