From 2bb4878fcc5ccc152634087f0aa13ab1eec56de0 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Mon, 20 Apr 2015 17:09:19 +0200 Subject: [PATCH] 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. --- src/am7xxx.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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); -- 2.1.4