From 733d8ddc19a9fbefd17495b51359fc5ae509693b Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 26 Jul 2022 05:26:31 +0100 Subject: [PATCH] adiv5: Fix the invalid AP handling loop so that we don't stop early and bail out before time. This improves target detection reliability. --- src/target/adiv5.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/target/adiv5.c b/src/target/adiv5.c index 6ee784c..50ff6fc 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -772,9 +772,9 @@ void adiv5_dp_init(ADIv5_DP_t *dp) /* Probe for APs on this DP */ uint32_t last_base = 0; - int void_aps = 0; + size_t void_aps = 0; dp->refcnt++; - for (int i = 0; (i < 256) && (void_aps < 8); i++) { + for (size_t i = 0; i < 256 && void_aps < 8; ++i) { ADIv5_AP_t *ap = NULL; #if PC_HOSTED == 1 if ((!dp->ap_setup) || dp->ap_setup(i)) @@ -783,17 +783,15 @@ void adiv5_dp_init(ADIv5_DP_t *dp) ap = adiv5_new_ap(dp, i); #endif if (ap == NULL) { - void_aps++; #if PC_HOSTED == 1 if (dp->ap_cleanup) dp->ap_cleanup(i); #endif - if (i == 0) { + if (++void_aps == 8) { adiv5_dp_unref(dp); return; - } else { - continue; } + continue; } if (ap->base == last_base) { DEBUG_WARN("AP %d: Duplicate base\n", i);