aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/libusb1_base.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-09-24 18:14:32 -0700
committerJosh Blum <josh@joshknows.com>2010-09-24 18:14:32 -0700
commit1dffd5bb5fe16cd35ba54e44e927888e0192e905 (patch)
tree08da412307cd9aecb885671035db5b8b68eb2978 /host/lib/transport/libusb1_base.cpp
parentf2f4840ff9e15ed21344a5a19d676d548b542e91 (diff)
downloaduhd-1dffd5bb5fe16cd35ba54e44e927888e0192e905.tar.gz
uhd-1dffd5bb5fe16cd35ba54e44e927888e0192e905.tar.bz2
uhd-1dffd5bb5fe16cd35ba54e44e927888e0192e905.zip
usb: tweaks to usb code to cleanup properly and/or in error conditions
Diffstat (limited to 'host/lib/transport/libusb1_base.cpp')
-rw-r--r--host/lib/transport/libusb1_base.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp
index 1f816c6e2..cd3e4adcf 100644
--- a/host/lib/transport/libusb1_base.cpp
+++ b/host/lib/transport/libusb1_base.cpp
@@ -30,9 +30,7 @@ using namespace uhd::transport;
**********************************************************/
void libusb::init(libusb_context **ctx, int debug_level)
{
- if (libusb_init(ctx) < 0)
- std::cerr << "error: libusb_init" << std::endl;
-
+ UHD_ASSERT_THROW(libusb_init(ctx) == 0);
libusb_set_debug(*ctx, debug_level);
}
@@ -48,14 +46,13 @@ libusb_device_handle *libusb::open_device(libusb_context *ctx,
libusb_device *dev = libusb_dev_list[i];
if (compare_device(dev, handle)) {
- libusb_open(dev, &dev_handle);
- libusb_unref_device(dev);
- break;
+ if (libusb_open(dev, &dev_handle) == 0) break;
}
-
- libusb_unref_device(dev);
}
+ libusb_free_device_list(libusb_dev_list, true);
+ if(dev_handle == NULL)
+ throw std::runtime_error("USB: cannot open device handle");
return dev_handle;
}
@@ -70,12 +67,12 @@ bool libusb::compare_device(libusb_device *dev,
boost::uint16_t device_addr = handle->get_device_addr();
libusb_device_descriptor libusb_desc;
- if (libusb_get_device_descriptor(dev, &libusb_desc) < 0)
+ if (libusb_get_device_descriptor(dev, &libusb_desc) != 0)
return false;
if (vendor_id != libusb_desc.idVendor)
return false;
if (product_id != libusb_desc.idProduct)
- return false;
+ return false;
if (serial != get_serial(dev))
return false;
if (device_addr != libusb_get_device_address(dev))