From ea8b44ed7b684159760f909fc1deef50570e3148 Mon Sep 17 00:00:00 2001 From: Ritvik Date: Thu, 24 Oct 2024 00:54:57 -0400 Subject: [PATCH 1/2] Fix Infinite Loop in arm_dcache.c Infinite Loop can happen since `ways` is assigned to an `int32_t tmpways`. This can cause infinite loop if `ways` gets a sufficiently large integer. --- arch/arm/src/armv7-m/arm_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c index 78cfbb3fc2a5b..9ec3a4e75fc26 100644 --- a/arch/arm/src/armv7-m/arm_cache.c +++ b/arch/arm/src/armv7-m/arm_cache.c @@ -529,7 +529,7 @@ void up_enable_dcache(void) ARM_DSB(); do { - int32_t tmpways = ways; + uint32_t tmpways = ways; do { From 2506959de00639b7b207a133d37b6ffbbe74dbe5 Mon Sep 17 00:00:00 2001 From: Ritvik Date: Thu, 24 Oct 2024 11:20:50 -0400 Subject: [PATCH 2/2] Fix the infinite loop in up_enable_dcache --- arch/arm/src/armv7-m/arm_cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c index 9ec3a4e75fc26..99704876c0d90 100644 --- a/arch/arm/src/armv7-m/arm_cache.c +++ b/arch/arm/src/armv7-m/arm_cache.c @@ -529,14 +529,13 @@ void up_enable_dcache(void) ARM_DSB(); do { - uint32_t tmpways = ways; - + int32_t tmpways = ways; do { sw = ((tmpways << wshift) | (sets << sshift)); putreg32(sw, NVIC_DCISW); } - while (tmpways--); + while (tmpways > 0 && tmpways--) } while (sets--);