This function pushes a slot/region into the v7M MPU. There is an out-by-one error in the check to see if the slot is in range or not. Consider the case when:
ARMv7M_MPU_REGIONS_MAX = 8
g_mpu_slot = 7
Then the check for overflow (++g_mpu_slot > ARMv7M_MPU_REGIONS_MAX) will fail (since 8 > 8 is false).
I think the fix is to change the strict inequality to (++g_mpu_slot >= ARMv7M_MPU_REGIONS_MAX).
Found using ArchEx.