summaryrefslogtreecommitdiff
path: root/libusb/hotplug.c
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2015-09-10 02:39:20 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2015-09-28 21:51:30 -0700
commit960a6e7506c4d0d59052056ae2ebfffbe8587175 (patch)
tree372d705f39f0e482a61815bd25b40b34124b88f3 /libusb/hotplug.c
parent4a0eacbc6f4268c29c1c8d13a89aa42f689bb91c (diff)
downloadlibusb-960a6e7506c4d0d59052056ae2ebfffbe8587175.tar.gz
core: Prevent attempts to recursively hande events
Prior to this commit, it was possible to call certain functions from within a hotplug or transfer completion callback that would in turn attempt to handle events (e.g. any of the sync transfer APIs). This is dangerous because certain events may cause the nested calls to free memory that is currently in use by the previous calls. This implementation uses thread-local storage to store a key within the context that is set to a non-NULL value whenever event handling is occurring. This allows us to detect when dangerous calls are made from within event handling context. Such calls will return an error code of LIBUSB_ERROR_BUSY. Note that this implementation was chosen because of its portability. It is supported on all platforms that libusb supports. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/hotplug.c')
-rw-r--r--libusb/hotplug.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/libusb/hotplug.c b/libusb/hotplug.c
index 8dc185f..779cb6b 100644
--- a/libusb/hotplug.c
+++ b/libusb/hotplug.c
@@ -80,8 +80,14 @@
* are invalid and will remain so even if the device comes back.
*
* When handling a LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED event it is considered
- * safe to call any libusb function that takes a libusb_device. On the other hand,
- * when handling a LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT event the only safe function
+ * safe to call any libusb function that takes a libusb_device. It also safe to
+ * open a device and submit asynchronous transfers. However, most other functions
+ * that take a libusb_device_handle are <b>not</b> safe to call. Examples of such
+ * functions are any of the \ref syncio "synchronous API" functions or the blocking
+ * functions that retrieve various \ref desc "USB descriptors". These functions must
+ * be used outside of the context of the hotplug callback.
+ *
+ * When handling a LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT event the only safe function
* is libusb_get_device_descriptor().
*
* The following code provides an example of the usage of the hotplug interface: