diff options
| author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2021-06-11 15:06:10 +0000 |
|---|---|---|
| committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2021-07-10 19:10:10 +0000 |
| commit | e50fd67784355030aedca8704223456c056fdeb4 (patch) | |
| tree | 0e5f5786ab89d92e0d0075f5abee6a468893050c | |
| parent | 666abb0888d277e82c6468851e015798e9a7629f (diff) | |
| download | src-e50fd67784355030aedca8704223456c056fdeb4.tar.gz src-e50fd67784355030aedca8704223456c056fdeb4.zip | |
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
Sponsored by: Mellanox Technologies // NVIDIA Networking
(cherry picked from commit 6847ea50196f1a685be408a24f01cb8d407da19c)
| -rw-r--r-- | lib/libusb/libusb10.c | 9 | ||||
| -rw-r--r-- | lib/libusb/libusb10_io.c | 12 | ||||
| -rw-r--r-- | lib/libusb/libusb20.c | 5 |
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 1c45b87d8f0b..ffe0cf3f366a 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -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); diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 53f5b040436d..0e32fc31c8e0 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -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); diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index 6c2bf721bea9..4323552b83ad 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -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: |
