Log warnings when LibusbUtils::MakeConfigDescriptor fails

This commit is contained in:
Pokechu22 2022-06-08 12:29:16 -07:00
parent 15cbb5c8f9
commit eeab51e3a4
4 changed files with 23 additions and 10 deletions

View File

@ -87,11 +87,12 @@ std::optional<IPCReply> 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;
}

View File

@ -36,7 +36,15 @@ LibusbDevice::LibusbDevice(Kernel& ios, libusb_device* device,
static_cast<u64>(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()

View File

@ -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<int, ConfigDescriptor> 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

View File

@ -6,6 +6,7 @@
#include <fmt/format.h>
#include <functional>
#include <memory>
#include <utility>
#include "Common/CommonTypes.h"
@ -39,7 +40,7 @@ private:
};
using ConfigDescriptor = UniquePtr<libusb_config_descriptor>;
ConfigDescriptor MakeConfigDescriptor(libusb_device* device, u8 config_num = 0);
std::pair<int, ConfigDescriptor> 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