]> git.sur5r.net Git - openocd/commitdiff
jtag: drivers: usb_blaster: clarify lowlevel driver selection code
authorPaul Fertser <fercerpav@gmail.com>
Fri, 30 Dec 2016 21:04:48 +0000 (00:04 +0300)
committerPaul Fertser <fercerpav@gmail.com>
Sat, 27 Jan 2018 17:16:02 +0000 (17:16 +0000)
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
src/jtag/drivers/usb_blaster/usb_blaster.c

index a975bd1e28b5aeded0758ef4fd5681a0e84a99ed..df9f2a174797d886ed245921526853255d2c5695 100644 (file)
@@ -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;
        }
 
        /*