usb: Match device by VID/PID without path/addr if it is unique

If there's only a single device with matching VID/PID attached,
we don't need to insist that either the path or the address of the
device matches.  Those are only needed to disambiguate multiple
devices with identical VID/PID.

Change-Id: I2ef245a56dfcf22758a0216b86d2a5c602ee5588
changes/98/27398/2
Harald Welte 9 months ago
parent 28b404fb71
commit ef872cb7ad
  1. 3
      src/usb/osmo_libusb.c

@ -537,7 +537,8 @@ libusb_device_handle *osmo_libusb_open_claim_interface(void *ctx, libusb_context
addr = libusb_get_device_address(*dev);
path = osmo_libusb_dev_get_path_buf(pathbuf, sizeof(pathbuf), *dev);
if ((ifm->addr && addr == ifm->addr) ||
(strlen(ifm->path) && !strcmp(path, ifm->path))) {
(strlen(ifm->path) && !strcmp(path, ifm->path)) ||
(!ifm->addr && !strlen(ifm->path) && !list[1] /* only one device */)) {
rc = libusb_open(*dev, &usb_devh);
if (rc < 0) {
fprintf(stderr, "Cannot open device: %s\n", libusb_error_name(rc));

Loading…
Cancel
Save