From 8fc9dca8cb4d35fb329826fffa00e1403eb7ed43 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 26 Jan 2022 22:15:23 +0100 Subject: [PATCH] Make serial optional to find USB devices If no serial is provided, then list all available USB devices (which can be open and having a serial). PR #2974 --- app/src/usb/usb.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/usb/usb.c b/app/src/usb/usb.c index 6add7b2e..8140b674 100644 --- a/app/src/usb/usb.c +++ b/app/src/usb/usb.c @@ -53,11 +53,14 @@ accept_device(libusb_device *device, const char *serial, return false; } - bool matches = !strcmp(serial, device_serial); - if (!matches) { - free(device_serial); - libusb_close(handle); - return false; + if (serial) { + // Filter by serial + bool matches = !strcmp(serial, device_serial); + if (!matches) { + free(device_serial); + libusb_close(handle); + return false; + } } out->device = libusb_ref_device(device); @@ -90,8 +93,6 @@ sc_usb_device_destroy_all(struct sc_usb_device *usb_devices, size_t count) { ssize_t sc_usb_find_devices(struct sc_usb *usb, const char *serial, struct sc_usb_device *devices, size_t len) { - assert(serial); - libusb_device **list; ssize_t count = libusb_get_device_list(usb->context, &list); if (count < 0) {