From: Antonio Ospite Date: Mon, 20 Apr 2015 15:09:19 +0000 (+0200) Subject: am7xxx: check the return value of libusb_get_configuration() X-Git-Tag: v0.1.6~27 X-Git-Url: https://git.ao2.it/libam7xxx.git/commitdiff_plain/2bb4878fcc5ccc152634087f0aa13ab1eec56de0?ds=sidebyside am7xxx: check the return value of libusb_get_configuration() libusb_get_configuration() can still fail after the device has been opened, so check its actual return value before trusting the returned current_configuration. --- diff --git a/src/am7xxx.c b/src/am7xxx.c index 1c3f704..b00a6be 100644 --- a/src/am7xxx.c +++ b/src/am7xxx.c @@ -734,7 +734,14 @@ static int open_device(am7xxx_context *ctx, */ current_configuration = -1; - libusb_get_configuration((*dev)->usb_device, ¤t_configuration); + ret = libusb_get_configuration((*dev)->usb_device, + ¤t_configuration); + if (ret < 0) { + debug(ctx, "libusb_get_configuration failed: %s\n", + libusb_error_name(ret)); + goto out_libusb_close; + } + if (current_configuration != (*dev)->desc->configuration) { /* * In principle kernel drivers bound to each interface should @@ -772,7 +779,14 @@ static int open_device(am7xxx_context *ctx, * http://libusb.sourceforge.net/api-1.0/caveats.html */ current_configuration = -1; - libusb_get_configuration((*dev)->usb_device, ¤t_configuration); + ret = libusb_get_configuration((*dev)->usb_device, + ¤t_configuration); + if (ret < 0) { + debug(ctx, "libusb_get_configuration after claim failed: %s\n", + libusb_error_name(ret)); + goto out_libusb_close; + } + if (current_configuration != (*dev)->desc->configuration) { debug(ctx, "libusb configuration changed (expected: %hhu, current: %hhu\n", (*dev)->desc->configuration, current_configuration);