Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: patches/12_check_for_libusb_init_failures.patch

Issue 11038043: Check for failures from libusb_init() in the libusb-1.0 glue code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libmtp/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/libusb1-glue.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: patches/12_check_for_libusb_init_failures.patch
===================================================================
--- patches/12_check_for_libusb_init_failures.patch (revision 0)
+++ patches/12_check_for_libusb_init_failures.patch (revision 0)
@@ -0,0 +1,76 @@
+Index: src/libusb1-glue.c
+===================================================================
+--- src/libusb1-glue.c (revision 160213)
++++ src/libusb1-glue.c (working copy)
+@@ -84,7 +84,7 @@
+ 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 *interface,
+@@ -125,16 +125,20 @@
+ }
+
+
+-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;
+ }
+
+ /**
+@@ -478,8 +482,11 @@
+ 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++) {
+@@ -551,8 +558,11 @@
+ 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++ ) {
+@@ -1904,9 +1914,12 @@
+ 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++) {
« no previous file with comments | « no previous file | src/libusb1-glue.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698