From: Gerhard Sittig Date: Thu, 28 Sep 2023 18:21:24 +0000 (+0200) Subject: chronovu-la: rephrase conn= checking in the scan routine X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=204dd31fa1074a78fbe3bf04208776a4a3615a1c;p=libsigrok.git chronovu-la: rephrase conn= checking in the scan routine 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. --- diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 53c94fdd..5ed496b0 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -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);