]> sigrok.org Git - libsigrok.git/commitdiff
chronovu-la: rephrase conn= checking in the scan routine
authorGerhard Sittig <redacted>
Thu, 28 Sep 2023 18:21:24 +0000 (20:21 +0200)
committerGerhard Sittig <redacted>
Mon, 9 Oct 2023 16:39:40 +0000 (18:39 +0200)
Prefer common support over DIY code to get the SR_CONF_CONN spec.
Simplify the check during USB enumeration whether a user provided
conn= spec applies. Sort local var decls to match their use. Setup
resulting 'devices' early.

src/hardware/chronovu-la/api.c

index 53c94fdd179e4c82b329314d316e96a78e5dcdd9..5ed496b0bf0c73c14cdc300b102a64d927adc455 100644 (file)
@@ -125,47 +125,41 @@ err_free_devc:
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
-       int i, ret, model;
        struct drv_context *drvc;
-       GSList *devices, *conn_devices, *l;
+       GSList *devices;
+       const char *conn;
+       int ret;
+       GSList *conn_devices, *l;
+       size_t i;
        struct sr_usb_dev_inst *usb;
-       struct sr_config *src;
+       uint8_t bus, addr;
        struct libusb_device_descriptor des;
        libusb_device **devlist;
        struct libusb_device_handle *hdl;
-       const char *conn;
        char product[64], serial_num[64], connection_id[64];
+       int model;
 
        drvc = di->context;
+       devices = NULL;
 
        conn = NULL;
-       for (l = options; l; l = l->next) {
-               src = l->data;
-               switch (src->key) {
-               case SR_CONF_CONN:
-                       conn = g_variant_get_string(src->data, NULL);
-                       break;
-               }
-       }
+       (void)sr_serial_extract_options(options, &conn, NULL);
+       conn_devices = NULL;
        if (conn)
                conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
-       else
-               conn_devices = NULL;
 
-       devices = NULL;
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
-
        for (i = 0; devlist[i]; i++) {
+               bus = libusb_get_bus_number(devlist[i]);
+               addr = libusb_get_device_address(devlist[i]);
                if (conn) {
+                       /* Check if the connection matches the user spec. */
                        for (l = conn_devices; l; l = l->next) {
                                usb = l->data;
-                               if (usb->bus == libusb_get_bus_number(devlist[i])
-                                       && usb->address == libusb_get_device_address(devlist[i]))
+                               if (usb->bus == bus && usb->address == addr)
                                        break;
                        }
                        if (!l)
-                               /* This device matched none of the ones that
-                                * matched the conn specification. */
                                continue;
                }
 
@@ -221,7 +215,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        sr_dbg("Failed to add device: %d.", ret);
                }
        }
-
        libusb_free_device_list(devlist, 1);
        g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);