aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-07-24 09:57:16 +0200
committerKévin Redon <kredon@sysmocom.de>2018-07-24 09:57:23 +0200
commit352809992cfbe748dba7b5b565fcd2bc3dbeac6d (patch)
tree3e14782f61ac38dbda3478532f4c6314e9025551
parenta71a6f48cbc996bdc30216e4c452d8db8db053ab (diff)
USB: print decoded USB error
In case of error it also ensures the returned value is NULL. Else a segfault would occur because the caller (e.g. remsim) continued on with a free handler. Change-Id: Ie7f20e3eff03acf77eb08283747ca8e032b9b4c8
-rw-r--r--host/libusb_util.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/host/libusb_util.c b/host/libusb_util.c
index 8565372..cb435e2 100644
--- a/host/libusb_util.c
+++ b/host/libusb_util.c
@@ -250,34 +250,39 @@ libusb_device_handle *usb_open_claim_interface(libusb_context *ctx,
(strlen(ifm->path) && !strcmp(path, ifm->path))) {
rc = libusb_open(*dev, &usb_devh);
if (rc < 0) {
- perror("Cannot open device");
+ fprintf(stderr, "Cannot open device: %s\n", libusb_error_name(rc));
+ usb_devh = NULL;
break;
}
rc = libusb_get_configuration(usb_devh, &config);
if (rc < 0) {
- perror("Cannot get current configuration");
+ fprintf(stderr, "Cannot get current configuration: %s\n", libusb_error_name(rc));
libusb_close(usb_devh);
+ usb_devh = NULL;
break;
}
if (config != ifm->configuration) {
rc = libusb_set_configuration(usb_devh, ifm->configuration);
if (rc < 0) {
- perror("Cannot set configuration");
+ fprintf(stderr, "Cannot set configuration: %s\n", libusb_error_name(rc));
libusb_close(usb_devh);
+ usb_devh = NULL;
break;
}
}
rc = libusb_claim_interface(usb_devh, ifm->interface);
if (rc < 0) {
- perror("Cannot claim interface");
+ fprintf(stderr, "Cannot claim interface: %s\n", libusb_error_name(rc));
libusb_close(usb_devh);
+ usb_devh = NULL;
break;
}
rc = libusb_set_interface_alt_setting(usb_devh, ifm->interface, ifm->altsetting);
if (rc < 0) {
- perror("Cannot set interface altsetting");
+ fprintf(stderr, "Cannot set interface altsetting: %s\n", libusb_error_name(rc));
libusb_release_interface(usb_devh, ifm->interface);
libusb_close(usb_devh);
+ usb_devh = NULL;
break;
}
}