From eeab51e3a42e74a5f0f6c2211cbff6247a78e4bc Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 8 Jun 2022 12:29:16 -0700 Subject: [PATCH] Log warnings when LibusbUtils::MakeConfigDescriptor fails --- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 9 +++++---- Source/Core/Core/IOS/USB/LibusbDevice.cpp | 10 +++++++++- Source/Core/Core/LibusbUtils.cpp | 11 +++++++---- Source/Core/Core/LibusbUtils.h | 3 ++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 8619d8766e..234c1ecc13 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -87,11 +87,12 @@ std::optional BluetoothRealDevice::Open(const OpenRequest& request) const int ret = m_context.GetDeviceList([this](libusb_device* device) { libusb_device_descriptor device_descriptor; libusb_get_device_descriptor(device, &device_descriptor); - auto config_descriptor = LibusbUtils::MakeConfigDescriptor(device); - if (!config_descriptor) + auto [ret, config_descriptor] = LibusbUtils::MakeConfigDescriptor(device); + if (ret != LIBUSB_SUCCESS || !config_descriptor) { - ERROR_LOG_FMT(IOS_WIIMOTE, "Failed to get config descriptor for device {:04x}:{:04x}", - device_descriptor.idVendor, device_descriptor.idProduct); + ERROR_LOG_FMT(IOS_WIIMOTE, "Failed to get config descriptor for device {:04x}:{:04x}: {}", + device_descriptor.idVendor, device_descriptor.idProduct, + LibusbUtils::ErrorWrap(ret)); return true; } diff --git a/Source/Core/Core/IOS/USB/LibusbDevice.cpp b/Source/Core/Core/IOS/USB/LibusbDevice.cpp index 5d90585083..f46268a80b 100644 --- a/Source/Core/Core/IOS/USB/LibusbDevice.cpp +++ b/Source/Core/Core/IOS/USB/LibusbDevice.cpp @@ -36,7 +36,15 @@ LibusbDevice::LibusbDevice(Kernel& ios, libusb_device* device, static_cast(libusb_get_device_address(device))); for (u8 i = 0; i < descriptor.bNumConfigurations; ++i) - m_config_descriptors.emplace_back(LibusbUtils::MakeConfigDescriptor(m_device, i)); + { + auto [ret, config_descriptor] = LibusbUtils::MakeConfigDescriptor(m_device, i); + if (ret != LIBUSB_SUCCESS || !config_descriptor) + { + WARN_LOG_FMT(IOS_USB, "Failed to make config descriptor {} for {:04x}:{:04x}: {}", i, m_vid, + m_pid, LibusbUtils::ErrorWrap(ret)); + } + m_config_descriptors.emplace_back(std::move(config_descriptor)); + } } LibusbDevice::~LibusbDevice() diff --git a/Source/Core/Core/LibusbUtils.cpp b/Source/Core/Core/LibusbUtils.cpp index f716cc4884..1b1852dddd 100644 --- a/Source/Core/Core/LibusbUtils.cpp +++ b/Source/Core/Core/LibusbUtils.cpp @@ -115,14 +115,17 @@ int Context::GetDeviceList(GetDeviceListCallback callback) const return m_impl->GetDeviceList(std::move(callback)); } -ConfigDescriptor MakeConfigDescriptor(libusb_device* device, u8 config_num) +std::pair MakeConfigDescriptor(libusb_device* device, u8 config_num) { #if defined(__LIBUSB__) libusb_config_descriptor* descriptor = nullptr; - if (libusb_get_config_descriptor(device, config_num, &descriptor) == LIBUSB_SUCCESS) - return {descriptor, libusb_free_config_descriptor}; + const int ret = libusb_get_config_descriptor(device, config_num, &descriptor); + if (ret == LIBUSB_SUCCESS) + return {ret, ConfigDescriptor{descriptor, libusb_free_config_descriptor}}; +#else + const int ret = -1; #endif - return {nullptr, [](auto) {}}; + return {ret, ConfigDescriptor{nullptr, [](auto) {}}}; } const char* ErrorWrap::GetName() const diff --git a/Source/Core/Core/LibusbUtils.h b/Source/Core/Core/LibusbUtils.h index 4fe3c0289f..89fba398dd 100644 --- a/Source/Core/Core/LibusbUtils.h +++ b/Source/Core/Core/LibusbUtils.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "Common/CommonTypes.h" @@ -39,7 +40,7 @@ private: }; using ConfigDescriptor = UniquePtr; -ConfigDescriptor MakeConfigDescriptor(libusb_device* device, u8 config_num = 0); +std::pair MakeConfigDescriptor(libusb_device* device, u8 config_num = 0); // Wrapper for libusb_error to be used with fmt. Note that we can't create a fmt::formatter // directly for libusb_error as it is a plain enum and most libusb functions actually return an