Do only one exit point in SetupDiInstallDevice

svn path=/trunk/; revision=18290
This commit is contained in:
Hervé Poussineau 2005-10-06 09:55:10 +00:00
parent abc9898008
commit ceff0e9f0e

View file

@ -4391,10 +4391,11 @@ SetupDiInstallDevice(
LPCWSTR AssociatedService = NULL; LPCWSTR AssociatedService = NULL;
LPWSTR pSectionName = NULL; LPWSTR pSectionName = NULL;
BOOL RebootRequired = FALSE; BOOL RebootRequired = FALSE;
HKEY hEnumKey, hKey; HKEY hEnumKey, hKey = INVALID_HANDLE_VALUE;
LONG rc; LONG rc;
HWND hWnd; HWND hWnd;
PVOID callback_context; PVOID callback_context;
BOOL ret = FALSE; /* Return value */
TRACE("%p %p\n", DeviceInfoSet, DeviceInfoData); TRACE("%p %p\n", DeviceInfoSet, DeviceInfoData);
@ -4416,7 +4417,7 @@ SetupDiInstallDevice(
if (!Result) if (!Result)
{ {
/* One parameter is bad */ /* One parameter is bad */
return FALSE; goto cleanup;
} }
/* FIXME: If DI_FLAGSEX_SETFAILEDINSTALL is set, set FAILEDINSTALL flag in ConfigFlags registry and exit */ /* FIXME: If DI_FLAGSEX_SETFAILEDINSTALL is set, set FAILEDINSTALL flag in ConfigFlags registry and exit */
@ -4435,15 +4436,12 @@ SetupDiInstallDevice(
hInf = SetupOpenInfFileW(DriverInfo->InfPath, NULL, INF_STYLE_WIN4, NULL); hInf = SetupOpenInfFileW(DriverInfo->InfPath, NULL, INF_STYLE_WIN4, NULL);
if (hInf == INVALID_HANDLE_VALUE) if (hInf == INVALID_HANDLE_VALUE)
return FALSE; goto cleanup;
Result = SetupDiGetActualSectionToInstallW(hInf, DriverInfo->InfSection, Result = SetupDiGetActualSectionToInstallW(hInf, DriverInfo->InfSection,
SectionName, MAX_PATH, &SectionNameLength, NULL); SectionName, MAX_PATH, &SectionNameLength, NULL);
if (!Result || SectionNameLength > MAX_PATH - 9) if (!Result || SectionNameLength > MAX_PATH - 9)
{ goto cleanup;
SetupCloseInfFile(hInf);
return FALSE;
}
pSectionName = &SectionName[wcslen(SectionName)]; pSectionName = &SectionName[wcslen(SectionName)];
/* Create driver key information */ /* Create driver key information */
@ -4474,7 +4472,7 @@ SetupDiInstallDevice(
NULL, 0, NULL, 0,
&RequiredSize); &RequiredSize);
if (!Result) if (!Result)
goto cleanup; goto nextfile;
if (RequiredSize > 0) if (RequiredSize > 0)
{ {
/* We got the needed size for the buffer */ /* We got the needed size for the buffer */
@ -4482,7 +4480,7 @@ SetupDiInstallDevice(
if (!ServiceName) if (!ServiceName)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto cleanup; goto nextfile;
} }
Result = SetupGetStringFieldW( Result = SetupGetStringFieldW(
&ContextService, &ContextService,
@ -4490,7 +4488,7 @@ SetupDiInstallDevice(
ServiceName, RequiredSize, ServiceName, RequiredSize,
&RequiredSize); &RequiredSize);
if (!Result) if (!Result)
goto cleanup; goto nextfile;
} }
Result = SetupGetIntField( Result = SetupGetIntField(
&ContextService, &ContextService,
@ -4507,7 +4505,7 @@ SetupDiInstallDevice(
NULL, 0, NULL, 0,
&RequiredSize); &RequiredSize);
if (!Result) if (!Result)
goto cleanup; goto nextfile;
if (RequiredSize > 0) if (RequiredSize > 0)
{ {
/* We got the needed size for the buffer */ /* We got the needed size for the buffer */
@ -4515,7 +4513,7 @@ SetupDiInstallDevice(
if (!ServiceSection) if (!ServiceSection)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto cleanup; goto nextfile;
} }
Result = SetupGetStringFieldW( Result = SetupGetStringFieldW(
&ContextService, &ContextService,
@ -4523,7 +4521,7 @@ SetupDiInstallDevice(
ServiceSection, RequiredSize, ServiceSection, RequiredSize,
&RequiredSize); &RequiredSize);
if (!Result) if (!Result)
goto cleanup; goto nextfile;
} }
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);
Result = SetupInstallServicesFromInfSectionExW(hInf, ServiceSection, Flags, DeviceInfoSet, DeviceInfoData, ServiceName, NULL); Result = SetupInstallServicesFromInfSectionExW(hInf, ServiceSection, Flags, DeviceInfoSet, DeviceInfoData, ServiceName, NULL);
@ -4534,15 +4532,11 @@ SetupDiInstallDevice(
if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED) if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED)
RebootRequired = TRUE; RebootRequired = TRUE;
} }
cleanup: nextfile:
HeapFree(GetProcessHeap(), 0, ServiceName); HeapFree(GetProcessHeap(), 0, ServiceName);
HeapFree(GetProcessHeap(), 0, ServiceSection); HeapFree(GetProcessHeap(), 0, ServiceSection);
if (!Result) if (!Result)
{ goto cleanup;
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService);
SetupCloseInfFile(hInf);
return FALSE;
}
Result = SetupFindNextLine(&ContextService, &ContextService); Result = SetupFindNextLine(&ContextService, &ContextService);
} }
@ -4558,9 +4552,7 @@ cleanup:
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
SetLastError(rc); SetLastError(rc);
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService); goto cleanup;
SetupCloseInfFile(hInf);
return FALSE;
} }
rc = RegOpenKeyExW( rc = RegOpenKeyExW(
hEnumKey, hEnumKey,
@ -4572,9 +4564,7 @@ cleanup:
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
SetLastError(rc); SetLastError(rc);
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService); goto cleanup;
SetupCloseInfFile(hInf);
return FALSE;
} }
/* Install .HW section */ /* Install .HW section */
@ -4586,12 +4576,7 @@ cleanup:
NULL, NULL); NULL, NULL);
SetupTermDefaultQueueCallback(callback_context); SetupTermDefaultQueueCallback(callback_context);
if (!Result) if (!Result)
{ goto cleanup;
RegCloseKey(hKey);
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService);
SetupCloseInfFile(hInf);
return FALSE;
}
/* Write information to enum key */ /* Write information to enum key */
FIXME("FIXME: Write information to enum key\n"); FIXME("FIXME: Write information to enum key\n");
@ -4607,13 +4592,10 @@ cleanup:
rc = RegSetValueEx(hKey, L"DeviceDesc", 0, REG_SZ, (const BYTE *)DriverInfo->Info.Description, (wcslen(DriverInfo->Info.Description) + 1) * sizeof(WCHAR)); rc = RegSetValueEx(hKey, L"DeviceDesc", 0, REG_SZ, (const BYTE *)DriverInfo->Info.Description, (wcslen(DriverInfo->Info.Description) + 1) * sizeof(WCHAR));
if (rc == ERROR_SUCCESS) if (rc == ERROR_SUCCESS)
rc = RegSetValueEx(hKey, L"Mfg", 0, REG_SZ, (const BYTE *)DriverInfo->Info.MfgName, (wcslen(DriverInfo->Info.MfgName) + 1) * sizeof(WCHAR)); rc = RegSetValueEx(hKey, L"Mfg", 0, REG_SZ, (const BYTE *)DriverInfo->Info.MfgName, (wcslen(DriverInfo->Info.MfgName) + 1) * sizeof(WCHAR));
RegCloseKey(hKey);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
SetLastError(rc); SetLastError(rc);
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService); goto cleanup;
SetupCloseInfFile(hInf);
return FALSE;
} }
/* Load the driver/call AddDevice */ /* Load the driver/call AddDevice */
@ -4623,8 +4605,16 @@ cleanup:
//if (!RebootRequired && !(Flags & (DI_NEEDRESTART | DI_NEEDREBOOT | DI_DONOTCALLCONFIGMG))) //if (!RebootRequired && !(Flags & (DI_NEEDRESTART | DI_NEEDREBOOT | DI_DONOTCALLCONFIGMG)))
FIXME("FIXME: Send IRP_MN_START_DEVICE\n"); FIXME("FIXME: Send IRP_MN_START_DEVICE\n");
ret = TRUE;
cleanup:
/* End of installation */ /* End of installation */
if (hKey != INVALID_HANDLE_VALUE)
RegCloseKey(hKey);
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService); HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService);
SetupCloseInfFile(hInf); if (hInf != NULL && hInf != INVALID_HANDLE_VALUE)
return TRUE; SetupCloseInfFile(hInf);
TRACE("Returning %d\n", ret);
return ret;
} }