From bae0e60cd2cfd09e0e14b86659f79917e712010c Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Tue, 2 Jun 2020 14:23:53 -0400 Subject: [PATCH] usb.c : Simplify the "usb:" context scanning the iio_create_scan_context() can take a filter, so use that, rather than doing it again here. Signed-off-by: Robin Getz --- usb.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/usb.c b/usb.c index 31184e9e5..bc4af060b 100644 --- a/usb.c +++ b/usb.c @@ -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; @@ -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; }