(wiiusb_hid.c) Prevent crashes
This commit is contained in:
parent
a0a3bff54b
commit
66f189dff6
|
@ -75,7 +75,8 @@ static void wiiusb_hid_process_control_message(struct wiiusb_adapter* adapter)
|
|||
do
|
||||
{
|
||||
r = USB_WriteIntrMsg(adapter->handle,
|
||||
adapter->endpoint_out, adapter->send_control_size, adapter->send_control_buffer);
|
||||
adapter->endpoint_out, adapter->send_control_size,
|
||||
adapter->send_control_buffer);
|
||||
} while (r < 0);
|
||||
break;
|
||||
case WIIUSB_SC_CTRLMSG:
|
||||
|
@ -145,8 +146,12 @@ static void wiiusb_hid_device_add_autodetect(unsigned idx,
|
|||
params.vid = dev_vid;
|
||||
params.pid = dev_pid;
|
||||
params.display_name[0] = '\0';
|
||||
params.name[0] = '\0';
|
||||
params.driver[0] = '\0';
|
||||
|
||||
if (!string_is_empty(device_name))
|
||||
strlcpy(params.name, device_name, sizeof(params.name));
|
||||
if (!string_is_empty(driver_name))
|
||||
strlcpy(params.driver, driver_name, sizeof(params.driver));
|
||||
|
||||
input_autoconfigure_connect(¶ms);
|
||||
|
@ -231,9 +236,8 @@ static int wiiusb_hid_remove_adapter(struct wiiusb_adapter *adapter)
|
|||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (adapter->handle > 0) {
|
||||
if (adapter->handle > 0)
|
||||
USB_CloseDevice(&adapter->handle);
|
||||
}
|
||||
|
||||
wiiusb_hid_release_adapter(adapter);
|
||||
|
||||
|
@ -340,6 +344,7 @@ static int wiiusb_hid_add_adapter(void *data, usb_device_entry *dev)
|
|||
|
||||
/* Get the name from the interface */
|
||||
device_name = wiiusb_hid_joypad_name(hid, adapter->slot);
|
||||
|
||||
RARCH_LOG("Interface found: [%s].\n", device_name);
|
||||
|
||||
RARCH_LOG("Device 0x%p attached (VID/PID: %04x:%04x).\n",
|
||||
|
@ -363,7 +368,8 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static bool wiiusb_hid_new_device(wiiusb_hid_t *hid, int32_t id) {
|
||||
static bool wiiusb_hid_new_device(wiiusb_hid_t *hid, int32_t id)
|
||||
{
|
||||
struct wiiusb_adapter *temp;
|
||||
|
||||
if(!hid)
|
||||
|
@ -385,9 +391,8 @@ static void wiiusb_hid_scan_for_devices(wiiusb_hid_t *hid)
|
|||
{
|
||||
unsigned i;
|
||||
u8 count;
|
||||
usb_device_entry *dev_entries;
|
||||
|
||||
dev_entries = (usb_device_entry *)calloc(MAX_USERS, sizeof(*dev_entries));
|
||||
usb_device_entry *dev_entries = (usb_device_entry *)
|
||||
calloc(MAX_USERS, sizeof(*dev_entries));
|
||||
|
||||
if (!dev_entries)
|
||||
goto error;
|
||||
|
@ -413,7 +418,7 @@ error:
|
|||
static void wiiusb_hid_poll_thread(void *data)
|
||||
{
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
struct wiiusb_adapter *adapter;
|
||||
struct wiiusb_adapter *adapter = NULL;
|
||||
|
||||
if (!hid)
|
||||
return;
|
||||
|
@ -433,18 +438,19 @@ static void wiiusb_hid_poll_thread(void *data)
|
|||
/* process each active adapter */
|
||||
for (adapter = hid->adapters_head; adapter; adapter=adapter->next)
|
||||
{
|
||||
if (!adapter->busy)
|
||||
{
|
||||
if (adapter->busy)
|
||||
continue;
|
||||
|
||||
/* lock itself while writing or reading */
|
||||
adapter->busy = true;
|
||||
|
||||
if (adapter->send_control_type)
|
||||
wiiusb_hid_process_control_message(adapter);
|
||||
|
||||
USB_ReadIntrMsgAsync(adapter->handle, adapter->endpoint_in, adapter->endpoint_in_max_size,
|
||||
USB_ReadIntrMsgAsync(adapter->handle, adapter->endpoint_in,
|
||||
adapter->endpoint_in_max_size,
|
||||
adapter->data, wiiusb_hid_read_cb, adapter);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait 10 milliseconds to process again */
|
||||
usleep(10000);
|
||||
|
@ -458,12 +464,10 @@ static int wiiusb_hid_change_cb(int result, void *usrdata)
|
|||
if (!hid)
|
||||
return -1;
|
||||
|
||||
if (!hid->removal_cb)
|
||||
{
|
||||
/* As it's not coming from the removal callback
|
||||
then we detected a new device being inserted */
|
||||
if (!hid->removal_cb)
|
||||
hid->device_detected = true;
|
||||
}
|
||||
else
|
||||
hid->removal_cb = false;
|
||||
|
||||
|
@ -515,8 +519,8 @@ static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad,
|
|||
static int16_t wiiusb_hid_joypad_axis(void *data,
|
||||
unsigned port, uint32_t joyaxis)
|
||||
{
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
int16_t val = 0;
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
|
||||
if (joyaxis == AXIS_NONE)
|
||||
return 0;
|
||||
|
@ -543,16 +547,20 @@ static int16_t wiiusb_hid_joypad_axis(void *data,
|
|||
|
||||
static void wiiusb_hid_free(void *data)
|
||||
{
|
||||
struct wiiusb_adapter *adapter = NULL;
|
||||
struct wiiusb_adapter *next_adapter = NULL;
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
|
||||
struct wiiusb_adapter *adapter, *next_adapter;
|
||||
|
||||
if (!hid)
|
||||
return;
|
||||
|
||||
hid->poll_thread_quit = true;
|
||||
|
||||
if (hid->poll_thread)
|
||||
sthread_join(hid->poll_thread);
|
||||
|
||||
hid->manual_removal = TRUE;
|
||||
|
||||
/* remove each of the adapters */
|
||||
for (adapter = hid->adapters_head; adapter; adapter = next_adapter)
|
||||
{
|
||||
|
@ -567,17 +575,19 @@ static void wiiusb_hid_free(void *data)
|
|||
|
||||
static void *wiiusb_hid_init(void)
|
||||
{
|
||||
joypad_connection_t *connections = NULL;
|
||||
wiiusb_hid_t *hid = (wiiusb_hid_t*)calloc(1, sizeof(*hid));
|
||||
|
||||
if (!hid)
|
||||
goto error;
|
||||
|
||||
hid->connections = pad_connection_init(MAX_USERS);
|
||||
connections = pad_connection_init(MAX_USERS);
|
||||
|
||||
if (!hid->connections)
|
||||
if (!connections)
|
||||
goto error;
|
||||
|
||||
/* Init hid values */
|
||||
/* Initialize HID values */
|
||||
hid->connections = connections;
|
||||
hid->adapters_head = NULL;
|
||||
hid->removal_cb = FALSE;
|
||||
hid->manual_removal = FALSE;
|
||||
|
|
Loading…
Reference in New Issue