diff options
| author | 2020-07-08 13:19:33 -0400 | |
|---|---|---|
| committer | 2020-07-08 13:19:33 -0400 | |
| commit | ec13746e4d1adb8567a3d52531ede6f57cde68f7 (patch) | |
| tree | c21737fcbe948b0002ea76b1346f41ef91e4979b /src/input_common/gcadapter/gc_adapter.cpp | |
| parent | Merge pull request #4243 from CrazyMax/display_version (diff) | |
| download | yuzu-ec13746e4d1adb8567a3d52531ede6f57cde68f7.tar.gz yuzu-ec13746e4d1adb8567a3d52531ede6f57cde68f7.tar.xz yuzu-ec13746e4d1adb8567a3d52531ede6f57cde68f7.zip | |
Add more libusb error checks
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index b39d2a3fb..f6e51705b 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -24,9 +24,13 @@ Adapter::Adapter() { | |||
| 24 | LOG_INFO(Input, "GC Adapter Initialization started"); | 24 | LOG_INFO(Input, "GC Adapter Initialization started"); |
| 25 | 25 | ||
| 26 | current_status = NO_ADAPTER_DETECTED; | 26 | current_status = NO_ADAPTER_DETECTED; |
| 27 | libusb_init(&libusb_ctx); | ||
| 28 | 27 | ||
| 29 | StartScanThread(); | 28 | const int init_res = libusb_init(&libusb_ctx); |
| 29 | if (init_res == LIBUSB_SUCCESS) { | ||
| 30 | StartScanThread(); | ||
| 31 | } else { | ||
| 32 | LOG_ERROR(Input, "libusb could not be initialized. failed with error = {}", init_res); | ||
| 33 | } | ||
| 30 | } | 34 | } |
| 31 | 35 | ||
| 32 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { | 36 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { |
| @@ -215,6 +219,10 @@ void Adapter::Setup() { | |||
| 215 | 219 | ||
| 216 | // populate the list of devices, get the count | 220 | // populate the list of devices, get the count |
| 217 | const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices); | 221 | const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices); |
| 222 | if (device_count < 0) { | ||
| 223 | LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count); | ||
| 224 | return; | ||
| 225 | } | ||
| 218 | 226 | ||
| 219 | for (std::size_t index = 0; index < device_count; ++index) { | 227 | for (std::size_t index = 0; index < device_count; ++index) { |
| 220 | if (CheckDeviceAccess(devices[index])) { | 228 | if (CheckDeviceAccess(devices[index])) { |
| @@ -223,6 +231,7 @@ void Adapter::Setup() { | |||
| 223 | break; | 231 | break; |
| 224 | } | 232 | } |
| 225 | } | 233 | } |
| 234 | libusb_free_device_list(devices, 1); | ||
| 226 | } | 235 | } |
| 227 | 236 | ||
| 228 | bool Adapter::CheckDeviceAccess(libusb_device* device) { | 237 | bool Adapter::CheckDeviceAccess(libusb_device* device) { |
| @@ -279,7 +288,13 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { | |||
| 279 | 288 | ||
| 280 | void Adapter::GetGCEndpoint(libusb_device* device) { | 289 | void Adapter::GetGCEndpoint(libusb_device* device) { |
| 281 | libusb_config_descriptor* config = nullptr; | 290 | libusb_config_descriptor* config = nullptr; |
| 282 | libusb_get_config_descriptor(device, 0, &config); | 291 | const int config_descriptor_error = libusb_get_config_descriptor(device, 0, &config); |
| 292 | if (config_descriptor_error) { | ||
| 293 | LOG_ERROR(Input, "libusb_get_config_descriptor failed with error = {}", | ||
| 294 | config_descriptor_error); | ||
| 295 | return; | ||
| 296 | } | ||
| 297 | |||
| 283 | for (u8 ic = 0; ic < config->bNumInterfaces; ic++) { | 298 | for (u8 ic = 0; ic < config->bNumInterfaces; ic++) { |
| 284 | const libusb_interface* interfaceContainer = &config->interface[ic]; | 299 | const libusb_interface* interfaceContainer = &config->interface[ic]; |
| 285 | for (int i = 0; i < interfaceContainer->num_altsetting; i++) { | 300 | for (int i = 0; i < interfaceContainer->num_altsetting; i++) { |