Skip to content

Commit bae0e60

Browse files
committed
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 <[email protected]>
1 parent 7657cef commit bae0e60

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

usb.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,9 @@ struct iio_context * usb_create_context_from_uri(const char *uri)
10871087

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

1092-
scan_ctx = iio_create_scan_context(NULL, 0);
1092+
scan_ctx = iio_create_scan_context("usb", 0);
10931093
if (!scan_ctx) {
10941094
errno = ENOMEM;
10951095
goto err_bad_uri;
@@ -1102,27 +1102,11 @@ struct iio_context * usb_create_context_from_uri(const char *uri)
11021102
goto err_bad_uri;
11031103
}
11041104
scan = true;
1105-
if (ret == 0) {
1105+
if (ret == 0 || ret > 1) {
11061106
errno = ENXIO;
11071107
goto err_bad_uri;
11081108
}
1109-
for (i = 0; i < ret; i++) {
1110-
ptr = iio_context_info_get_uri(info[i]);
1111-
if (strncmp(ptr, "usb:", sizeof("usb:") - 1) != 0)
1112-
continue;
1113-
1114-
if (hit != -1) {
1115-
errno = EMLINK;
1116-
goto err_bad_uri;
1117-
}
1118-
hit = (unsigned int)i;
1119-
}
1120-
if (hit == -1) {
1121-
errno = ENXIO;
1122-
goto err_bad_uri;
1123-
}
1124-
1125-
ptr = iio_context_info_get_uri(info[hit]);
1109+
ptr = iio_context_info_get_uri(info[0]);
11261110
ptr += sizeof("usb:") - 1;
11271111
}
11281112

0 commit comments

Comments
 (0)