Skip to content

Commit 349b106

Browse files
committed
arch: arm: cortex_m: do not read MMFAR if MMARVALID is not set
When the MMARVALID bit is not set, do not read the MMFAR register to get the fault address in a MemManage fault. This change prevents the fault handler to erroneously assume MMFAR contains a valid address. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent fc1b5de commit 349b106

File tree

1 file changed

+3
-2
lines changed
  • arch/arm/core/aarch32/cortex_m

1 file changed

+3
-2
lines changed

arch/arm/core/aarch32/cortex_m/fault.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ static uint32_t mem_manage_fault(z_arch_esf_t *esf, int from_hard_fault,
230230
* Software must follow this sequence because another higher
231231
* priority exception might change the MMFAR value.
232232
*/
233-
mmfar = SCB->MMFAR;
233+
uint32_t temp = SCB->MMFAR;
234234

235235
if ((SCB->CFSR & SCB_CFSR_MMARVALID_Msk) != 0) {
236+
mmfar = temp;
236237
PR_EXC(" MMFAR Address: 0x%x", mmfar);
237238
if (from_hard_fault) {
238239
/* clear SCB_MMAR[VALID] to reset */
@@ -248,7 +249,7 @@ static uint32_t mem_manage_fault(z_arch_esf_t *esf, int from_hard_fault,
248249
PR_FAULT_INFO(
249250
" Floating-point lazy state preservation error");
250251
}
251-
#endif /* !defined(CONFIG_ARMV7_M_ARMV8_M_FP) */
252+
#endif /* CONFIG_ARMV7_M_ARMV8_M_FP */
252253

253254
/* When stack protection is enabled, we need to assess
254255
* if the memory violation error is a stack corruption.

0 commit comments

Comments
 (0)