Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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