platform/upstream/libusb.git
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

10 years agoDarwin: Fix format of 64-bit sessionIDs in log messages
Matthias Bolte [Mon, 14 Oct 2013 17:05:12 +0000 (19:05 +0200)]
Darwin: Fix format of 64-bit sessionIDs in log messages

* The sessionID value is 64-bit, so print it as such.
* Closes #153

10 years agoDarwin: Fix a SIGFPE
Bei Zhang [Fri, 23 Aug 2013 08:10:35 +0000 (01:10 -0700)]
Darwin: Fix a SIGFPE

* GetPipeProperties() may fail when the device is unplugged if DeviceVersion is not greater than 320.
* In this case maxPacketSize will be zero and the integer division will throw a EXC_ARITHMETIC signal.
* Closes #136

10 years agoDarwin: Return error code in darwin_error_str() on unknown error
Francisco Facioni [Fri, 14 Jun 2013 16:03:54 +0000 (13:03 -0300)]
Darwin: Return error code in darwin_error_str() on unknown error

* Closes #117

10 years agoWindows: Add SetupAPI error handling
Pete Batard [Mon, 30 Dec 2013 21:32:28 +0000 (21:32 +0000)]
Windows: Add SetupAPI error handling

* http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
  states that SetupAPI errors must be be converted before passing it to FormatMessage().
* Use our own implementation of HRESULT_FROM_SETUPAPI to avoid defining a new function call.
* Issue and original fix suggested by Matthias Bolte
* Closes #166

10 years agoLinux: Remove trailing whitespace
Moritz Fischer [Thu, 7 Nov 2013 07:56:31 +0000 (08:56 +0100)]
Linux: Remove trailing whitespace

* Closes #157

10 years agoAndroid: Add support for Linux/Android platforms
Kuangye Guo [Tue, 22 Oct 2013 01:36:15 +0000 (18:36 -0700)]
Android: Add support for Linux/Android platforms

* Closes #154

10 years agoAndroid: Build for all Android architectures
Andrew Fernandes [Tue, 20 Aug 2013 16:19:26 +0000 (12:19 -0400)]
Android: Build for all Android architectures

* Don't limit support to ARM only (adds MIPS support)
* Also add a workaround for a MIPS NDK linker bug
* Also add a gitignore entry required to run bootstrap.sh on OS X
* Closes #134

10 years agoWindows: Add Visual Studio 2013 solution files
Joshua Blake [Mon, 9 Dec 2013 03:58:17 +0000 (22:58 -0500)]
Windows: Add Visual Studio 2013 solution files

* Also update gitignore
* Closes #162

10 years agocore: fix Doxygen warning
Ludovic Rousseau [Fri, 6 Dec 2013 15:56:16 +0000 (16:56 +0100)]
core: fix Doxygen warning

libusbx/libusb/libusb.h:153: warning: no matching file member found for
libusb_cpu_to_le16()Possible candidates:
  static uint16_t libusb_cpu_to_le16(const uint16_t x)

Thanks to Serhat Sevki Dincer for the bug report
http://sourceforge.net/mailarchive/message.php?msg_id=31719691

10 years agoWindows: Fix a crash when HID transfers return no data
Pete Batard [Wed, 27 Nov 2013 22:02:55 +0000 (22:02 +0000)]
Windows: Fix a crash when HID transfers return no data

* Issue reported by Surmakyynis
* Closes #160

10 years agocore: Make LIBUSB_DEBUG environment variable also work from libusb_exit
Hans de Goede [Tue, 15 Oct 2013 14:03:05 +0000 (16:03 +0200)]
core: Make LIBUSB_DEBUG environment variable also work from libusb_exit

libusb_exit sets usbi_default_context to NULL, modify usbi_log_v so that
it still honors the  LIBUSB_DEBUG environment variable in this case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Fix usb_device memleak with hotunplug events pending on libusb_exit
Hans de Goede [Tue, 15 Oct 2013 13:30:02 +0000 (15:30 +0200)]
hotplug: Fix usb_device memleak with hotunplug events pending on libusb_exit

Closes #150

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoio: Ensure all pending events are consumed in one libusb_handle_events call
Hans de Goede [Tue, 15 Oct 2013 13:15:31 +0000 (15:15 +0200)]
io: Ensure all pending events are consumed in one libusb_handle_events call

Before this patch if ie multiple hot-plug events were pending, multiple
handle_events calls would be necessary to handle them all, this patch
changes handle_events so that the poll is re-done to check for more events
if there was activity on any of the special fds.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoWindows: Add support for VIA VL805 USB 3.0 Host Controllers
Omri Iluz [Mon, 7 Oct 2013 11:09:12 +0000 (04:09 -0700)]
Windows: Add support for VIA VL805 USB 3.0 Host Controllers

* These controllers identify themselves as VUSB3HUB
* Closes #152

10 years agoexamples: check value returned by ftell()
Ludovic Rousseau [Sun, 6 Oct 2013 12:23:20 +0000 (14:23 +0200)]
examples: check value returned by ftell()

Problem detected by the Coverity tool
CID 1042546 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)3.
negative_returns: "initial_pos" is passed to a parameter that cannot be
negative.

fseek(3) can't be called with a negative offset with SEEK_SET

10 years agoWindows: Avoid potential mismatch in transfer error reporting
Matthias Bolte [Tue, 1 Oct 2013 12:10:48 +0000 (14:10 +0200)]
Windows: Avoid potential mismatch in transfer error reporting

The default case in windows_transfer_callback() calls windows_error_str(0)
which will convert the error code returned by GetLastError() to a string.
This currently works because windows_transfer_callback() is either called
with io_result set to NO_ERROR or io_result set to GetLastError().

If windows_transfer_callback() will ever be called with io_result set
differently then the default case might report the wrong error message.

Call windows_error_str(io_result) instead to avoid this.

Closes #151

10 years agoexamples: add an option to force a device request for WCID descriptors
Pete Batard [Sun, 29 Sep 2013 20:39:26 +0000 (21:39 +0100)]
examples: add an option to force a device request for WCID descriptors

* Add option 'w' to force the use of a Device Request rather than an
  Interface Request when querying the WCID OS Extended Properties descriptor.
* This is due to a WinUSB limitation where all Interface Requests have the
  wIndex set to the interface number.
* This assumes that the WCID firmware answers both Device and Interface requests
  equally.

10 years agoexamples: fix warning
Ludovic Rousseau [Sat, 28 Sep 2013 11:14:17 +0000 (13:14 +0200)]
examples: fix warning

ezusb.c: In function 'ezusb_load_ram':
ezusb.c:719:6: warning: 'ret' may be used uninitialized in this function
[-Wmaybe-uninitialized]
  int ret;

10 years agotests: set output_file to a valid value
Ludovic Rousseau [Sun, 22 Sep 2013 19:29:50 +0000 (21:29 +0200)]
tests: set output_file to a valid value

If fdopen(3) fails then ctx->output_file is NULL and should not be used
in cleanup_test_output() called next.

Problem detected by the Coverity tool
CID 1042543 (#1 of 1): Dereference after null check (FORWARD_NULL)9.
var_deref_model: Passing "ctx" to function
"cleanup_test_output(libusbx_testlib_ctx *)", which dereferences null
"ctx->output_file".

10 years agoexamples: check value returned by libusb_bulk_transfer()
Ludovic Rousseau [Sun, 22 Sep 2013 19:25:00 +0000 (21:25 +0200)]
examples: check value returned by libusb_bulk_transfer()

Problem detected by the Coverity tool
CID 1042540 (#1 of 1): Unchecked return value (CHECKED_RETURN)1.
check_return: Calling function "libusb_bulk_transfer(struct
libusb_device_handle *, unsigned char, unsigned char *, int, int *,
unsigned int)" without checking return value (as is done elsewhere 4 out
of 5 times).

10 years agoexamples: check the value returned by libusb_handle_events()
Ludovic Rousseau [Sun, 22 Sep 2013 19:19:06 +0000 (21:19 +0200)]
examples: check the value returned by libusb_handle_events()

Problem detected by the Coverity tool
CID 1042539 (#1 of 1): Unchecked return value (CHECKED_RETURN)8.
check_return: Calling function "libusb_handle_events(libusb_context *)"
without checking return value (as is done elsewhere 6 out of 7 times).

10 years agoexamples: check the value returned by libusb_init()
Ludovic Rousseau [Sun, 22 Sep 2013 19:15:56 +0000 (21:15 +0200)]
examples: check the value returned by libusb_init()

Problem detected by the Coverity tool
CID 1042538 (#1 of 1): Unchecked return value (CHECKED_RETURN)4.
check_return: Calling function "libusb_init(libusb_context **)" without
checking return value (as is done elsewhere 11 out of 12 times).

10 years agolinux: take newline into account for sysfs_get_active_config
Karsten Koenig [Wed, 25 Sep 2013 22:08:16 +0000 (18:08 -0400)]
linux: take newline into account for sysfs_get_active_config

bConfigurationValue in sysfs can be 3 digits (1byte value) + 1 new line
= 4 bytes

In it's current form a bConfigurationValue of 128 will be detected as
not null terminated due to the trailing newline, simple fix is to just
extend the array size to 5

10 years agoexamples: Fix a memory leak
Ludovic Rousseau [Thu, 19 Sep 2013 21:51:04 +0000 (23:51 +0200)]
examples: Fix a memory leak

Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042549 (#2 of 3): Resource leak (RESOURCE_LEAK)9. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.

10 years agoexamples: Fix a memory leak
Ludovic Rousseau [Thu, 19 Sep 2013 21:46:14 +0000 (23:46 +0200)]
examples: Fix a memory leak

Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042550 (#1 of 15): Resource leak (RESOURCE_LEAK)7. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.

10 years agoFix darwin compilation broken by the usbi_get_device_by_session_id changes
Hans de Goede [Sun, 15 Sep 2013 09:47:23 +0000 (11:47 +0200)]
Fix darwin compilation broken by the usbi_get_device_by_session_id changes

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoMake usbi_get_device_by_session_id return a ref to the found device
Hans de Goede [Fri, 6 Sep 2013 14:49:26 +0000 (16:49 +0200)]
Make usbi_get_device_by_session_id return a ref to the found device

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Fix a memleak
Hans de Goede [Fri, 6 Sep 2013 14:45:10 +0000 (16:45 +0200)]
openbsd: Fix a memleak

discovered_devs_append takes a reference to the past in dev, so we must
release our own reference.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Fix usbi_sanitize_device error handling
Hans de Goede [Fri, 6 Sep 2013 14:40:51 +0000 (16:40 +0200)]
openbsd: Fix usbi_sanitize_device error handling

If usbi_sanitize_device fails we need to continue from the beginning of
the loop, rather then going on with the device we've just free-ed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoconfigure.ac: uclinux is also linux
Gustavo Zacarias [Tue, 3 Sep 2013 13:24:04 +0000 (10:24 -0300)]
configure.ac: uclinux is also linux

When the tuple contains uclinux rather than just linux (nommu flat
targets) configure will fail with an unknown operating system.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRelease 1.0.17
Hans de Goede [Fri, 6 Sep 2013 09:20:53 +0000 (11:20 +0200)]
Release 1.0.17

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoWindows: Address an VS2012/x64 warning in hotplug.c
Xiaofan Chen [Mon, 2 Sep 2013 10:35:40 +0000 (11:35 +0100)]
Windows: Address an VS2012/x64 warning in hotplug.c

..\libusb\hotplug.c(255): warning C4244: '=' : conversion from
'ssize_t' to 'int', possible loss of data

10 years agoNathan is a maintainer now, so add him to the README
Hans de Goede [Fri, 30 Aug 2013 14:50:12 +0000 (16:50 +0200)]
Nathan is a maintainer now, so add him to the README

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRemove unused THANKS file
Hans de Goede [Fri, 30 Aug 2013 14:49:32 +0000 (16:49 +0200)]
Remove unused THANKS file

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoMakefile.am: Add Xcode dir to EXTRA_DIST
Hans de Goede [Fri, 30 Aug 2013 14:44:45 +0000 (16:44 +0200)]
Makefile.am: Add Xcode dir to EXTRA_DIST

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoAndroid: Add android build files to source tarball
Toby Gray [Fri, 30 Aug 2013 12:42:34 +0000 (14:42 +0200)]
Android: Add android build files to source tarball

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRelease 1.0.17-rc1
Hans de Goede [Wed, 28 Aug 2013 08:17:53 +0000 (10:17 +0200)]
Release 1.0.17-rc1

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agodarwin: return libusb error codes instead of kernel error codes and fix
Nathan Hjelm [Tue, 27 Aug 2013 02:40:52 +0000 (20:40 -0600)]
darwin: return libusb error codes instead of kernel error codes and fix
a bug introduced in the last commit.

10 years agodarwin: clean up some code. remove a clang warning
Nathan Hjelm [Tue, 27 Aug 2013 02:12:23 +0000 (20:12 -0600)]
darwin: clean up some code. remove a clang warning

The check for NULL != cached_device was unnecessary and caused clang's
static analysis to print out a warning.

10 years agoAndroid: Add further documentation to Android README file
Toby Gray [Wed, 21 Aug 2013 14:27:03 +0000 (16:27 +0200)]
Android: Add further documentation to Android README file

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoOpenBSD: Add basic support for non ugen(4) devices using usb(4)
Martin Pieuchot [Tue, 16 Jul 2013 09:32:23 +0000 (11:32 +0200)]
OpenBSD: Add basic support for non ugen(4) devices using usb(4)

It is now possible to have a read access and submit control transfers
to all USB devices using libusb, please note that controllers and hubs
also appear as devices.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Split openbsd backend into separate openbsd and netbsd backends
Hans de Goede [Wed, 21 Aug 2013 14:18:39 +0000 (16:18 +0200)]
openbsd: Split openbsd backend into separate openbsd and netbsd backends

Note the new netbsd_usb.c is an unmodified copy of openbsd_usb.c with
s/obsd/netbsd done on it. The reason for this split is that the openbsd
developers have been working on various improvements for their userspace
usb support, and adding support for those means breaking netbsd support,
by giving netbsd its own backend we can add support for the openbsd
improvements without breaking netbsd support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoClarify alignment requirements for the control transfer buffer
Paul Fertser [Mon, 1 Jul 2013 17:07:24 +0000 (21:07 +0400)]
Clarify alignment requirements for the control transfer buffer

Since the buffer pointer will later be casted to ``struct
libusb_control_setup *'', it should point to memory aligned to at least
2 bytes boundary as that's the strictest requirement of the struct fields.

Also, use a (void *) casting trick to convince the compiler the cast is
safe, to fix warnings such as:

/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_control_transfer_get_setup':
/usr/local/include/libusb-1.0/libusb.h:1435:9: error: cast increases required alignment of target type [-Werror=cast-align]
/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_fill_control_setup':
/usr/local/include/libusb-1.0/libusb.h:1464:39: error: cast increases required alignment of target type [-Werror=cast-align]
/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_fill_control_transfer':
/usr/local/include/libusb-1.0/libusb.h:1509:39: error: cast increases required alignment of target type [-Werror=cast-align]
cc1: all warnings being treated as errors

This actually can lead to failure to build from the sources for certain
projects which use -Werror=cast-align on ARM.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux: Handle device disconnection early when possible
Chris Dickens [Thu, 27 Jun 2013 16:14:15 +0000 (09:14 -0700)]
linux: Handle device disconnection early when possible

If a device is open, the device's fd will trigger a POLLERR condition
once it is removed. Sometimes this can occur well before the udev
monitor sends the remove event. This can also be caught early if
the device is not currently open but an attempt to open it is made.

In both situations, this can be caught early and processed so that
the device does not continue to show up in the device list after it
has been disconnected but before the udev monitor processes the event.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Document LIBUSB_HOTPLUG_ENUMERATE gotchas
Hans de Goede [Wed, 21 Aug 2013 12:46:45 +0000 (14:46 +0200)]
hotplug: Document LIBUSB_HOTPLUG_ENUMERATE gotchas

When libusb_hotplug_register_callback gets called with the
LIBUSB_HOTPLUG_ENUMERATE flag, there may still be hotplug events pending
in the hotplug pipe, waiting for dispatching from libusb_handle_events.

This means that the user callback can be called twice for arrival of the
same device, once from libusb_hotplug_register_callback, since the device
is already part of the usb_devs list, and once from libusb_handle_events
when it reads the event from the hotplug pipe.

This could be fixed by adding a mechanism to pause hotplug handling, then
drain the hotplug pipe (ie by calling libusb_handle_events from
libusb_hotplug_register_callback), before iterating over the usb_devs list,
and then un-pausing hotplug handling afterwards, doing this however requires
a lot of hairy code, which will be prone to dead-locking.

OTOH it is quite simple for user applications which care about this to detect
this and ignore the 2nd call, so lets simply document this may happen and
be done with it.

Note that this is also the solution which ie libudev has choosen, there is
no way with libudev to get a device-list + listen for device arrival / removal
without running into the same problem.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Document that callbacks cannot unregister themselves when called from hotplu...
Hans de Goede [Wed, 21 Aug 2013 12:30:51 +0000 (14:30 +0200)]
hotplug: Document that callbacks cannot unregister themselves when called from hotplug_register_callback

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Don't call the user callback while holding various locks
Hans de Goede [Wed, 21 Aug 2013 12:18:09 +0000 (14:18 +0200)]
hotplug: Don't call the user callback while holding various locks

Calling user callbacks with locks held is a bad idea and should be avoided
whenever possible. Before this patch this could lead ie to the following hang:

1) User calls libusb_hotplug_register_callback with the
   LIBUSB_HOTPLUG_ENUMERATE flag
2) libusb_hotplug_register_callback calls the user callback while holding the
   hotplug_cbs_lock
3) The callback calls a synchronous libusb function
4) The synchronous libusb function calls libusb_handle_events
5) There is an hotplug event waiting in the hotplug pipe and
   libusb_handle_events calls usbi_hotplug_match
6) usbi_hotplug_match tries to take the lock a 2nd time
7) hang / assert / abort (depending on the platform)

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Remove device from usb_devs before signalling its removal
Hans de Goede [Tue, 20 Aug 2013 13:18:59 +0000 (15:18 +0200)]
hotplug: Remove device from usb_devs before signalling its removal

If we write the remove event to the pipe before doing the list_del,
in theory another thread can process the event and unref the device before
it has been removed from usb_devs.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolibusb: Fix usb_devs_lock mutex use after free in libusb_init error path
Hans de Goede [Tue, 20 Aug 2013 12:41:36 +0000 (14:41 +0200)]
libusb: Fix usb_devs_lock mutex use after free in libusb_init error path

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux/netlink: correct usage of fcntl
Nathan Hjelm [Wed, 14 Aug 2013 17:08:36 +0000 (11:08 -0600)]
linux/netlink: correct usage of fcntl

Closes #130

10 years agoWindows: Fix a cast warning when compiling for x64 in VS
Pete Batard [Tue, 13 Aug 2013 18:00:54 +0000 (19:00 +0100)]
Windows: Fix a cast warning when compiling for x64 in VS

* Also fixes and closes #129 again