From 7f35f0dbab5237bef45a7cc93b3faf6f21296974 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 2 Nov 2020 00:13:55 +0100 Subject: [PATCH] api: map cr errors to win32 errors Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index 159b244..7db8023 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -174,26 +174,22 @@ static WINTUN_STATUS GetDeviceObject(_In_opt_z_ const WCHAR *InstanceId, _Out_ HANDLE *Handle) { ULONG InterfacesLen; - DWORD Result = CM_Get_Device_Interface_List_SizeW( - &InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); - if (Result != CR_SUCCESS) - { - LOG(WINTUN_LOG_ERR, L"Failed to query associated instances size"); - return ERROR_GEN_FAILURE; - } + DWORD Result = CM_MapCrToWin32Err(CM_Get_Device_Interface_List_SizeW( + &InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT), ERROR_GEN_FAILURE); + if (Result != ERROR_SUCCESS) + return LOG_ERROR(L"Failed to query associated instances size", Result); WCHAR *Interfaces = HeapAlloc(ModuleHeap, 0, InterfacesLen * sizeof(WCHAR)); if (!Interfaces) return LOG(WINTUN_LOG_ERR, L"Out of memory"), ERROR_OUTOFMEMORY; - Result = CM_Get_Device_Interface_ListW( + Result = CM_MapCrToWin32Err(CM_Get_Device_Interface_ListW( (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, Interfaces, InterfacesLen, - CM_GET_DEVICE_INTERFACE_LIST_PRESENT); - if (Result != CR_SUCCESS) + CM_GET_DEVICE_INTERFACE_LIST_PRESENT), ERROR_GEN_FAILURE); + if (Result != ERROR_SUCCESS) { - LOG(WINTUN_LOG_ERR, L"Failed to get associated instances"); - Result = ERROR_GEN_FAILURE; + LOG_ERROR(L"Failed to get associated instances", Result); goto cleanupBuf; } *Handle = CreateFileW(