platform/upstream/libusb.git
9 years agodarwin: fix resource leak (cached devices are never freed)
parafin [Mon, 9 Feb 2015 21:28:43 +0000 (00:28 +0300)]
darwin: fix resource leak (cached devices are never freed)

For each new device (processed by hotplug code) darwin_ref_cached_device
is called twice - in process_new_device and in darwin_get_cached_device
(which is called from the first function). But when the device is detached
only one darwin_deref_cached_device is done - in darwin_destroy_device.
So there is inbalance between ref and deref which causes darwin_cached_devices
list to monotonically grow and consume more and more resources over time.
This commit fixes the problem by adding darwin_deref_cached_device call
to darwin_devices_detached.

Closes #52

Signed-off-by: Nathan Hjelm <hjelmn@mac.com>
9 years agodarwin: Fix build break and warning caused by commit 699db154
Chris Dickens [Sun, 1 Feb 2015 06:25:24 +0000 (22:25 -0800)]
darwin: Fix build break and warning caused by commit 699db154

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agohaiku: Transition to use new transfer completion API
Chris Dickens [Wed, 21 Jan 2015 08:18:44 +0000 (00:18 -0800)]
haiku: Transition to use new transfer completion API

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoopenbsd: Transition to use new transfer completion API
Chris Dickens [Wed, 21 Jan 2015 08:18:43 +0000 (00:18 -0800)]
openbsd: Transition to use new transfer completion API

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agonetbsd: Transition to use new transfer completion API
Chris Dickens [Wed, 21 Jan 2015 08:18:42 +0000 (00:18 -0800)]
netbsd: Transition to use new transfer completion API

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agodarwin: Transition to use new transfer completion API
Chris Dickens [Wed, 21 Jan 2015 08:18:41 +0000 (00:18 -0800)]
darwin: Transition to use new transfer completion API

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Implement new transfer completion API
Chris Dickens [Wed, 21 Jan 2015 08:18:40 +0000 (00:18 -0800)]
core: Implement new transfer completion API

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agodarwin: change Xcode project end-of-line
Ludovic Rousseau [Sun, 25 Jan 2015 12:52:38 +0000 (13:52 +0100)]
darwin: change Xcode project end-of-line

The end of line character was CR (0x0D) instead of NL (0x0A).

It looks like the mistake is from
1eff220474f63d7ea7f8f99bef2a3da9da5324eb

9 years agolinux_usbfs: Update MAX_ISO_BUFFER_LENGTH
Chris Dickens [Thu, 22 Jan 2015 08:25:16 +0000 (00:25 -0800)]
linux_usbfs: Update MAX_ISO_BUFFER_LENGTH

Newer kernels have raised the maximum length of individual ISO
packets and URBs. There's no easy way to detect the limit, so we
will define MAX_ISO_BUFFER_LENGTH as the largest known limit.

If a user runs this on an earlier kernel and submits an ISO transfer
that is too large, they will receive LIBUSB_ERROR_INVALID_PARAM.

The documentation has been updated to note this behavior, under
"Considerations for isochronous transfers".

Closes #23

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoFix up backends for new transfer completion API.
Chris Dickens [Wed, 21 Jan 2015 06:58:04 +0000 (22:58 -0800)]
Fix up backends for new transfer completion API.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Add alternative API for backends to handle transfer completion
Chris Dickens [Wed, 21 Jan 2015 06:49:59 +0000 (22:49 -0800)]
core: Add alternative API for backends to handle transfer completion

Currently all non-Linux POSIX backends emulate the Linux design of
having individual pollable file descriptors for each device. This
patch introduces a new internal API that allows backends to handle
transfer completion notification in a different way.

A new function, usbi_signal_transfer_completion(), is added. Each
backend can call this function when it detects a transfer has
completed. This function will place the transfer on a new
completed_transfers list and will signal the context's event.

Backends that use this new API will no longer provide a handle_events()
function but instead provide a handle_transfer_completion() function.
When a thread is doing event handling, it will call this backend
function for all transfers on the completed_transfers list.

With this change, backends that do not really have natively pollable
file descriptors can completely move away from this design and avoid
poll() altogether.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agohotplug: Provide a default enum value for libusb_hotplug_flag
Chris Dickens [Tue, 13 Jan 2015 07:32:48 +0000 (23:32 -0800)]
hotplug: Provide a default enum value for libusb_hotplug_flag

* Closes #35

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoExamples: Fix device leak in hotplugtest
Chris Dickens [Mon, 12 Jan 2015 08:12:02 +0000 (00:12 -0800)]
Examples: Fix device leak in hotplugtest

Device leak occurred if either of the following occured:
  1) Detach followed by attach
  2) Two consecutive attach

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoWindows: Fix broken build caused by missing rename in 63a440f1
Chris Dickens [Sun, 11 Jan 2015 16:16:24 +0000 (08:16 -0800)]
Windows: Fix broken build caused by missing rename in 63a440f1

9 years agocore: Fix handling of duplicate transfer submission/cancellation
Chris Dickens [Thu, 8 Jan 2015 20:45:56 +0000 (12:45 -0800)]
core: Fix handling of duplicate transfer submission/cancellation

In the docs, we claim to report LIBUSB_ERROR_BUSY if submitting a
transfer that has already been submitted. Linux was the only backend
that actually checked and reported this, but unfortunately the code
in libusb_submit_transfer() resulted in a segfault. This is because
submission failure would delete the (active) transfer from the
flying_transfers list, and when the transfer finally completes it
would be deleted from the flying_transfers list a second time.

Instead of modifying each backend to check for a busy transfer, this
patch adds a flag to indicate when a transfer is in-flight. The core
library will check this flag and return LIBUSB_ERROR_BUSY immediately.

This patch also modifies libusb_cancel_transfer() to check that a
transfer is in-flight before cancelling and to check that a transfer
has not already been cancelled, returning LIBUSB_ERROR_NOT_FOUND in
both cases.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoWindows: Free all WinUSB handles when closing a device
Chris Dickens [Sun, 11 Jan 2015 07:55:28 +0000 (23:55 -0800)]
Windows: Free all WinUSB handles when closing a device

* libusbK (as of v3.0.7.0) will fail after 32 opens because
  resources from claimed interfaces are not freed by simply
  closing just the device handle
* Closes #16

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Add debug statements to help trace transfers
Chris Dickens [Thu, 8 Jan 2015 19:09:32 +0000 (11:09 -0800)]
core: Add debug statements to help trace transfers

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoDo not use IOUSBDeviceInterface550 or kIOUSBInterfaceInterfaceID550 on OSX versions
Nathan Hjelm [Thu, 8 Jan 2015 03:43:47 +0000 (20:43 -0700)]
Do not use IOUSBDeviceInterface550 or kIOUSBInterfaceInterfaceID550 on OSX versions
older than 10.9.

Closes #48

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
9 years agocore: Make event_data_lock non-recursive
Chris Dickens [Tue, 6 Jan 2015 18:59:01 +0000 (10:59 -0800)]
core: Make event_data_lock non-recursive

Hans pointed out that usbi_fd_notification() is only used by the
functions that add/remove pollfds. They already hold the required
lock, so to make it less expensive we will assume the lock is
already held.

The usbi_fd_notification() function has also been moved from core.c
into io.c and made static, since it now only has one use case.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoFixing erroneous double semi-colon
Chris Dickens [Tue, 6 Jan 2015 07:34:45 +0000 (23:34 -0800)]
Fixing erroneous double semi-colon

9 years agoWindows: Direct control requests to a specific interface when possible
Chris Dickens [Tue, 6 Jan 2015 04:47:47 +0000 (20:47 -0800)]
Windows: Direct control requests to a specific interface when possible

Control requests on composite devices for Windows is tricky, because not
all APIs are able to correctly process all types of requests. To improve
robustness, this change checks whether the control request recipient is
an interface or endpoint. If it is either, the control request will be
attempted against that interface's API first.

Additionally, when cycling through the interfaces to find a working API,
it will no longer fail if that API does not support the specific type of
control request because there is a chance that another API will succeed.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Improve the handling of the pollfd list
Chris Dickens [Sun, 21 Dec 2014 22:58:35 +0000 (14:58 -0800)]
core: Improve the handling of the pollfd list

This change consists of two parts that must be taken together.

Part 1 moves the pollfd list under the protection of event_data_lock
and eliminates the pollfd_lock. Since modifications to the pollfd
list are considered an event, it makes sense to merge this. Another
benefit of doing so is an enhancement to event handling. The event
handler can get the updated pollfd list upon entry into handle_events()
and can clear the event pipe if no other pending events exist, which
saves a needless iteration.

Part 2 makes notification of pollfd list changes part of adding or
removing a pollfd from the list. Previously this was done in two
distinct steps, however nothing prevented a new pollfd from being
used by an event handler before an explicit notification was sent out.
This change eliminates the need for USBI_TRANSFER_UPDATED_FDS and
reverts 9a9ef3ec2b9c691609ec9f8b82ac4436a662df18.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Signal the event pipe at most one time
Chris Dickens [Tue, 18 Nov 2014 07:53:14 +0000 (23:53 -0800)]
core: Signal the event pipe at most one time

This change will ensure that the event pipe is only signalled
at most one time during the course of any incoming events. New
events that occur while the event pipe is in the signalled state
will not cause the event pipe to be signalled again.

This change will provide support for the use of native events on
the Windows/WinCE backends, as these events are binary and do not
"count" the number of times they are signalled.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Eliminate hotplug pipe, using list and event pipe instead
Chris Dickens [Tue, 18 Nov 2014 07:53:13 +0000 (23:53 -0800)]
core: Eliminate hotplug pipe, using list and event pipe instead

To further consolidate libusb internal events, this change removes
the hotplug pipe. Hotplug messages are now kept in a list within the
context, and the event pipe is signalled when a new hotplug message
is added. When handling events, the hotplug messages will be processed
from the list instead of from a separate pipe.

This change is greatly beneficial for the Windows/WinCE backends which
do not allow pipes to be used in the WaitFor* functions.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Add new flag to record when a new poll fd is added
Chris Dickens [Tue, 18 Nov 2014 07:53:12 +0000 (23:53 -0800)]
core: Add new flag to record when a new poll fd is added

This flag will be useful in a subsequent commit that further
consolidates event handling.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Add helper functions to signal and clear the event pipe
Chris Dickens [Tue, 18 Nov 2014 07:53:11 +0000 (23:53 -0800)]
core: Add helper functions to signal and clear the event pipe

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Rename pipe used to signal internal events
Chris Dickens [Tue, 18 Nov 2014 07:53:10 +0000 (23:53 -0800)]
core: Rename pipe used to signal internal events

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Transition device close event to use event_data_lock
Chris Dickens [Tue, 18 Nov 2014 07:53:09 +0000 (23:53 -0800)]
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>
9 years agocore: Add new lock to protect internal context event data
Chris Dickens [Tue, 18 Nov 2014 07:53:08 +0000 (23:53 -0800)]
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>
9 years agocore: Rename pollfd_modify counter and its lock to device_close
Chris Dickens [Tue, 18 Nov 2014 07:53:07 +0000 (23:53 -0800)]
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>
9 years agocore: Remove taking of events lock inside usbi_fd_notification()
Chris Dickens [Tue, 18 Nov 2014 07:53:06 +0000 (23:53 -0800)]
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>
9 years agoDoxygen: upgrade doxygen.cfg.in file
Ludovic Rousseau [Tue, 16 Dec 2014 20:55:37 +0000 (21:55 +0100)]
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

9 years agoDoxygen: fix a duplicate label
Ludovic Rousseau [Tue, 16 Dec 2014 20:50:19 +0000 (21:50 +0100)]
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"

9 years agoDoxygen: fix a duplicate label
Ludovic Rousseau [Tue, 16 Dec 2014 20:47:44 +0000 (21:47 +0100)]
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"

9 years agoAPI: remove unused libusb_hotplug_callback struct
Ludovic Rousseau [Tue, 16 Dec 2014 20:17:16 +0000 (21:17 +0100)]
API: remove unused libusb_hotplug_callback struct

The structure libusb_hotplug_callback was declared (but not defined) and
never used in the public API.

9 years agoAPI: Add an Application Programming Interface page
Ludovic Rousseau [Mon, 15 Dec 2014 10:46:41 +0000 (11:46 +0100)]
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.

9 years agoWindows: fix 2 bugs in windows_handle_events()
Pete Batard [Tue, 16 Dec 2014 19:19:50 +0000 (19:19 +0000)]
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

9 years agomisc: Fix grammar in a comment
Simon Newton [Tue, 25 Nov 2014 04:09:57 +0000 (20:09 -0800)]
misc: Fix grammar in a comment

# Closes #41

9 years agoWindows: Silence VS2013 code analysis warnings
Pete Batard [Thu, 13 Nov 2014 22:03:30 +0000 (22:03 +0000)]
Windows: Silence VS2013 code analysis warnings

* Also update Windows version report for Windows 10

9 years agoWindows: Fix cygwin64 build
Pete Batard [Thu, 6 Nov 2014 00:50:01 +0000 (00:50 +0000)]
Windows: Fix cygwin64 build

* Issue reported by Thejus

9 years agoFix broken 'make install'
Akshay Jaggi [Fri, 26 Sep 2014 05:05:07 +0000 (10:35 +0530)]
Fix broken 'make install'

...that was broken with dc97425bb415422423b8876af0e34111e566d56d (Haiku inclusion)

9 years agohaiku: Add Haiku support
Akshay Jaggi [Wed, 24 Sep 2014 21:46:17 +0000 (22:46 +0100)]
haiku: Add Haiku support

9 years agoio: Move timerfd close into error handling path
Chris Dickens [Fri, 29 Aug 2014 23:12:55 +0000 (16:12 -0700)]
io: Move timerfd close into error handling path

This makes error handling consistent with other areas. This is a
follow-on change to commit b72f4cf77edb1975cada8aab5ae63361c68c5992.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoio: Fix memory leaks in usbi_io_init()
Chris Dickens [Wed, 27 Aug 2014 06:36:12 +0000 (23:36 -0700)]
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>
9 years agothreads_posix: Fix compiler warning due to redefinition of _GNU_SOURCE
Chris Dickens [Sun, 7 Sep 2014 04:59:03 +0000 (21:59 -0700)]
threads_posix: Fix compiler warning due to redefinition of _GNU_SOURCE

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agocore: Make use of headers consistent across all files
Chris Dickens [Wed, 3 Sep 2014 18:50:47 +0000 (11:50 -0700)]
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>
9 years agocore: Fix compiler warnings on MinGW and Visual Studio
Chris Dickens [Wed, 3 Sep 2014 17:10:23 +0000 (10:10 -0700)]
core: Fix compiler warnings on MinGW and Visual Studio

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoWindows: Define WINVER to fix building on MinGW
Tormod Volden [Tue, 2 Sep 2014 18:25:00 +0000 (19:25 +0100)]
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.

9 years agocore: Fix reference count leak for default context
Chris Dickens [Wed, 27 Aug 2014 06:36:13 +0000 (23:36 -0700)]
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.

9 years agocore: Rename count variable for pollfds for consistency with other count variables
Chris Dickens [Fri, 29 Aug 2014 22:38:49 +0000 (15:38 -0700)]
core: Rename count variable for pollfds for consistency with other count variables

Signed-off-by: Chris Dickens <chris.dickens@hp.com>
9 years agocore: Reuse poll fds across calls to handle_events()
Chris Dickens [Thu, 5 Jun 2014 09:04:11 +0000 (02:04 -0700)]
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>
9 years agoMisc: Add myself to the README as a maintainer
Chris Dickens [Wed, 27 Aug 2014 09:04:21 +0000 (02:04 -0700)]
Misc: Add myself to the README as a maintainer

9 years agocore: Be more efficient by not passing internal fds to backend
Chris Dickens [Tue, 26 Aug 2014 06:26:53 +0000 (23:26 -0700)]
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>
9 years agocore: Only interrupt event handlers as necessary during libusb_open()
Chris Dickens [Tue, 26 Aug 2014 06:26:52 +0000 (23:26 -0700)]
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>
9 years agousbi_handle_transfer_completion: Remove signal to event waiters
Chris Dickens [Tue, 26 Aug 2014 06:26:51 +0000 (23:26 -0700)]
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>
10 years agolibusb 1.0.19
Hans de Goede [Fri, 13 Jun 2014 18:31:35 +0000 (20:31 +0200)]
libusb 1.0.19

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoFix leak in failure path of libusb_get_max_packet_size()
John Sheu [Tue, 10 Jun 2014 22:09:06 +0000 (15:09 -0700)]
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>
10 years agoFixed clang static analyzer warning about dereferencing null
Sean McBride [Wed, 21 May 2014 14:15:50 +0000 (10:15 -0400)]
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>
10 years agoMade darwin_hotplug_poll static to fix Xcode warning
Sean McBride [Wed, 21 May 2014 14:11:25 +0000 (10:11 -0400)]
Made darwin_hotplug_poll static to fix Xcode warning

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agolibusb 1.0.19-rc2
Hans de Goede [Fri, 30 May 2014 12:48:28 +0000 (14:48 +0200)]
libusb 1.0.19-rc2

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolibusb_submit_transfer: Don't reference the device on submission failure
Hans de Goede [Fri, 30 May 2014 10:25:18 +0000 (12:25 +0200)]
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>
10 years agolibusb_submit_transfer: Fix possible deadlock
Hans de Goede [Fri, 30 May 2014 10:14:30 +0000 (12:14 +0200)]
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>
10 years agolinux_udev: Fix a Coverity warning
Hans de Goede [Fri, 30 May 2014 09:57:42 +0000 (11:57 +0200)]
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>
10 years agolinux_usbfs: op_handle_events: Protect against not finding the device-handle
Hans de Goede [Fri, 30 May 2014 09:38:07 +0000 (11:38 +0200)]
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>
10 years agolinux_usbfs: Don't mark init_count as volatile
Hans de Goede [Fri, 30 May 2014 09:13:21 +0000 (11:13 +0200)]
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>
10 years agoFix a small typo in comment to free_streams()
Lars Kanis [Sat, 24 May 2014 13:42:37 +0000 (15:42 +0200)]
Fix a small typo in comment to free_streams()

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoWindows: fix broken WDK compilation for XP targets
Pete Batard [Tue, 20 May 2014 19:42:54 +0000 (20:42 +0100)]
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.

10 years agoChangeLog: Add an entry about the Russian strerror translation
Hans de Goede [Mon, 19 May 2014 09:33:03 +0000 (11:33 +0200)]
ChangeLog: Add an entry about the Russian strerror translation

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolibusb 1.0.19-rc1
Hans de Goede [Fri, 2 May 2014 13:25:26 +0000 (15:25 +0200)]
libusb 1.0.19-rc1

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agostrerrror.c: Add Russian translation
Ларионов Даниил [Mon, 19 May 2014 08:36:46 +0000 (10:36 +0200)]
strerrror.c: Add Russian translation

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agowindows: fix USB 3.0 speed detection on Windows 8 or later
Pete Batard [Sun, 18 May 2014 19:18:29 +0000 (20:18 +0100)]
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

10 years agosamples: set xusb to also produce debug output during init when -d is specified
Pete Batard [Sun, 18 May 2014 18:49:51 +0000 (19:49 +0100)]
samples: set xusb to also produce debug output during init when -d is specified

* This can be quite useful for troubleshooting user issues

10 years agocore: fix/silence issues reported by Coverity
Pete Batard [Fri, 16 May 2014 22:01:57 +0000 (23:01 +0100)]
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.

10 years agodarwin: initial implemenations of the hotplug_poll function
Nathan Hjelm [Mon, 12 May 2014 23:36:46 +0000 (17:36 -0600)]
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>
10 years agoWindows: Fix broken WDK compilation
Pete Batard [Thu, 8 May 2014 20:19:45 +0000 (21:19 +0100)]
Windows: Fix broken WDK compilation

* void function call was returning a value
* introduced in 6d8dfe0aee41a3c7dd862c3de488df3ce452d86e
* also fix whitespaces

10 years agodarwin: correct endpoint address calculation
Nathan Hjelm [Tue, 6 May 2014 08:35:44 +0000 (02:35 -0600)]
darwin: correct endpoint address calculation

The backend was incorrectly calculating the addresses of endpoints
with directions other than kUSBIn and kUSBOut. This primarily affects
devices with multiple control endpoints. This commit should correct
the issue by only setting the direction bit when the direction is
kUSBIn.

Thanks to Jean-Etienne for identifying the issue.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agodarwin: code cleanup
Nathan Hjelm [Fri, 13 Sep 2013 15:59:54 +0000 (09:59 -0600)]
darwin: code cleanup

Clean up some code in the darwin backend.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agodarwin: Add support for bulk stream transfers.
Nathan Hjelm [Thu, 12 Sep 2013 20:57:01 +0000 (14:57 -0600)]
darwin: Add support for bulk stream transfers.

This commit adds support for bulk streams to the darwin backend. I
have not had a chance to fully test this code as I have no access
to any devices that use this interface.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agoUse @rpath in Xcode project
Sean McBride [Tue, 22 Apr 2014 20:53:17 +0000 (16:53 -0400)]
Use @rpath in Xcode project

In the Xcode project, set:

LD_DYLIB_INSTALL_NAME = @rpath

Such that the built dylib's install name uses rpath, which is
generally what one wants.

10 years agoRemoved unneeded casts
Sean McBride [Tue, 22 Apr 2014 20:52:29 +0000 (16:52 -0400)]
Removed unneeded casts

The parameters already match the function declaration; no need to cast.

10 years agoAdd API for using bulk streams
Hans de Goede [Wed, 11 Sep 2013 11:45:01 +0000 (13:45 +0200)]
Add API for using bulk streams

Being able to allocate bulk-streams is not really useful if the user cannot
specify the stream ids when submitting transfers.

The actual stream id gets added to our private itransfer struct, and a setter +
getter are added to get to it. Unfortunately this is the only way to add
support for stream ids without breaking ABI. So this is another item to fix
when we do break ABI in libusb-2.0.

Bulk streams also use a separate transer type, to allow backends to determine
if a transfer is a bulk stream transfer or an ordinary bulk transfer. This is
added because there is no other reliable way to determine if a transfer is
a stream as the stream_id is part of the private itransfer struct so apps
re-using a transfer may not set it to 0. Adding a separate transfer-type
for this was suggested (and coded) by Nathan Hjelm.

Most users will likely use the new libusb_fill_bulk_stream_transfer()
though, and will never know the difference.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoAdd API for allocating / freeing usb3 bulk streams + Linux implementation
Hans de Goede [Wed, 11 Sep 2013 11:06:38 +0000 (13:06 +0200)]
Add API for allocating / freeing usb3 bulk streams + Linux implementation

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years ago Updated netlink code to parse events that do not contain BUSNUM and
Justin Bischoff [Wed, 26 Mar 2014 19:00:20 +0000 (12:00 -0700)]
 Updated netlink code to parse events that do not contain BUSNUM and
  DEVNUM but do have a DEVICE parameter.

 These netlink events are now parsed:
 >>>>>>>>>>>>>>>>>
 add@/devices/platform/brcm-ohci-0.0/usb3/3-2/3-2:1.0
 ACTION=add
 DEVPATH=/devices/platform/brcm-ohci-0.0/usb3/3-2/3-2:1.0
 SUBSYSTEM=usb
 SEQNUM=290
 PHYSDEVBUS=usb
 DEVICE=/proc/bus/usb/003/003
 PRODUCT=45e/28e/114
 TYPE=255/255/255
 INTERFACE=255/93/1
 <<<<<<<<<<<<<<<<<

 Also added a retry when opening the device file to work around a race condition with the kernel

10 years agoexamples: fix incorrect error message in fxload
Carl Karsten [Sun, 6 Apr 2014 15:06:35 +0000 (10:06 -0500)]
examples: fix incorrect error message in fxload

* Closes #3

10 years agoRemoved obsolete comment related to libusbx fork
Sean McBride [Fri, 21 Mar 2014 18:01:57 +0000 (14:01 -0400)]
Removed obsolete comment related to libusbx fork

10 years agoEnabled LTO optimization in release in Xcode project
Sean McBride [Fri, 21 Mar 2014 18:01:23 +0000 (14:01 -0400)]
Enabled LTO optimization in release in Xcode project

10 years agoRemoved empty \see statements, fixing -Wdocumentation warnings
Sean McBride [Fri, 21 Mar 2014 18:00:28 +0000 (14:00 -0400)]
Removed empty \see statements, fixing -Wdocumentation warnings

10 years agoEnabled additional warnings in Xcode project
Sean McBride [Fri, 21 Mar 2014 18:00:04 +0000 (14:00 -0400)]
Enabled additional warnings in Xcode project

10 years agodarwin: squash warning about returning size_t as int
Nathan Hjelm [Fri, 21 Mar 2014 19:23:39 +0000 (13:23 -0600)]
darwin: squash warning about returning size_t as int

I also updated the documentation on the backend get_config_descriptor
function. The documentation incorrectly stated that this function returns
0 on success when it really returns the length of the descriptor.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agoDocumentation: Update the doxygen tagline
Pete Batard [Thu, 20 Mar 2014 00:03:56 +0000 (00:03 +0000)]
Documentation: Update the doxygen tagline

* Make it the same as the one used on the website and elsewhere

10 years agodarwin: use destructor function instead of atexit to cleanup state
Nathan Hjelm [Wed, 26 Feb 2014 15:02:40 +0000 (08:02 -0700)]
darwin: use destructor function instead of atexit to cleanup state

Using an atexit function to cleanup the state could cause weird interactions
with other atexit functions. Ensure the darwin cleanup function is called
last by making it a destructor function instead.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
10 years agoWindows: Add support for AMD USB 3.0 root hubs
Markus Heidelberg [Fri, 20 Dec 2013 19:37:32 +0000 (20:37 +0100)]
Windows: Add support for AMD USB 3.0 root hubs

* The driver has to be updated to version 1.0.0.66 (2011-10-25) or later
* Older versions can fail with the following warning:
  could not get node connection information for device [..]: [87] The parameter is incorrect.
* Also Remove duplicated "API" string in debug output
* Closes #1

10 years agoDocumentation: fix hotplug example
Markus Heidelberg [Sun, 2 Feb 2014 14:41:20 +0000 (15:41 +0100)]
Documentation: fix hotplug example

* add a missing call to libusb_handle_events_completed()
* add a missing argument to libusb_hotplug_deregister_callback()

10 years agoWindows: Add support for (old?) Intel USB 3.0 hub driver
Pete Batard [Sat, 1 Feb 2014 22:38:26 +0000 (22:38 +0000)]
Windows: Add support for (old?) Intel USB 3.0 hub driver

* Has VID:PID 8086:1111

10 years agolibusb 1.0.18
Pete Batard [Sat, 25 Jan 2014 22:43:39 +0000 (22:43 +0000)]
libusb 1.0.18

10 years agoWindows: Fix MinGW parallel build
xantares [Fri, 24 Jan 2014 09:07:11 +0000 (09:07 +0000)]
Windows: Fix MinGW parallel build

10 years agoDarwin: Fix Xcode warning in 'struct timeval' initialization
Sean McBride [Tue, 21 Jan 2014 16:20:20 +0000 (11:20 -0500)]
Darwin: Fix Xcode warning in 'struct timeval' initialization

10 years agolibusb 1.0.18-rc1
Pete Batard [Wed, 8 Jan 2014 23:51:38 +0000 (23:51 +0000)]
libusb 1.0.18-rc1

10 years agoMisc: Revert all references to libusb/libusb.info
hjelmn@cs.unm.edu [Wed, 8 Jan 2014 23:50:34 +0000 (23:50 +0000)]
Misc: Revert all references to libusb/libusb.info

10 years agoWindows: Fix a MinGW compilation issue
Pete Batard [Wed, 8 Jan 2014 19:56:12 +0000 (19:56 +0000)]
Windows: Fix a MinGW compilation issue

* Some MinGW platforms may not have FACILITY_SETUPAPI defined
* Issue introduced with 8b46e1c088167eb86b1712765896e2f17d70d148