From e60573c528081cbf10269ea447e8c3521fddeed0 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sat, 31 Dec 2016 00:04:48 +0300 Subject: [PATCH] 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 Reviewed-on: http://openocd.zylin.com/3931 Tested-by: jenkins --- src/jtag/drivers/usb_blaster/usb_blaster.c | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index a975bd1e..df9f2a17 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -839,26 +839,30 @@ static int ublast_init(void) { int ret, i; - if (info.lowlevel_name) { - for (i = 0; lowlevel_drivers_map[i].name; i++) - if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name)) + for (i = 0; lowlevel_drivers_map[i].name; i++) { + if (info.lowlevel_name) { + if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name)) { + info.drv = lowlevel_drivers_map[i].drv_register(); + if (!info.drv) { + LOG_ERROR("Error registering lowlevel driver \"%s\"", + info.lowlevel_name); + return ERROR_JTAG_DEVICE_ERROR; + } break; - if (lowlevel_drivers_map[i].name) + } + } else { info.drv = lowlevel_drivers_map[i].drv_register(); - if (!info.drv) { - LOG_ERROR("no lowlevel driver found for %s or lowlevel driver opening error", - 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; + if (info.drv) { + info.lowlevel_name = strdup(lowlevel_drivers_map[i].name); + LOG_INFO("No lowlevel driver configured, using %s", info.lowlevel_name); + break; + } } - info.lowlevel_name = strdup(lowlevel_drivers_map[i-1].name); + } + + if (!info.drv) { + LOG_ERROR("No lowlevel driver available"); + return ERROR_JTAG_DEVICE_ERROR; } /* -- 2.39.5