From 7c5233a80e5c36c1a4871b8cd58c563a56d22606 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 9 Nov 2020 13:02:31 +0100 Subject: api: account for adapter disappearing during deletion This makes the race less fatal. Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'api/adapter.c') diff --git a/api/adapter.c b/api/adapter.c index 6c1a5b5..325a29e 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1707,8 +1707,9 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter( SP_REMOVEDEVICE_PARAMS Params = { .ClassInstallHeader = { .cbSize = sizeof(SP_CLASSINSTALL_HEADER), .InstallFunction = DIF_REMOVE }, .Scope = DI_REMOVEDEVICE_GLOBAL }; - if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) || - !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) + if ((!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) || + !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) && + GetLastError() != ERROR_NO_SUCH_DEVINST) { LastError = LOG_LAST_ERROR(L"Failed to remove existing adapter"); goto cleanupDevInfo; @@ -1759,8 +1760,9 @@ static _Return_type_success_(return != FALSE) BOOL LOG(WINTUN_LOG_WARN, L"Failed to force close adapter handles"); LOG(WINTUN_LOG_INFO, L"Removing existing adapter"); - if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) || - !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) + if ((!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) || + !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) && + GetLastError() != ERROR_NO_SUCH_DEVINST) { LOG_LAST_ERROR(L"Failed to remove existing adapter"); LastError = LastError != ERROR_SUCCESS ? LastError : GetLastError(); -- cgit v1.2.3-59-g8ed1b