[UMPNPMGR] PNP_CreateDevInst: Do not create a new device while generating a device id

This commit is contained in:
Eric Kohl 2022-04-18 12:59:41 +02:00
parent 11886ebec2
commit 426687becf

View file

@ -3012,39 +3012,38 @@ PNP_CreateDevInst(
{ {
WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN]; WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
DWORD dwInstanceNumber; DWORD dwInstanceNumber;
DWORD dwError = ERROR_SUCCESS;
HKEY hKey;
/* Generated ID is: Root\<Device ID>\<Instance number> */ /* Generated ID is: Root\<Device ID>\<Instance number> */
dwInstanceNumber = 0; dwInstanceNumber = 0;
do while (dwError == ERROR_SUCCESS)
{ {
swprintf(szGeneratedInstance, L"Root\\%ls\\%04lu", swprintf(szGeneratedInstance, L"Root\\%ls\\%04lu",
pszDeviceID, dwInstanceNumber); pszDeviceID, dwInstanceNumber);
/* Try to create a device instance with this ID */ /* Try to open the enum key of the device instance */
ret = CreateDeviceInstance(szGeneratedInstance); dwError = RegOpenKeyEx(hEnumKey, szGeneratedInstance, 0, KEY_QUERY_VALUE, &hKey);
if (dwError == ERROR_SUCCESS)
dwInstanceNumber++; {
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 */ ret = CR_BUFFER_SMALL;
if (wcslen(szGeneratedInstance) > ulLength) }
{ else
ret = CR_BUFFER_SMALL; {
} wcscpy(pszDeviceID, szGeneratedInstance);
else
{
wcscpy(pszDeviceID, szGeneratedInstance);
}
} }
} }
else
{ /* Create the device instance */
/* Create the device instance */ ret = CreateDeviceInstance(pszDeviceID);
ret = CreateDeviceInstance(pszDeviceID);
}
DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret); DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret);