From: Bert Vermeulen Date: Sat, 19 Sep 2015 15:59:54 +0000 (+0200) Subject: No need to check return value of libusb_get_device_descriptor(). X-Git-Tag: libsigrok-0.4.0~270 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=2a8f2d41adcd0aa9e498c4eea2a5f82263039e5c No need to check return value of libusb_get_device_descriptor(). Since libusb 1.0.16 this is guaranteed to always succeed. This fixes bug #658. --- diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index ed440537..16ab9be0 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -228,11 +228,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; } - if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) { - sr_warn("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor( devlist[i], &des); if ((ret = libusb_open(devlist[i], &hdl)) < 0) continue; diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index 32a65c50..12fc9e2c 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -157,8 +157,7 @@ SR_PRIV gboolean match_manuf_prod(libusb_device *dev, const char *manufacturer, ret = FALSE; while (!ret) { /* Assume the FW has not been loaded, unless proven wrong. */ - if (libusb_get_device_descriptor(dev, &des) != 0) - break; + libusb_get_device_descriptor(dev, &des); if (libusb_open(dev, &hdl) != 0) break; @@ -211,11 +210,7 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) } for (i = 0; i < device_count; i++) { - if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != devc->profile->vid || des.idProduct != devc->profile->pid) diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 4e8ac83f..b05e644a 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -270,7 +270,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; - int ret, i, j; + int i, j; const char *conn; char connection_id[64]; @@ -308,11 +308,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; } - if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); diff --git a/src/hardware/hantek-dso/dso.c b/src/hardware/hantek-dso/dso.c index 79c16008..8561ac3d 100644 --- a/src/hardware/hantek-dso/dso.c +++ b/src/hardware/hantek-dso/dso.c @@ -76,8 +76,7 @@ static int dso_getmps(libusb_device *dev) const struct libusb_interface_descriptor *intf_dsc; int mps; - if (libusb_get_device_descriptor(dev, &des) != 0) - return 0; + libusb_get_device_descriptor(dev, &des); if (des.bNumConfigurations != 1) return 0; @@ -128,11 +127,7 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi) libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { - if ((err = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(err)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != devc->profile->fw_vid || des.idProduct != devc->profile->fw_pid) diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 95b28f12..9d523144 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -111,8 +111,7 @@ static gboolean check_conf_profile(libusb_device *dev) ret = FALSE; while (!ret) { /* Assume the FW has not been loaded, unless proven wrong. */ - if (libusb_get_device_descriptor(dev, &des) != 0) - break; + libusb_get_device_descriptor(dev, &des); if (libusb_open(dev, &hdl) != 0) break; @@ -148,7 +147,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; - int ret; unsigned int i, j; const char *conn; char connection_id[64]; @@ -187,11 +185,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; } - if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) { - sr_warn("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); @@ -272,11 +266,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) } for (i = 0; i < device_count; i++) { - if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID) continue; diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 6907ba4e..0c37886e 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -92,11 +92,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; } - if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) { - sr_warn("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if ((ret = libusb_open(devlist[i], &hdl)) < 0) continue; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 6f7416ce..8e8f0276 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -63,7 +63,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct libusb_device_descriptor des; libusb_device **devlist; GSList *devices; - int ret, i; + int i; char connection_id[64]; (void)options; @@ -73,11 +73,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { - if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) { - sr_warn("Failed to get device descriptor: %s", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != VICTOR_VID || des.idProduct != VICTOR_PID) continue; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 7886fbbd..50b7df9e 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -183,12 +183,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); /* TODO: Errors. */ for (i = 0; devlist[i]; i++) { - ret = libusb_get_device_descriptor(devlist[i], &des); - if (ret != 0) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if ((ret = libusb_open(devlist[i], &hdl)) < 0) continue; diff --git a/src/scpi/scpi_usbtmc_libusb.c b/src/scpi/scpi_usbtmc_libusb.c index a6eb922b..d54ea40c 100644 --- a/src/scpi/scpi_usbtmc_libusb.c +++ b/src/scpi/scpi_usbtmc_libusb.c @@ -114,11 +114,7 @@ static GSList *scpi_usbtmc_libusb_scan(struct drv_context *drvc) return NULL; } for (i = 0; devlist[i]; i++) { - if ((ret = libusb_get_device_descriptor(devlist[i], &des)) < 0) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); for (confidx = 0; confidx < des.bNumConfigurations; confidx++) { if ((ret = libusb_get_config_descriptor(devlist[i], confidx, &confdes)) < 0) { @@ -198,11 +194,7 @@ static int scpi_usbtmc_libusb_open(void *priv) return SR_ERR; dev = libusb_get_device(usb->devhdl); - if ((ret = libusb_get_device_descriptor(dev, &des)) < 0) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - return SR_ERR; - } + libusb_get_device_descriptor(dev, &des); for (confidx = 0; confidx < des.bNumConfigurations; confidx++) { if ((ret = libusb_get_config_descriptor(dev, confidx, &confdes)) < 0) {