From ef872cb7ad39172a1d8047a0d7696292edbf50bd Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 3 Mar 2022 17:24:41 +0100 Subject: [PATCH] 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 --- src/usb/osmo_libusb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usb/osmo_libusb.c b/src/usb/osmo_libusb.c index c5ea5079f..a249d100d 100644 --- a/src/usb/osmo_libusb.c +++ b/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));