- struct drv_context *drvc;
-
- drvc = di->context;
-
- return drvc->instances;
-}
-
-/* Destroy the private device context.
- */
-static void clear_dev_context(void *priv)
-{
- struct dev_context *devc;
-
- devc = priv;
-
- if (devc->acquisition) {
- sr_err("Cannot clear device context during acquisition!");
- return; /* leak and pray */
+ int drained, xfer_len, ret;
+ unsigned char buf[512];
+ const unsigned int drain_timeout_ms = 10;
+
+ drained = 0;
+ do {
+ xfer_len = 0;
+ ret = libusb_bulk_transfer(usb->devhdl, endpoint,
+ buf, sizeof(buf), &xfer_len,
+ drain_timeout_ms);
+ drained += xfer_len;
+ } while (ret == LIBUSB_SUCCESS && xfer_len != 0);
+
+ if (ret != LIBUSB_SUCCESS && ret != LIBUSB_ERROR_TIMEOUT) {
+ sr_err("Failed to drain USB endpoint %u: %s.",
+ endpoint & (LIBUSB_ENDPOINT_IN - 1),
+ libusb_error_name(ret));
+ return SR_ERR;
+ }
+ if (drained > 0) {
+ sr_warn("Drained %d bytes from USB endpoint %u.",
+ drained, endpoint & (LIBUSB_ENDPOINT_IN - 1));