Skip to content

Commit

Permalink
Review adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
k1-801 committed Nov 21, 2023
1 parent 2beb6bd commit 35a5253
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static struct hid_hotplug_context {
struct hid_device_info *devs;
} hid_hotplug_context = {
.notify_handle = NULL,
.mutex = NULL,
.next_handle = 1,
.hotplug_cbs = NULL,
.devs = NULL
Expand Down Expand Up @@ -382,14 +383,16 @@ HID_API_EXPORT const char* HID_API_CALL hid_version_str(void)

int HID_API_EXPORT hid_init(void)
{
register_global_error(NULL);
register_global_error(NULL);
if (!hid_hotplug_context.mutex) {
hid_hotplug_context.mutex = CreateMutexA(NULL, FALSE, NULL);
}
#ifndef HIDAPI_USE_DDK
if (!hidapi_initialized) {
if (lookup_functions() < 0) {
register_global_winapi_error(L"resolve DLL functions");
return -1;
}
hid_hotplug_context.mutex = CreateMutexA(NULL, FALSE, NULL);
}
hidapi_initialized = TRUE;
}
#endif
Expand Down Expand Up @@ -920,7 +923,7 @@ struct hid_hotplug_callback {
struct hid_hotplug_callback *next;
};

static void hid_internal_cleanup_hotplugs()
static int hid_internal_cleanup_hotplugs()
{
/* Unregister a HID device connection notification when removing the last callback */
if (hid_hotplug_context.hotplug_cbs == NULL) {
Expand All @@ -940,6 +943,7 @@ static void hid_internal_cleanup_hotplugs()

hid_hotplug_context.notify_handle = NULL;
}
return 0;
}

DWORD WINAPI hid_internal_notify_callback(HCMNOTIFICATION notify, PVOID context, CM_NOTIFY_ACTION action, PCM_NOTIFY_EVENT_DATA event_data, DWORD event_data_size)
Expand Down Expand Up @@ -1018,9 +1022,9 @@ DWORD WINAPI hid_internal_notify_callback(HCMNOTIFICATION notify, PVOID context,
struct hid_hotplug_callback **current = &hid_hotplug_context.hotplug_cbs;
while (*current) {
struct hid_hotplug_callback *callback = *current;
if ((current->events & hotplug_event) &&
if ((callback->events & hotplug_event) &&
hid_internal_match_device_id(device->vendor_id, device->product_id, callback->vendor_id, callback->product_id)) {
int result = (*cur_hotplug_cb->callback)(callback->handle, device, hotplug_event, callback->user_data);
int result = (callback->callback)(callback->handle, device, hotplug_event, callback->user_data);
/* If the result is non-zero, we remove the callback and proceed */
/* Do not use the deregister call as it locks the mutex, and we are currently in a lock */
if(result) {
Expand Down

0 comments on commit 35a5253

Please sign in to comment.