target/cortex_m: prevent segmentation fault in cortex_m_poll()
[fw/openocd] / src / target / hla_target.c
index a0f2d760868a5c784805b1455ff30dc0fff47f1c..748905691d065e66114e9658066ca2f53ac69b3e 100644 (file)
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2011 by Mathias Kuester                                 *
  *   Mathias Kuester <kesmtp@freenet.de>                                   *
@@ -6,19 +8,6 @@
  *   spen@spen-soft.co.uk                                                  *
  *                                                                         *
  *   revised:  4/25/13 by brent@mbari.org [DCC target request support]    *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -203,7 +192,7 @@ static int adapter_target_create(struct target *target,
 {
        LOG_DEBUG("%s", __func__);
        struct adiv5_private_config *pc = target->private_config;
-       if (pc && pc->ap_num > 0) {
+       if (pc && pc->ap_num != DP_APSEL_INVALID && pc->ap_num != 0) {
                LOG_ERROR("hla_target: invalid parameter -ap-num (> 0)");
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
@@ -214,6 +203,8 @@ static int adapter_target_create(struct target *target,
                return ERROR_FAIL;
        }
 
+       cortex_m->common_magic = CORTEX_M_COMMON_MAGIC;
+
        adapter_init_arch_info(target, cortex_m, target->tap);
 
        return ERROR_OK;