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.
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct drv_context *drvc;
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_usb_dev_inst *usb;
struct libusb_device_descriptor des;
libusb_device **devlist;
struct libusb_device_handle *hdl;
struct libusb_device_descriptor des;
libusb_device **devlist;
struct libusb_device_handle *hdl;
char product[64], serial_num[64], connection_id[64];
char product[64], serial_num[64], connection_id[64];
- 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);
if (conn)
conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
- else
- conn_devices = NULL;
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
for (i = 0; devlist[i]; i++) {
+ bus = libusb_get_bus_number(devlist[i]);
+ addr = libusb_get_device_address(devlist[i]);
+ /* Check if the connection matches the user spec. */
for (l = conn_devices; l; l = l->next) {
usb = l->data;
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)
- /* This device matched none of the ones that
- * matched the conn specification. */
sr_dbg("Failed to add device: %d.", ret);
}
}
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);
libusb_free_device_list(devlist, 1);
g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);