Safe to call function libusb_get_device_list

This commit is contained in:
dreamsourcelabTAI 2023-02-24 10:59:00 +08:00
parent 58d16495fe
commit bfe2b71b54
4 changed files with 36 additions and 0 deletions

View File

@ -221,7 +221,14 @@ static GSList *scan(GSList *options)
/* Find all DSCope compatible devices and upload firmware to them. */
devices = NULL;
devlist = NULL;
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
if (devlist == NULL){
sr_info("%s: Failed to call libusb_get_device_list(), it returns a null list.", __func__);
return NULL;
}
for (i = 0; devlist[i]; i++)
{

View File

@ -314,6 +314,7 @@ static GSList *scan(GSList *options)
break;
}
}
if (conn){
sr_info("%s", "Find usb device with connect config.");
conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
@ -323,8 +324,15 @@ static GSList *scan(GSList *options)
/* Find all DSLogic compatible devices and upload firmware to them. */
devices = NULL;
devlist = NULL;
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
if (devlist == NULL){
sr_info("%s: Failed to call libusb_get_device_list(), it returns a null list.", __func__);
return NULL;
}
for (i = 0; devlist[i]; i++)
{
device_handle = devlist[i];

View File

@ -105,7 +105,15 @@ SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn)
/* Looks like a valid USB device specification, but is it connected? */
devices = NULL;
devlist = NULL;
libusb_get_device_list(usb_ctx, &devlist);
if (devlist == NULL){
sr_info("%s: Failed to call libusb_get_device_list(), it returns a null list.", __func__);
return NULL;
}
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
sr_err("Failed to get device descriptor: %s.",
@ -156,7 +164,15 @@ SR_PRIV GSList *sr_usb_find_usbtmc(libusb_context *usb_ctx)
int confidx, intfidx, ret, i;
devices = NULL;
devlist = NULL;
libusb_get_device_list(usb_ctx, &devlist);
if (devlist == NULL){
sr_info("%s: Failed to call libusb_get_device_list(), it returns a null list.", __func__);
return NULL;
}
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
sr_err("Failed to get device descriptor: %s.",

View File

@ -388,6 +388,11 @@ SR_PRIV int ds_scan_all_device_list(libusb_context *usb_ctx,struct libusb_device
wr = 0;
libusb_get_device_list(usb_ctx, &devlist);
if (devlist == NULL){
sr_info("%s: Failed to call libusb_get_device_list(), it returns a null list.", __func__);
return NULL;
}
for (i = 0; devlist[i]; i++)
{
ret = libusb_get_device_descriptor(devlist[i], &des);