In 1.2, ftdi_usb_get_strings stops opening a device if it's already open. But it still closes the device, even if it didn't open it. So if I have an open device, there's no way to just get the string info without having to reopen it.
The following simple patch changes the behavior to only close the usb_dev if it was opened, so now the open and close functions are matched internally.
I don't know whether or where to mention this change. Should I add it to a changelog anywhere?
Best regards, Fahrzin Hemmati
From 171c4747dd295d3b6085f09fa56e2c766d0f6cd9 Mon Sep 17 00:00:00 2001 From: Fahrzin Hemmati <fahhem@xxxxxxxxxx> Date: Mon, 25 Jan 2016 23:23:42 -0800 Subject: [PATCH] Match close with open in ftdi_usb_get_strings --- src/ftdi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index aa4b4ec..8ebddbd 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -414,7 +414,8 @@ int ftdi_usb_get_strings(struct ftdi_context * ftdi, struct libusb_device * dev, if ((ftdi==NULL) || (dev==NULL)) return -1; - if (ftdi->usb_dev == NULL && libusb_open(dev, &ftdi->usb_dev) < 0) + int need_open = ftdi->usb_dev == NULL; + if (need_open && libusb_open(dev, &ftdi->usb_dev) < 0) ftdi_error_return(-4, “libusb_open() failed”); if (libusb_get_device_descriptor(dev, &desc) < 0) @@ -447,7 +448,8 @@ int ftdi_usb_get_strings(struct ftdi_context * ftdi, struct libusb_device * dev, } } - ftdi_usb_close_internal (ftdi); + if (need_open) + ftdi_usb_close_internal (ftdi); return 0; } -- 2.7.0.rc3.207.g0ac5344
|