diff options
author | Daniel Drake <dsd@gentoo.org> | 2008-05-12 15:43:30 +0100 |
---|---|---|
committer | Daniel Drake <dsd@gentoo.org> | 2008-05-12 15:43:30 +0100 |
commit | ade26afc42c34ceb1c45afcadd2ea5e8240eaca4 (patch) | |
tree | 212f25ccc4448209269048ded466c44f92668ad0 /libusb/os/linux_usbfs.c | |
parent | e25d590a9198995b4f0b6afeb41ecae318715e7e (diff) | |
download | libusb-ade26afc42c34ceb1c45afcadd2ea5e8240eaca4.tar.gz |
Linux: fix caching of guessed configuration
Reported and tested by Xiaofan Chen
Diffstat (limited to 'libusb/os/linux_usbfs.c')
-rw-r--r-- | libusb/os/linux_usbfs.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index edf1545..1ed9ad8 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -384,6 +384,8 @@ static int op_get_config_descriptor(struct libusb_device *dev, return r; } +/* cache the active config descriptor in memory. a value of -1 means that + * we aren't sure which one is active, so just assume the first one. */ static int cache_active_config(struct libusb_device *dev, int fd, int active_config) { @@ -394,11 +396,15 @@ static int cache_active_config(struct libusb_device *dev, int fd, int idx; int r; - r = usbi_get_config_index_by_value(dev, active_config, &idx); - if (r < 0) - return r; - if (idx == -1) - return LIBUSB_ERROR_NOT_FOUND; + if (active_config == -1) { + idx = 0; + } else { + r = usbi_get_config_index_by_value(dev, active_config, &idx); + if (r < 0) + return r; + if (idx == -1) + return LIBUSB_ERROR_NOT_FOUND; + } r = get_config_descriptor(fd, idx, tmp, sizeof(tmp)); if (r < 0) { |