Skip to content

Instantly share code, notes, and snippets.

@pcercuei
Created January 12, 2017 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcercuei/896c8f6dfb21e715a3ef25ec1a97df55 to your computer and use it in GitHub Desktop.
Save pcercuei/896c8f6dfb21e715a3ef25ec1a97df55 to your computer and use it in GitHub Desktop.
diff --git a/usb.c b/usb.c
index 0f1875b..3cdb184 100644
--- a/usb.c
+++ b/usb.c
@@ -1120,6 +1120,7 @@ int usb_context_scan(struct iio_scan_backend_context *ctx,
{
struct iio_context_info **info;
libusb_device **device_list;
+ bool had_eaccess = false, found_one = false;
unsigned int i;
int ret;
@@ -1133,10 +1134,14 @@ int usb_context_scan(struct iio_scan_backend_context *ctx,
unsigned int interface = 0;
ret = libusb_open(dev, &hdl);
+ if (ret == LIBUSB_ERROR_ACCESS)
+ had_eaccess = true;
if (ret)
continue;
if (!iio_usb_match_device(dev, hdl, &interface)) {
+ found_one = true;
+
info = iio_scan_result_add(scan_result, 1);
if (!info)
ret = -ENOMEM;
@@ -1150,7 +1155,10 @@ int usb_context_scan(struct iio_scan_backend_context *ctx,
goto cleanup_free_device_list;
}
- ret = 0;
+ if (!found_one && had_eaccess)
+ ret = -EACCES;
+ else
+ ret = 0;
cleanup_free_device_list:
libusb_free_device_list(device_list, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment