jtag/hla_interface: avoid segfault with adapters that do not have configurable speed
[fw/openocd] / src / jtag / hla / hla_tcl.c
index 86838b0ca8ad0311d18a98df49ca3d5196b40401..20082f3858f258a4cd4f36328f253673605657a8 100644 (file)
@@ -18,7 +18,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -59,7 +59,13 @@ static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
        return JIM_OK;
 }
 
-#define NTAP_OPT_EXPECTED_ID 0
+#define NTAP_OPT_IRLEN     0
+#define NTAP_OPT_IRMASK    1
+#define NTAP_OPT_IRCAPTURE 2
+#define NTAP_OPT_ENABLED   3
+#define NTAP_OPT_DISABLED  4
+#define NTAP_OPT_EXPECTED_ID 5
+#define NTAP_OPT_VERSION   6
 
 static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi)
 {
@@ -69,8 +75,14 @@ static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi)
        Jim_Nvp *n;
        char *cp;
        const Jim_Nvp opts[] = {
-               {.name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID},
-               {.name = NULL, .value = -1},
+               { .name = "-irlen",       .value = NTAP_OPT_IRLEN },
+               { .name = "-irmask",       .value = NTAP_OPT_IRMASK },
+               { .name = "-ircapture",       .value = NTAP_OPT_IRCAPTURE },
+               { .name = "-enable",       .value = NTAP_OPT_ENABLED },
+               { .name = "-disable",       .value = NTAP_OPT_DISABLED },
+               { .name = "-expected-id",       .value = NTAP_OPT_EXPECTED_ID },
+               { .name = "-ignore-version",       .value = NTAP_OPT_VERSION },
+               { .name = NULL, .value = -1},
        };
 
        pTap = calloc(1, sizeof(struct jtag_tap));
@@ -107,7 +119,7 @@ static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi)
                e = Jim_GetOpt_Nvp(goi, opts, &n);
                if (e != JIM_OK) {
                        Jim_GetOpt_NvpUnknown(goi, opts, 0);
-                       free((void *)pTap->dotted_name);
+                       free(cp);
                        free(pTap);
                        return e;
                }
@@ -116,11 +128,17 @@ static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi)
                case NTAP_OPT_EXPECTED_ID:
                        e = jim_newtap_expected_id(n, goi, pTap);
                        if (JIM_OK != e) {
-                               free((void *)pTap->dotted_name);
+                               free(cp);
                                free(pTap);
                                return e;
                        }
                        break;
+               case NTAP_OPT_IRLEN:
+               case NTAP_OPT_IRMASK:
+               case NTAP_OPT_IRCAPTURE:
+                       /* dummy read to ignore the next argument */
+                       Jim_GetOpt_Wide(goi, NULL);
+                       break;
                }               /* switch (n->value) */
        }                       /* while (goi->argc) */