Windows: Fix broken WDK compilation

* void function call was returning a value
* introduced in 6d8dfe0aee41a3c7dd862c3de488df3ce452d86e
* also fix whitespaces
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>
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.
samples: set xusb to also produce debug output during init when -d is specified

* This can be quite useful for troubleshooting user issues
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
strerrror.c: Add Russian translation

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb 1.0.19-rc1

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ChangeLog: Add an entry about the Russian strerror translation

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
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.
Fix a small typo in comment to free_streams()

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
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>
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>
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>
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>
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>
libusb 1.0.19-rc2

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Made darwin_hotplug_poll static to fix Xcode warning

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
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>
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>
libusb 1.0.19

Signed-off-by: Hans de Goede <hdegoede@redhat.com>