[channels,warnings] properly handle function return

This commit is contained in:
Armin Novak
2026-02-16 08:16:58 +01:00
parent e0e6a7f800
commit bf99266c2e
16 changed files with 115 additions and 41 deletions

View File

@@ -514,9 +514,7 @@ static UINT dvcman_channel_close(DVCMAN_CHANNEL* channel, BOOL perRequest, BOOL
IWTSVirtualChannelCallback* cb = channel->channel_callback; IWTSVirtualChannelCallback* cb = channel->channel_callback;
channel->channel_callback = NULL; channel->channel_callback = NULL;
if (cb) if (cb)
{ error = IFCALLRESULT(CHANNEL_RC_OK, cb->OnClose, cb);
IFCALL(cb->OnClose, cb);
}
} }
if (channel->dvcman && channel->dvcman->drdynvc) if (channel->dvcman && channel->dvcman->drdynvc)

View File

@@ -923,7 +923,7 @@ static void drive_message_free(void* obj)
if (!irp) if (!irp)
return; return;
WINPR_ASSERT(irp->Discard); WINPR_ASSERT(irp->Discard);
(void)irp->Discard(irp); irp->Discard(irp);
} }
/** /**

View File

@@ -48,7 +48,8 @@ static void devman_device_free(void* obj)
if (!device) if (!device)
return; return;
IFCALL(device->Free, device); if (device->Free)
device->Free(device);
} }
DEVMAN* devman_new(rdpdrPlugin* rdpdr) DEVMAN* devman_new(rdpdrPlugin* rdpdr)

View File

@@ -1563,7 +1563,7 @@ static UINT rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* s)
WLog_Print(rdpdr->log, WLOG_ERROR, "device->IRPRequest failed with error %" PRIu32 "", WLog_Print(rdpdr->log, WLOG_ERROR, "device->IRPRequest failed with error %" PRIu32 "",
error); error);
} }
(void)irp->Discard(irp); irp->Discard(irp);
return error; return error;
} }

View File

@@ -401,11 +401,12 @@ static UINT ecam_plugin_terminated(IWTSPlugin* pPlugin)
HashTable_Free(ecam->devices); HashTable_Free(ecam->devices);
UINT rc = CHANNEL_RC_OK;
if (ecam->ihal) if (ecam->ihal)
ecam->ihal->Free(ecam->ihal); rc = ecam->ihal->Free(ecam->ihal);
free(ecam); free(ecam);
return CHANNEL_RC_OK; return rc;
} }
/** /**

View File

@@ -73,8 +73,10 @@ static void free_surfaces(RdpgfxClientContext* context, wHashTable* SurfaceTable
HashTable_Foreach(SurfaceTable, delete_surface, context); HashTable_Foreach(SurfaceTable, delete_surface, context);
} }
static void evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots, void** CacheSlots) static UINT evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots, void** CacheSlots)
{ {
UINT error = CHANNEL_RC_OK;
WINPR_ASSERT(CacheSlots); WINPR_ASSERT(CacheSlots);
for (UINT16 index = 0; index < MaxCacheSlots; index++) for (UINT16 index = 0; index < MaxCacheSlots; index++)
{ {
@@ -85,12 +87,15 @@ static void evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots
if (context && context->EvictCacheEntry) if (context && context->EvictCacheEntry)
{ {
context->EvictCacheEntry(context, &pdu); const UINT rc = context->EvictCacheEntry(context, &pdu);
if (rc != CHANNEL_RC_OK)
error = rc;
} }
CacheSlots[index] = NULL; CacheSlots[index] = NULL;
} }
} }
return error;
} }
/** /**
@@ -861,7 +866,6 @@ fail:
static UINT rdpgfx_load_cache_import_reply(RDPGFX_PLUGIN* gfx, static UINT rdpgfx_load_cache_import_reply(RDPGFX_PLUGIN* gfx,
const RDPGFX_CACHE_IMPORT_REPLY_PDU* reply) const RDPGFX_CACHE_IMPORT_REPLY_PDU* reply)
{ {
int count = 0;
UINT error = CHANNEL_RC_OK; UINT error = CHANNEL_RC_OK;
rdpPersistentCache* persistent = NULL; rdpPersistentCache* persistent = NULL;
WINPR_ASSERT(gfx); WINPR_ASSERT(gfx);
@@ -896,7 +900,7 @@ static UINT rdpgfx_load_cache_import_reply(RDPGFX_PLUGIN* gfx,
goto fail; goto fail;
} }
count = persistent_cache_get_count(persistent); int count = persistent_cache_get_count(persistent);
count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount; count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount;
@@ -913,7 +917,11 @@ static UINT rdpgfx_load_cache_import_reply(RDPGFX_PLUGIN* gfx,
const UINT16 cacheSlot = reply->cacheSlots[idx]; const UINT16 cacheSlot = reply->cacheSlots[idx];
if (context && context->ImportCacheEntry) if (context && context->ImportCacheEntry)
context->ImportCacheEntry(context, cacheSlot, &entry); {
error = context->ImportCacheEntry(context, cacheSlot, &entry);
if (error != CHANNEL_RC_OK)
break;
}
} }
persistent_cache_free(persistent); persistent_cache_free(persistent);
@@ -1011,7 +1019,10 @@ static UINT rdpgfx_recv_create_surface_pdu(GENERIC_CHANNEL_CALLBACK* callback, w
* manually. * manually.
*/ */
RDPGFX_DELETE_SURFACE_PDU deletePdu = { pdu.surfaceId }; RDPGFX_DELETE_SURFACE_PDU deletePdu = { pdu.surfaceId };
IFCALL(context->DeleteSurface, context, &deletePdu); const UINT drc = IFCALLRESULT(CHANNEL_RC_OK, context->DeleteSurface, context, &deletePdu);
if (drc != CHANNEL_RC_OK)
WLog_Print(gfx->log, WLOG_WARN,
"context->DeleteSurface failed with error %" PRIu32 ", ignoring", error);
IFCALLRET(context->CreateSurface, error, context, &pdu); IFCALLRET(context->CreateSurface, error, context, &pdu);
@@ -2116,7 +2127,13 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
} }
free_surfaces(context, gfx->SurfaceTable); free_surfaces(context, gfx->SurfaceTable);
evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots); error = evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
if (error)
{
// print error, but don't consider this a hard failure
WLog_Print(gfx->log, WLOG_ERROR, "evict_cache_slots failed with error %" PRIu32 "",
error);
}
free(callback); free(callback);
gfx->UnacknowledgedFrames = 0; gfx->UnacknowledgedFrames = 0;
@@ -2124,7 +2141,13 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
if (context) if (context)
{ {
IFCALL(context->OnClose, context); error = IFCALLRESULT(CHANNEL_RC_OK, context->OnClose, context);
if (error)
{
// print error, but don't consider this a hard failure
WLog_Print(gfx->log, WLOG_ERROR, "context->OnClose failed with error %" PRIu32 "",
error);
}
} }
} }

View File

@@ -710,7 +710,9 @@ error_handle:
(void)CloseHandle(irpThread); (void)CloseHandle(irpThread);
irp->IoStatus = STATUS_NO_MEMORY; irp->IoStatus = STATUS_NO_MEMORY;
WINPR_ASSERT(irp->Complete); WINPR_ASSERT(irp->Complete);
irp->Complete(irp); const UINT rc = irp->Complete(irp);
if (rc != CHANNEL_RC_OK)
WLog_Print(serial->log, WLOG_WARN, "irp->Complete failed with %" PRIu32, rc);
free(data); free(data);
} }

View File

@@ -198,7 +198,7 @@ static UINT64 tsmf_alsa_get_latency(ITSMFAudioDevice* audio)
return latency; return latency;
} }
static BOOL tsmf_alsa_flush(ITSMFAudioDevice* audio) static BOOL tsmf_alsa_flush(WINPR_ATTR_UNUSED ITSMFAudioDevice* audio)
{ {
return TRUE; return TRUE;
} }

View File

@@ -462,7 +462,7 @@ static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder* decoder, const BYTE* data, UI
} }
static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size,
UINT32 extensions) WINPR_ATTR_UNUSED UINT32 extensions)
{ {
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder;
int len = 0; int len = 0;
@@ -686,7 +686,9 @@ static void tsmf_ffmpeg_free(ITSMFDecoder* decoder)
} }
static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT; static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT;
static BOOL CALLBACK InitializeAvCodecs(PINIT_ONCE once, PVOID param, PVOID* context) static BOOL CALLBACK InitializeAvCodecs(WINPR_ATTR_UNUSED PINIT_ONCE once,
WINPR_ATTR_UNUSED PVOID param,
WINPR_ATTR_UNUSED PVOID* context)
{ {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100)
avcodec_register_all(); avcodec_register_all();

View File

@@ -194,7 +194,7 @@ static UINT64 tsmf_oss_get_latency(ITSMFAudioDevice* audio)
return latency; return latency;
} }
static BOOL tsmf_oss_flush(ITSMFAudioDevice* audio) static BOOL tsmf_oss_flush(WINPR_ATTR_UNUSED ITSMFAudioDevice* audio)
{ {
return TRUE; return TRUE;
} }

View File

@@ -156,7 +156,8 @@ static BOOL tsmf_pulse_open(ITSMFAudioDevice* audio, const char* device)
return TRUE; return TRUE;
} }
static void tsmf_pulse_stream_success_callback(pa_stream* stream, int success, void* userdata) static void tsmf_pulse_stream_success_callback(WINPR_ATTR_UNUSED pa_stream* stream,
WINPR_ATTR_UNUSED int success, void* userdata)
{ {
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)userdata; TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)userdata;
pa_threaded_mainloop_signal(pulse->mainloop, 0); pa_threaded_mainloop_signal(pulse->mainloop, 0);
@@ -201,7 +202,8 @@ static void tsmf_pulse_stream_state_callback(pa_stream* stream, void* userdata)
} }
} }
static void tsmf_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata) static void tsmf_pulse_stream_request_callback(WINPR_ATTR_UNUSED pa_stream* stream,
WINPR_ATTR_UNUSED size_t length, void* userdata)
{ {
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)userdata; TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)userdata;
DEBUG_TSMF("%" PRIdz "", length); DEBUG_TSMF("%" PRIdz "", length);
@@ -294,7 +296,7 @@ static BOOL tsmf_pulse_open_stream(TSMFPulseAudioDevice* pulse)
} }
static BOOL tsmf_pulse_set_format(ITSMFAudioDevice* audio, UINT32 sample_rate, UINT32 channels, static BOOL tsmf_pulse_set_format(ITSMFAudioDevice* audio, UINT32 sample_rate, UINT32 channels,
UINT32 bits_per_sample) WINPR_ATTR_UNUSED UINT32 bits_per_sample)
{ {
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)audio; TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*)audio;
DEBUG_TSMF("sample_rate %" PRIu32 " channels %" PRIu32 " bits_per_sample %" PRIu32 "", DEBUG_TSMF("sample_rate %" PRIu32 " channels %" PRIu32 " bits_per_sample %" PRIu32 "",

View File

@@ -432,7 +432,9 @@ static UINT tsmf_on_close(IWTSVirtualChannelCallback* pChannelCallback)
* @return 0 on success, otherwise a Win32 error code * @return 0 on success, otherwise a Win32 error code
*/ */
static UINT tsmf_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, static UINT tsmf_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, IWTSVirtualChannel* pChannel,
WINPR_ATTR_UNUSED BYTE* Data,
WINPR_ATTR_UNUSED BOOL* pbAccept,
IWTSVirtualChannelCallback** ppCallback) IWTSVirtualChannelCallback** ppCallback)
{ {
TSMF_CHANNEL_CALLBACK* callback = NULL; TSMF_CHANNEL_CALLBACK* callback = NULL;

View File

@@ -450,9 +450,13 @@ static UINT urbdrc_process_query_device_text(IUDEVICE* pdev, GENERIC_CHANNEL_CAL
DeviceDescription, bufferSize); DeviceDescription, bufferSize);
} }
static void func_select_all_interface_for_msconfig(IUDEVICE* pdev, static void func_select_all_interface_for_msconfig(URBDRC_PLUGIN* urbdrc, IUDEVICE* pdev,
MSUSB_CONFIG_DESCRIPTOR* MsConfig) MSUSB_CONFIG_DESCRIPTOR* MsConfig)
{ {
WINPR_ASSERT(urbdrc);
WINPR_ASSERT(pdev);
WINPR_ASSERT(MsConfig);
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces; MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces;
UINT32 NumInterfaces = MsConfig->NumInterfaces; UINT32 NumInterfaces = MsConfig->NumInterfaces;
@@ -460,7 +464,12 @@ static void func_select_all_interface_for_msconfig(IUDEVICE* pdev,
{ {
const BYTE InterfaceNumber = MsInterfaces[inum]->InterfaceNumber; const BYTE InterfaceNumber = MsInterfaces[inum]->InterfaceNumber;
const BYTE AlternateSetting = MsInterfaces[inum]->AlternateSetting; const BYTE AlternateSetting = MsInterfaces[inum]->AlternateSetting;
pdev->select_interface(pdev, InterfaceNumber, AlternateSetting); const int rc = pdev->select_interface(pdev, InterfaceNumber, AlternateSetting);
if (rc < 0)
{
WLog_Print(urbdrc->log, WLOG_WARN, "select_interface %" PRIu8 " [%" PRIu8 "] failed",
InterfaceNumber, AlternateSetting);
}
} }
} }
@@ -545,9 +554,16 @@ static UINT urb_select_configuration(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* c
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
/* select config */ /* select config */
pdev->select_configuration(pdev, MsConfig->bConfigurationValue); const int lrc = pdev->select_configuration(pdev, MsConfig->bConfigurationValue);
if (lrc != 0)
{
msusb_msconfig_free(MsConfig);
MsConfig = NULL;
return ERROR_INTERNAL_ERROR;
}
/* select all interface */ /* select all interface */
func_select_all_interface_for_msconfig(pdev, MsConfig); func_select_all_interface_for_msconfig(urbdrc, pdev, MsConfig);
/* complete configuration setup */ /* complete configuration setup */
if (!pdev->complete_msconfig_setup(pdev, MsConfig)) if (!pdev->complete_msconfig_setup(pdev, MsConfig))
{ {
@@ -657,7 +673,14 @@ static UINT urb_select_interface(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callb
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
pdev->select_interface(pdev, MsInterface->InterfaceNumber, MsInterface->AlternateSetting); const int lerr =
pdev->select_interface(pdev, MsInterface->InterfaceNumber, MsInterface->AlternateSetting);
if (lerr != 0)
{
msusb_msinterface_free(MsInterface);
return ERROR_INTERNAL_ERROR;
}
/* replace device's MsInterface */ /* replace device's MsInterface */
MSUSB_CONFIG_DESCRIPTOR* MsConfig = pdev->get_MsConfig(pdev); MSUSB_CONFIG_DESCRIPTOR* MsConfig = pdev->get_MsConfig(pdev);
const uint8_t InterfaceNumber = MsInterface->InterfaceNumber; const uint8_t InterfaceNumber = MsInterface->InterfaceNumber;
@@ -1982,7 +2005,11 @@ UINT urbdrc_process_udev_data_transfer(GENERIC_CHANNEL_CALLBACK* callback, URBDR
} }
/* USB kernel driver detach!! */ /* USB kernel driver detach!! */
pdev->detach_kernel_driver(pdev); if (!pdev->detach_kernel_driver(pdev))
{
error = ERROR_SUCCESS;
goto fail;
}
switch (FunctionId) switch (FunctionId)
{ {

View File

@@ -1169,7 +1169,11 @@ static void libusb_udev_mark_channel_closed(IUDEVICE* idev)
pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED; pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED;
pdev->iface.cancel_all_transfer_request(&pdev->iface); pdev->iface.cancel_all_transfer_request(&pdev->iface);
urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr); if (!urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr))
{
WLog_Print(pdev->urbdrc->log, WLOG_WARN, "unregister_udevice failed for %d, %d", busNr,
devNr);
}
} }
} }
@@ -1192,9 +1196,15 @@ static void libusb_udev_channel_closed(IUDEVICE* idev)
pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED; pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED;
if (channel) if (channel)
channel->Write(channel, 0, NULL, NULL); {
const UINT rc = channel->Write(channel, 0, NULL, NULL);
if (rc != CHANNEL_RC_OK)
WLog_Print(urbdrc->log, WLOG_WARN, "channel->Write failed with %" PRIu32, rc);
}
urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr); if (!urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr))
WLog_Print(urbdrc->log, WLOG_WARN, "unregister_udevice failed for %d, %d", busNr,
devNr);
} }
} }
@@ -1562,7 +1572,8 @@ static void udev_free(IUDEVICE* idev)
Sleep(100); Sleep(100);
/* release all interface and attach kernel driver */ /* release all interface and attach kernel driver */
udev->iface.attach_kernel_driver(idev); if (!udev->iface.attach_kernel_driver(idev))
WLog_Print(udev->urbdrc->log, WLOG_WARN, "attach_kernel_driver failed for device");
ArrayList_Free(udev->request_queue); ArrayList_Free(udev->request_queue);
/* free the config descriptor that send from windows */ /* free the config descriptor that send from windows */
msusb_msconfig_free(udev->MsConfig); msusb_msconfig_free(udev->MsConfig);

View File

@@ -350,7 +350,9 @@ static UINT urdbrc_send_usb_device_add(GENERIC_CHANNEL_CALLBACK* callback, IUDEV
size_t nrCompatIds = 3; size_t nrCompatIds = 3;
/* USB kernel driver detach!! */ /* USB kernel driver detach!! */
pdev->detach_kernel_driver(pdev); if (!pdev->detach_kernel_driver(pdev))
return ERROR_INTERNAL_ERROR;
{ {
const UINT16 idVendor = (UINT16)pdev->query_device_descriptor(pdev, ID_VENDOR); const UINT16 idVendor = (UINT16)pdev->query_device_descriptor(pdev, ID_VENDOR);
const UINT16 idProduct = (UINT16)pdev->query_device_descriptor(pdev, ID_PRODUCT); const UINT16 idProduct = (UINT16)pdev->query_device_descriptor(pdev, ID_PRODUCT);
@@ -505,7 +507,8 @@ static UINT urbdrc_device_control_channel(GENERIC_CHANNEL_CALLBACK* callback,
case INIT_CHANNEL_IN: case INIT_CHANNEL_IN:
/* Control channel was established */ /* Control channel was established */
error = ERROR_SUCCESS; error = ERROR_SUCCESS;
udevman->initialize(udevman, channelId); if (!udevman->initialize(udevman, channelId))
goto fail;
if (!urbdrc_announce_devices(udevman)) if (!urbdrc_announce_devices(udevman))
goto fail; goto fail;

View File

@@ -716,8 +716,9 @@ static void video_timer(VideoClientContext* video, UINT64 now)
memcpy(presentation->surface->data, frame->surfaceData, 1ull * frame->scanline * frame->h); memcpy(presentation->surface->data, frame->surfaceData, 1ull * frame->scanline * frame->h);
WINPR_ASSERT(video->showSurface); WINPR_ASSERT(video->showSurface);
video->showSurface(video, presentation->surface, presentation->ScaledWidth, if (!video->showSurface(video, presentation->surface, presentation->ScaledWidth,
presentation->ScaledHeight); presentation->ScaledHeight))
WLog_WARN(TAG, "showSurface failed");
VideoFrame_free(&frame); VideoFrame_free(&frame);
} }
@@ -872,8 +873,9 @@ static UINT video_VideoData(VideoClientContext* context, const TSMM_VIDEO_DATA*
return CHANNEL_RC_OK; return CHANNEL_RC_OK;
WINPR_ASSERT(context->showSurface); WINPR_ASSERT(context->showSurface);
context->showSurface(context, presentation->surface, presentation->ScaledWidth, if (!context->showSurface(context, presentation->surface, presentation->ScaledWidth,
presentation->ScaledHeight); presentation->ScaledHeight))
return CHANNEL_RC_NOT_INITIALIZED;
priv->publishedFrames++; priv->publishedFrames++;