From f45c56af83eb79d8c6f7b68d4c25df3b65d6de6a Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 28 Nov 2020 17:40:37 +0100 Subject: [PATCH] adiv5/swdp: Check early for valid DP idcode. --- src/target/adiv5.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/target/adiv5.c b/src/target/adiv5.c index d6eafe9..8ab2a25 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -614,6 +614,12 @@ ADIv5_AP_t *adiv5_new_ap(ADIv5_DP_t *dp, uint8_t apsel) void adiv5_dp_init(ADIv5_DP_t *dp) { + /* Check IDCODE for a valid designer*/ + if ((dp->idcode & 0xfff) == 0) { + DEBUG_WARN("Invalid DP idcode %08" PRIx32 "\n", dp->idcode); + free(dp); + return; + } DEBUG_INFO("DPIDR 0x%08" PRIx32 " (v%d %srev%d)\n", dp->idcode, (dp->idcode >> 12) & 0xf, (dp->idcode & 0x10000) ? "MINDP " : "", dp->idcode >> 28);