summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_adapter.cpp
diff options
context:
space:
mode:
authorGravatar Ameer2020-07-08 14:18:54 -0400
committerGravatar Ameer2020-07-08 14:18:54 -0400
commit3c7a115afe0590fd6358767942340eb807f9b81d (patch)
tree7954a988d1881123a939b92c5984fce2b491ccfd /src/input_common/gcadapter/gc_adapter.cpp
parentAdd more libusb error checks (diff)
downloadyuzu-3c7a115afe0590fd6358767942340eb807f9b81d.tar.gz
yuzu-3c7a115afe0590fd6358767942340eb807f9b81d.tar.xz
yuzu-3c7a115afe0590fd6358767942340eb807f9b81d.zip
Address comments for better clarity/signed dev count
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp
index f6e51705b..6d9f4d9eb 100644
--- a/src/input_common/gcadapter/gc_adapter.cpp
+++ b/src/input_common/gcadapter/gc_adapter.cpp
@@ -215,23 +215,27 @@ void Adapter::Setup() {
215 adapter_controllers_status.fill(ControllerTypes::None); 215 adapter_controllers_status.fill(ControllerTypes::None);
216 216
217 // pointer to list of connected usb devices 217 // pointer to list of connected usb devices
218 libusb_device** devices; 218 libusb_device** devices{};
219 219
220 // populate the list of devices, get the count 220 // populate the list of devices, get the count
221 const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices); 221 const ssize_t device_count = libusb_get_device_list(libusb_ctx, &devices);
222 if (device_count < 0) { 222 if (device_count < 0) {
223 LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count); 223 LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count);
224 detect_thread_running = false; // Stop the loop constantly checking for gc adapter
225 // TODO: For hotplug+gc adapter checkbox implementation, revert this.
224 return; 226 return;
225 } 227 }
226 228
227 for (std::size_t index = 0; index < device_count; ++index) { 229 if (devices != nullptr) {
228 if (CheckDeviceAccess(devices[index])) { 230 for (std::size_t index = 0; index < device_count; ++index) {
229 // GC Adapter found and accessible, registering it 231 if (CheckDeviceAccess(devices[index])) {
230 GetGCEndpoint(devices[index]); 232 // GC Adapter found and accessible, registering it
231 break; 233 GetGCEndpoint(devices[index]);
234 break;
235 }
232 } 236 }
237 libusb_free_device_list(devices, 1);
233 } 238 }
234 libusb_free_device_list(devices, 1);
235} 239}
236 240
237bool Adapter::CheckDeviceAccess(libusb_device* device) { 241bool Adapter::CheckDeviceAccess(libusb_device* device) {
@@ -288,10 +292,10 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
288 292
289void Adapter::GetGCEndpoint(libusb_device* device) { 293void Adapter::GetGCEndpoint(libusb_device* device) {
290 libusb_config_descriptor* config = nullptr; 294 libusb_config_descriptor* config = nullptr;
291 const int config_descriptor_error = libusb_get_config_descriptor(device, 0, &config); 295 const int config_descriptor_return = libusb_get_config_descriptor(device, 0, &config);
292 if (config_descriptor_error) { 296 if (config_descriptor_return != LIBUSB_SUCCESS) {
293 LOG_ERROR(Input, "libusb_get_config_descriptor failed with error = {}", 297 LOG_ERROR(Input, "libusb_get_config_descriptor failed with error = {}",
294 config_descriptor_error); 298 config_descriptor_return);
295 return; 299 return;
296 } 300 }
297 301