From b779eca8d37896072ddc5017f1c63a3056515869 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 26 Jan 2022 21:40:46 +0100 Subject: [PATCH] Remove libusb_device field It is possible to retrieve the device instance from the handle via libusb_get_device(), so we don't need to reference the device one more time. PR #2974 --- app/src/usb/usb.c | 9 ++++----- app/src/usb/usb.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/usb/usb.c b/app/src/usb/usb.c index ebd218dc..44d1d489 100644 --- a/app/src/usb/usb.c +++ b/app/src/usb/usb.c @@ -84,17 +84,17 @@ sc_usb_init(struct sc_usb *usb, const char *serial) { return false; } - usb->device = sc_usb_find_device(serial); - if (!usb->device) { + libusb_device *device = sc_usb_find_device(serial); + if (!device) { LOGW("USB device %s not found", serial); libusb_exit(usb->context); return false; } - usb->handle = sc_usb_open_handle(usb->device); + usb->handle = sc_usb_open_handle(device); + libusb_unref_device(device); if (!usb->handle) { LOGW("Could not open USB device %s", serial); - libusb_unref_device(usb->device); libusb_exit(usb->context); return false; } @@ -105,6 +105,5 @@ sc_usb_init(struct sc_usb *usb, const char *serial) { void sc_usb_destroy(struct sc_usb *usb) { libusb_close(usb->handle); - libusb_unref_device(usb->device); libusb_exit(usb->context); } diff --git a/app/src/usb/usb.h b/app/src/usb/usb.h index 5743626d..8ee3eb9f 100644 --- a/app/src/usb/usb.h +++ b/app/src/usb/usb.h @@ -8,7 +8,6 @@ struct sc_usb { libusb_context *context; - libusb_device *device; libusb_device_handle *handle; };