]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/chronovu-la/api.c
chronovu-la: Add checking of VendorId
[libsigrok.git] / src / hardware / chronovu-la / api.c
index 3d19b4f06941ce4b20f51a4b6d63a3d0b387651e..53c94fdd179e4c82b329314d316e96a78e5dcdd9 100644 (file)
@@ -20,6 +20,8 @@
 #include <config.h>
 #include "protocol.h"
 
+#define CHRONOVU_VENDOR (0x0403)
+
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
 };
@@ -169,6 +171,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor(devlist[i], &des);
 
+               /* See https://sigrok.org/bugzilla/show_bug.cgi?id=1115 and
+                * https://github.com/sigrokproject/libsigrok/pull/166 */
+               if (des.idVendor != CHRONOVU_VENDOR)
+                       continue;
+
                if ((ret = libusb_open(devlist[i], &hdl)) < 0)
                        continue;
 
@@ -192,10 +199,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        continue;
                }
 
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
-
                libusb_close(hdl);
 
+               if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                       continue;
+
                if (!strcmp(product, "ChronoVu LA8"))
                        model = 0;
                else if (!strcmp(product, "ChronoVu LA16"))
@@ -242,7 +250,7 @@ static int dev_open(struct sr_dev_inst *sdi)
                goto err_ftdi_free;
        }
 
-       if ((ret = ftdi_usb_purge_buffers(devc->ftdic)) < 0) {
+       if ((ret = PURGE_FTDI_BOTH(devc->ftdic)) < 0) {
                sr_err("Failed to purge FTDI buffers (%d): %s.",
                       ret, ftdi_get_error_string(devc->ftdic));
                goto err_ftdi_free;
@@ -351,12 +359,12 @@ static int config_list(uint32_t key, GVariant **data,
                *data = std_gvar_samplerates(ARRAY_AND_SIZE(devc->samplerates));
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               if (!devc->prof)
+               if (!devc || !devc->prof)
                        return SR_ERR_BUG;
                *data = std_gvar_tuple_u64(0, (devc->prof->model == CHRONOVU_LA8) ? MAX_NUM_SAMPLES : MAX_NUM_SAMPLES / 2);
                break;
        case SR_CONF_TRIGGER_MATCH:
-               if (!devc->prof)
+               if (!devc || !devc->prof)
                        return SR_ERR_BUG;
                *data = std_gvar_array_i32(trigger_matches, devc->prof->num_trigger_matches);
                break;