diff options
author | Richard Hughes <richard@hughsie.com> | 2011-11-01 09:29:14 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2011-11-01 09:29:14 +0000 |
commit | f2d71bdb35223c7c8aac31e9f079bc224d777769 (patch) | |
tree | 320865d6d4128cddd04c063a55e0352803fd8b57 | |
parent | c90172092a0876036d8be96518526cc4fbd6ff9e (diff) | |
download | gusb-f2d71bdb35223c7c8aac31e9f079bc224d777769.tar.gz |
Do not try to set the currently running device configuration twice
...otherwise libusb returns LIBUSB_ERROR_BUSY and fails the request.
-rw-r--r-- | gusb/gusb-device.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index 969ae5c..26a08df 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -282,12 +282,25 @@ gboolean g_usb_device_set_configuration (GUsbDevice *device, GError **error) { gint rc; + gint config_tmp = 0; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); + /* verify we've not already set the same configuration */ + rc = libusb_get_configuration (device->priv->handle, + &config_tmp); + if (rc != LIBUSB_SUCCESS) { + return g_usb_device_libusb_error_to_gerror (device, + rc, + error); + } + if (config_tmp == configuration) + return TRUE; + + /* different, so change */ rc = libusb_set_configuration (device->priv->handle, configuration); return g_usb_device_libusb_error_to_gerror (device, rc, error); } |