mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-22 15:47:37 +00:00
Improve handling of USB device re-open in the LibUSB v1.x API.
Make sure the "device_is_gone" flag is cleared after every successful open, so that the "device_is_gone" flag doesn't persist forever. Found by: sergii.dmytruk@3mdeb.com PR: 256296 MFC after: 1 week Sponsored by: Mellanox Technologies // NVIDIA Networking
This commit is contained in:
parent
fa3746be42
commit
6847ea5019
@ -529,6 +529,15 @@ libusb_open(libusb_device *dev, libusb_device_handle **devh)
|
||||
libusb_unref_device(dev);
|
||||
return (LIBUSB_ERROR_NO_MEM);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the device gone flag, in case the device was opened
|
||||
* after a re-attach, to allow new transaction:
|
||||
*/
|
||||
CTX_LOCK(ctx);
|
||||
dev->device_is_gone = 0;
|
||||
CTX_UNLOCK(ctx);
|
||||
|
||||
libusb10_add_pollfd(ctx, &dev->dev_poll, pdev, libusb20_dev_get_fd(pdev), POLLIN |
|
||||
POLLOUT | POLLRDNORM | POLLWRNORM);
|
||||
|
||||
|
@ -165,8 +165,16 @@ libusb10_handle_events_sub(struct libusb_context *ctx, struct timeval *tv)
|
||||
err = libusb20_dev_process(ppdev[i]);
|
||||
|
||||
if (err) {
|
||||
/* set device is gone */
|
||||
dev->device_is_gone = 1;
|
||||
/*
|
||||
* When the device is opened
|
||||
* set the "device_is_gone"
|
||||
* flag. This prevents the
|
||||
* client from submitting new
|
||||
* USB transfers to a detached
|
||||
* device.
|
||||
*/
|
||||
if (ppdev[i]->is_opened)
|
||||
dev->device_is_gone = 1;
|
||||
|
||||
/* remove USB device from polling loop */
|
||||
libusb10_remove_pollfd(dev->ctx, &dev->dev_poll);
|
||||
|
@ -608,6 +608,11 @@ libusb20_dev_close(struct libusb20_device *pdev)
|
||||
|
||||
pdev->is_opened = 0;
|
||||
|
||||
/*
|
||||
* Make sure libusb20_tr_get_pointer() fails:
|
||||
*/
|
||||
pdev->nTransfer = 0;
|
||||
|
||||
/*
|
||||
* The following variable is only used by the libusb v0.1
|
||||
* compat layer:
|
||||
|
Loading…
Reference in New Issue
Block a user