From 5d0f1bd10b1af825a80ab78160fe7c9924e835e9 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sun, 2 Jul 2023 20:07:37 -0700 Subject: [PATCH] Switch libusb_config_descriptor to RAII type --- Source/Core/InputCommon/GCAdapter.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index bb1542988e..ec3c3a1fb3 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -625,8 +625,8 @@ static bool CheckDeviceAccess(libusb_device* device) static void AddGCAdapter(libusb_device* device) { - libusb_config_descriptor* config = nullptr; - if (const int error = libusb_get_config_descriptor(device, 0, &config); error != LIBUSB_SUCCESS) + auto [error, config] = LibusbUtils::MakeConfigDescriptor(device); + if (error != LIBUSB_SUCCESS) { WARN_LOG_FMT(CONTROLLERINTERFACE, "libusb_get_config_descriptor failed: {}", LibusbUtils::ErrorWrap(error)); @@ -647,13 +647,12 @@ static void AddGCAdapter(libusb_device* device) } } } - libusb_free_config_descriptor(config); + config.reset(); int size = 0; std::array payload = {0x13}; - const int error = - libusb_interrupt_transfer(s_handle, s_endpoint_out, payload.data(), - CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS); + error = libusb_interrupt_transfer(s_handle, s_endpoint_out, payload.data(), + CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS); if (error != LIBUSB_SUCCESS) { WARN_LOG_FMT(CONTROLLERINTERFACE, "AddGCAdapter: libusb_interrupt_transfer failed: {}",