Commit Graph

936 Commits

Author SHA1 Message Date
Chris Dickens 192adf437b core: Add helper functions to signal and clear the event pipe
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:17:50 -08:00
Chris Dickens 5b2f2e1185 core: Rename pipe used to signal internal events
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:15:55 -08:00
Chris Dickens 1b4b7f8b15 core: Transition device close event to use event_data_lock
This change removes the device_close_lock and uses the shared event
data lock to protect the value of the device_close counter.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:13:46 -08:00
Chris Dickens 0e62e5cf34 core: Add new lock to protect internal context event data
This lock will be used in subsequent changes that will consolidate
all different event sources (i.e. device close, fd notification,
hotplug message) into a single event.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:12:48 -08:00
Chris Dickens c57953cfb3 core: Rename pollfd_modify counter and its lock to device_close
This counter is now solely used for closing a device, so rename
the variable appropriately.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:12:04 -08:00
Chris Dickens 7ede4b76bd core: Remove taking of events lock inside usbi_fd_notification()
It is unnecessary to take the events lock when a thread needs to
interrupt an event handler to receive a change list of poll fds.
It is sufficient to simply write to the control pipe and let the
event handler be notified of this event when it polls.

Taking the events lock inside this function leads to opportunity
for deadlock in certain situations, such as a client program
running on an OS that uses fd notification on each individual
transfer. If the client program were to protect a list of transfers
with a single lock, it could deadlock if that lock were taken in
two separate threads, one which is attempting to submit a new
transfer and one which is executing inside the transfer completion
callback.

Thanks to Dmitry Fleytman and Pavel Gurvich for reporting this.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-12-19 11:11:07 -08:00
Ludovic Rousseau 7924c1fc67 Doxygen: upgrade doxygen.cfg.in file
Warning: Tag `XML_SCHEMA' at line 942 of file `doxygen.cfg' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
Warning: Tag `XML_DTD' at line 948 of file `doxygen.cfg' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"

I upgrade the doxygen.cfg.in using: "doxygen -u doxygen.cfg.in"

The configuration file changed from Doxyfile 1.5.3 to Doxyfile 1.8.8
2014-12-16 21:57:42 +01:00
Ludovic Rousseau 7e725e556a Doxygen: fix a duplicate label
libusb/io.c:46: warning: multiple use of section label 'intro' while
adding section, (first occurrence: libusb/core.c, line 79)

Use label "io_intro" instead of "intro"
2014-12-16 21:51:01 +01:00
Ludovic Rousseau de6130dc0d Doxygen: fix a duplicate label
libusb/hotplug.c:46: warning: multiple use of section label 'intro'
while adding section, (first occurrence: libusb/core.c, line 79)

Use label "hotplug_intro" instead of "intro"
2014-12-16 21:49:19 +01:00
Ludovic Rousseau e82c9b2b46 API: remove unused libusb_hotplug_callback struct
The structure libusb_hotplug_callback was declared (but not defined) and
never used in the public API.
2014-12-16 21:26:10 +01:00
Ludovic Rousseau 8c4f86b9f5 API: Add an Application Programming Interface page
This page lists the all the public functions, structures and enums
provided by libusb.
The HTML page is generated by Doxygen.
2014-12-16 21:19:22 +01:00
Pete Batard 63cd7d193c Windows: fix 2 bugs in windows_handle_events()
* Var found was not reset to false before list_for_each_entry()
* ctx->open_devs_lock was not released on error.
* Issues reported by Yongjian Xu
2014-12-16 19:19:50 +00:00
Simon Newton d37635afb2 misc: Fix grammar in a comment
# Closes #41
2014-12-01 00:00:59 +00:00
Pete Batard ada59db186 Windows: Silence VS2013 code analysis warnings
* Also update Windows version report for Windows 10
2014-11-13 22:03:30 +00:00
Pete Batard ab8f71c03f Windows: Fix cygwin64 build
* Issue reported by Thejus
2014-11-06 00:50:01 +00:00
Akshay Jaggi a447fa4cd5 Fix broken 'make install'
...that was broken with dc97425bb4 (Haiku inclusion)
2014-09-27 00:17:39 +01:00
Akshay Jaggi dc97425bb4 haiku: Add Haiku support 2014-09-25 21:42:16 +01:00
Chris Dickens 12e9e35579 io: Move timerfd close into error handling path
This makes error handling consistent with other areas. This is a
follow-on change to commit b72f4cf77e.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-09-06 23:17:36 -07:00
Chris Dickens b72f4cf77e io: Fix memory leaks in usbi_io_init()
* If the hotplug pipe failed to be created, the usbi_pollfd for the
  control pipe was being leaked.
* If the usbi_pollfd for timerfd failed to be added, the usbi_pollfd
  for the hotplug pipe was being leaked.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-09-06 23:11:23 -07:00
Chris Dickens a0d37149dc threads_posix: Fix compiler warning due to redefinition of _GNU_SOURCE
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-09-06 21:59:03 -07:00
Chris Dickens d8a2950f54 core: Make use of headers consistent across all files
* Include config.h before anything else in all files
* Remove unnecessary inclusion of libusb.h
* Use angle brackets for system headers and quotes for local headers

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-09-06 21:25:23 -07:00
Chris Dickens 8035a77489 core: Fix compiler warnings on MinGW and Visual Studio
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-09-03 10:10:23 -07:00
Tormod Volden 4e95d0e7f9 Windows: Define WINVER to fix building on MinGW
* For newer versions of MinGW, VerSetConditionMask() is only defined
  if building for Windows XP (0x501) or newer.
2014-09-03 14:10:42 +01:00
Chris Dickens 47e1141f6b core: Fix reference count leak for default context
If the default context was created but failed to fully initialize,
the reference count was not decremented appropriately.
2014-08-29 15:58:17 -07:00
Chris Dickens 3c323dc36e core: Rename count variable for pollfds for consistency with other count variables
Signed-off-by: Chris Dickens <chris.dickens@hp.com>
2014-08-29 15:38:49 -07:00
Chris Dickens 8c60a6716d core: Reuse poll fds across calls to handle_events()
Prior to this patch, the array of poll fds given to poll() was
allocated and freed every time handle_events() was called. This
is unnecessary if the list of poll fds has not changed since the
last call to handle_events(). With this patch, the array and count
of poll fds is stored in the context and only reallocated when the
list of poll fds changes, saving any unnecessary overhead.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-08-27 02:41:42 -07:00
Chris Dickens b65dd04a3d Misc: Add myself to the README as a maintainer 2014-08-27 02:04:21 -07:00
Chris Dickens b5f43b29e7 core: Be more efficient by not passing internal fds to backend
There are a number of fds that the core uses internally. Currently
any events on these fds are masked out so that the backend will
skip over them during handle_events().

This change improves upon this by simply not providing these fds
to the backend.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-08-27 01:54:54 -07:00
Chris Dickens 9a9ef3ec2b core: Only interrupt event handlers as necessary during libusb_open()
The current behavior of libusb_open() unconditionally interrupts
any event handlers via usbi_fd_notification(). However, not all
backends, namely Win/WinCE, make changes to the pollfd list during
a device open.

This change adds a new CAP for backends (HAS_POLLABLE_DEVICE_FD),
and libusb_open() will only call usbi_fd_notification() if the
backend declares this capability.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-08-27 01:50:09 -07:00
Chris Dickens a3a4806d49 usbi_handle_transfer_completion: Remove signal to event waiters
usbi_handle_transfer_completion() is only called by backends when
handling transfer completion. The backend can only make this call
whilst holding the events lock, therefore it is pointless to send
this signal. Any threads waiting to be signaled will be woken up
and will either find that an event handler is still active or will
try to obtain the events lock and be blocked.

Event waiters are automatically signaled in libusb_unlock_events(),
so when the backend is done handling events it will release the lock
and wake up any waiters. At this point the events lock wll be free,
which is the only time waking up waiters makes sense.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2014-08-27 01:49:03 -07:00
Hans de Goede e11525c66c libusb 1.0.19
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
v1.0.19
2014-06-13 20:31:35 +02:00
John Sheu cdf3c36ea1 Fix leak in failure path of libusb_get_max_packet_size()
If libusb_get_max_packet_size() or libusb_get_max_iso_packet_size()
fails to find the endpoint, it leaks the configuration descriptor.  Fix
this.

Signed-off-by: John Sheu <sheu@google.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-06-13 20:25:48 +02:00
Sean McBride e6902b2b0f Fixed clang static analyzer warning about dereferencing null
It looks like *ifcp should be the same as iface,
so I just use the latter instead of the former.

Closes pull request #13

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2014-06-10 18:59:30 -06:00
Sean McBride 7dfdf8e1b1 Made darwin_hotplug_poll static to fix Xcode warning
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2014-06-10 18:58:11 -06:00
Hans de Goede f3587bb68e libusb 1.0.19-rc2
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
v1.0.19-rc2
2014-05-30 14:48:28 +02:00
Hans de Goede 6edd96ab81 libusb_submit_transfer: Don't reference the device on submission failure
If submission fails libusb_ref_device will never get balanced by an unref
on completion, since there will be no completion.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 12:37:37 +02:00
Hans de Goede 4f347f01fa libusb_submit_transfer: Fix possible deadlock
Fix a possible deadlock due to a lock ordering reversal, caught by Coverity:

*** CID 62579:  Thread deadlock  (ORDER_REVERSAL)
/libusb/io.c: 1451 in libusb_submit_transfer()
1445     	r = calculate_timeout(itransfer);
1446     	if (r < 0) {
1447     		r = LIBUSB_ERROR_OTHER;
1448     		goto out;
1449     	}
1450
>>>     CID 62579:  Thread deadlock  (ORDER_REVERSAL)
>>>     Calling "pthread_mutex_lock" acquires lock "libusb_context.flying_transfers_lock" while holding lock "usbi_transfer.lock" (count: 1 / 4).
1451     	usbi_mutex_lock(&ctx->flying_transfers_lock);
1452     	r = add_to_flying_list(itransfer);
1453     	if (r == LIBUSB_SUCCESS) {
1454     		r = usbi_backend->submit_transfer(itransfer);
1455     	}
1456     	if (r != LIBUSB_SUCCESS) {

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 12:36:11 +02:00
Hans de Goede 507f6c7bda linux_udev: Fix a Coverity warning
This really is a false positive, but easy enough to silence:

*** CID 62578:  Failure to restore non-local value  (MISSING_RESTORE)
/libusb/os/linux_udev.c: 64 in linux_udev_start_event_monitor()
58     	int r;
59
60     	assert(udev_ctx == NULL);
61     	udev_ctx = udev_new();
62     	if (!udev_ctx) {
63     		usbi_err(NULL, "could not create udev context");
>>>     CID 62578:  Failure to restore non-local value  (MISSING_RESTORE)
>>>     Value of non-local "udev_ctx" that was verified to be "NULL" is not restored as it was along other paths.
64     		return LIBUSB_ERROR_OTHER;
65     	}
66
67     	udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
68     	if (!udev_monitor) {
69     		usbi_err(NULL, "could not initialize udev monitor");

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 12:35:34 +02:00
Hans de Goede d7e763e277 linux_usbfs: op_handle_events: Protect against not finding the device-handle
We scan the list of open devices to find the device-handle based on the fd,
add a check to ensure that we've actually found the handle before continuing.

This fixes the following Coverity warning:

*** CID 62575:  Explicit null dereferenced  (FORWARD_NULL)
/libusb/os/linux_usbfs.c: 2594 in op_handle_events()
2588     			hpriv = _device_handle_priv(handle);
2589     			if (hpriv->fd == pollfd->fd)
2590     				break;
2591     		}
2592
2593     		if (pollfd->revents & POLLERR) {
>>>     CID 62575:  Explicit null dereferenced  (FORWARD_NULL)
>>>     Dereferencing null pointer "hpriv".
2594     			usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->fd);
2595     			usbi_handle_disconnect(handle);
2596     			/* device will still be marked as attached if hotplug
monitor thread
2597     			 * hasn't processed remove event yet */
2598     			usbi_mutex_static_lock(&linux_hotplug_lock);
2599     			if (handle->dev->attached)

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 11:38:07 +02:00
Hans de Goede 8af0e460e1 linux_usbfs: Don't mark init_count as volatile
There is no reason to mark init_count as volatile, it is protected by the
linux_hotplug_startstop_lock. Removing the volatile marking fixes the
following Coverity warning:

*** CID 62574:  Side effect in assertion  (ASSERT_SIDE_EFFECT)
/libusb/os/linux_usbfs.c: 460 in op_exit()
454     	return r;
455     }
456
457     static void op_exit(void)
458     {
459     	usbi_mutex_static_lock(&linux_hotplug_startstop_lock);
>>>     CID 62574:  Side effect in assertion  (ASSERT_SIDE_EFFECT)
>>>     Argument "init_count" of assert() has a side effect because the variable is volatile.  The containing function might work differently in a non-debug build.
460     	assert(init_count != 0);
461     	if (!--init_count) {
462     		/* tear down event handler */
463     		(void)linux_stop_event_monitor();
464     	}
465     	usbi_mutex_static_unlock(&linux_hotplug_startstop_lock);

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 11:13:21 +02:00
Lars Kanis 64b20360a4 Fix a small typo in comment to free_streams()
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-30 11:09:02 +02:00
Pete Batard 6d5e7ec800 Windows: fix broken WDK compilation for XP targets
* On XP environments, the call to GetSystemMetrics() fails without an explicit reference to user.lib...
  which end user applications would also need to do.
  Considering that this call was just to differentiate Windows 2003 from 2003 R2, just remove it.
2014-05-20 20:42:54 +01:00
Hans de Goede 5e77b8838b ChangeLog: Add an entry about the Russian strerror translation
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-19 11:33:03 +02:00
Hans de Goede edaa1afe5d libusb 1.0.19-rc1
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
v1.0.19-rc1
2014-05-19 11:03:07 +02:00
Ларионов Даниил c8e9269a06 strerrror.c: Add Russian translation
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2014-05-19 10:58:15 +02:00
Pete Batard d41802053c windows: fix USB 3.0 speed detection on Windows 8 or later
* ...since Microsoft broke IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX between Windows 7 and Windows 8
* Also improve Windows version detection and reporting
* Closes #10
2014-05-18 20:19:03 +01:00
Pete Batard c0f5e58acb samples: set xusb to also produce debug output during init when -d is specified
* This can be quite useful for troubleshooting user issues
2014-05-18 19:49:51 +01:00
Pete Batard bcc4e517d5 core: fix/silence issues reported by Coverity
* libusb has been added to Coverity at https://scan.coverity.com/projects/2180
* Use "// coverity[keyword]" to silence the issues we don't care about
* All other issues from the Windows build have been fixed, apart from the closing of the DLLs.
2014-05-16 23:01:57 +01:00
Nathan Hjelm 26dab3d680 darwin: initial implemenations of the hotplug_poll function
This implementation makes use of the IOKitWaitQuiet which waits until
all IOKit processing is complete. The performance won't necessarily be
great but it should help codes that have not yet or cannot move to the
libusb hotplug API.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
2014-05-12 17:40:12 -06:00
Pete Batard 3893c4fcc9 Windows: Fix broken WDK compilation
* void function call was returning a value
* introduced in 6d8dfe0aee
* also fix whitespaces
2014-05-08 21:20:31 +01:00