Skip to content

Commit

Permalink
usb.c : Simplify the "usb:" context scanning
Browse files Browse the repository at this point in the history
the iio_create_scan_context() can take a filter, so use that, rather
than doing it again here.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jun 2, 2020
1 parent 7657cef commit bae0e60
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ struct iio_context * usb_create_context_from_uri(const char *uri)

/* if uri is just "usb:" that means search for the first one */
if (!*ptr) {
ssize_t ret, i, hit = -1;
ssize_t ret;

scan_ctx = iio_create_scan_context(NULL, 0);
scan_ctx = iio_create_scan_context("usb", 0);
if (!scan_ctx) {
errno = ENOMEM;
goto err_bad_uri;
Expand All @@ -1102,27 +1102,11 @@ struct iio_context * usb_create_context_from_uri(const char *uri)
goto err_bad_uri;
}
scan = true;
if (ret == 0) {
if (ret == 0 || ret > 1) {
errno = ENXIO;
goto err_bad_uri;
}
for (i = 0; i < ret; i++) {
ptr = iio_context_info_get_uri(info[i]);
if (strncmp(ptr, "usb:", sizeof("usb:") - 1) != 0)
continue;

if (hit != -1) {
errno = EMLINK;
goto err_bad_uri;
}
hit = (unsigned int)i;
}
if (hit == -1) {
errno = ENXIO;
goto err_bad_uri;
}

ptr = iio_context_info_get_uri(info[hit]);
ptr = iio_context_info_get_uri(info[0]);
ptr += sizeof("usb:") - 1;
}

Expand Down

0 comments on commit bae0e60

Please sign in to comment.