Change in simtrace2[master]: USB: print decoded USB error

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Tue Jul 24 08:00:01 UTC 2018


Kévin Redon has uploaded this change for review. ( https://gerrit.osmocom.org/10125


Change subject: USB: print decoded USB error
......................................................................

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
---
M host/libusb_util.c
1 file changed, 10 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/25/10125/1

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 @@
 		    (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;
 			}
 		}

-- 
To view, visit https://gerrit.osmocom.org/10125
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7f20e3eff03acf77eb08283747ca8e032b9b4c8
Gerrit-Change-Number: 10125
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180724/2485b8b5/attachment.htm>


More information about the gerrit-log mailing list