jtag: drivers: usb_blaster: clarify lowlevel driver selection code

This patch should make the code logic more transparent and user
notifications more useful.

It also fixes a warning "array subscript is below array bounds" that
leads to FTBFS on Raspbian GNU/Linux 8 (jessie).

Change-Id: I626b6a5bc013dfee7d36cf196f0abab981d30675
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/3931
Tested-by: jenkins
This commit is contained in:
Paul Fertser 2016-12-31 00:04:48 +03:00
parent a0c4c9e717
commit e60573c528
1 changed files with 21 additions and 17 deletions

View File

@ -839,26 +839,30 @@ static int ublast_init(void)
{
int ret, i;
for (i = 0; lowlevel_drivers_map[i].name; i++) {
if (info.lowlevel_name) {
for (i = 0; lowlevel_drivers_map[i].name; i++)
if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name))
break;
if (lowlevel_drivers_map[i].name)
if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name)) {
info.drv = lowlevel_drivers_map[i].drv_register();
if (!info.drv) {
LOG_ERROR("no lowlevel driver found for %s or lowlevel driver opening error",
LOG_ERROR("Error registering lowlevel driver \"%s\"",
info.lowlevel_name);
return ERROR_JTAG_DEVICE_ERROR;
}
} else {
LOG_INFO("No lowlevel driver configured, will try them all");
for (i = 0; !info.drv && lowlevel_drivers_map[i].name; i++)
info.drv = lowlevel_drivers_map[i].drv_register();
if (!info.drv) {
LOG_ERROR("no lowlevel driver found");
return ERROR_JTAG_DEVICE_ERROR;
break;
}
info.lowlevel_name = strdup(lowlevel_drivers_map[i-1].name);
} else {
info.drv = lowlevel_drivers_map[i].drv_register();
if (info.drv) {
info.lowlevel_name = strdup(lowlevel_drivers_map[i].name);
LOG_INFO("No lowlevel driver configured, using %s", info.lowlevel_name);
break;
}
}
}
if (!info.drv) {
LOG_ERROR("No lowlevel driver available");
return ERROR_JTAG_DEVICE_ERROR;
}
/*