diff options
author | Lei Zhang <thestig@google.com> | 2013-02-13 15:15:51 -0800 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2013-03-12 08:41:45 +0100 |
commit | 3df1589b0b5b81484ebc507ac4b96d1e04891d9b (patch) | |
tree | 37098dec680998855c388204cbfb74ee7c9798f2 | |
parent | aeed281f2cc403ee0b8d7e281cffd564e16844c1 (diff) | |
download | libmtp-3df1589b0b5b81484ebc507ac4b96d1e04891d9b.tar.gz |
Check for failures from libusb_init() in the libusb-1.0 glue code.
Signed-off-by: Lei Zhang <thestig@google.com>
Signed-off-by: Linus Walleij <triad@df.lth.se>
-rw-r--r-- | src/libusb1-glue.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/libusb1-glue.c b/src/libusb1-glue.c index 62704d9..df44eac 100644 --- a/src/libusb1-glue.c +++ b/src/libusb1-glue.c @@ -84,7 +84,7 @@ static const LIBMTP_device_entry_t mtp_device_table[] = { static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMTP_device_entry_t); // Local functions -static void init_usb(); +static LIBMTP_error_number_t init_usb(); static void close_usb(PTP_USB* ptp_usb); static int find_interface_and_endpoints(libusb_device *dev, uint8_t *conf, @@ -127,16 +127,20 @@ int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const devices, in } -static void init_usb() +static LIBMTP_error_number_t init_usb() { /* * Some additional libusb debugging please. * We use the same level debug between MTP and USB. */ - libusb_init(NULL); + if (libusb_init(NULL) < 0) { + LIBMTP_ERROR("Libusb1 init failed\n"); + return LIBMTP_ERROR_USB_LAYER; + } if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) libusb_set_debug(NULL,9); + return LIBMTP_ERROR_NONE; } /** @@ -492,8 +496,11 @@ static LIBMTP_error_number_t get_mtp_usb_device_list(mtpdevice_list_t ** mtp_dev ssize_t nrofdevs; libusb_device **devs = NULL; int ret, i; + LIBMTP_error_number_t init_usb_ret; - init_usb(); + init_usb_ret = init_usb(); + if (init_usb_ret != LIBMTP_ERROR_NONE) + return init_usb_ret; nrofdevs = libusb_get_device_list (NULL, &devs); for (i = 0; i < nrofdevs ; i++) { @@ -565,8 +572,11 @@ int LIBMTP_Check_Specific_Device(int busno, int devno) ssize_t nrofdevs; libusb_device **devs = NULL; int i; + LIBMTP_error_number_t init_usb_ret; - init_usb(); + init_usb_ret = init_usb(); + if (init_usb_ret != LIBMTP_ERROR_NONE) + return 0; nrofdevs = libusb_get_device_list (NULL, &devs); for (i = 0; i < nrofdevs ; i++ ) { @@ -1973,9 +1983,12 @@ LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, ssize_t nrofdevs; libusb_device **devs = NULL; struct libusb_device_descriptor desc; + LIBMTP_error_number_t init_usb_ret; /* See if we can find this raw device again... */ - init_usb(); + init_usb_ret = init_usb(); + if (init_usb_ret != LIBMTP_ERROR_NONE) + return init_usb_ret; nrofdevs = libusb_get_device_list(NULL, &devs); for (i = 0; i < nrofdevs ; i++) { |