arm: nxp: mpu: Fix off-by-1 error in region index calculation

Both the ARM and NXP MPU drivers incorrectly calculated the region index
by assuming the region type (e.g., THREAD_STACK_GUARD_REGION) was
zero-indexed, when in reality it is one-indexed. This had the effect of
wasting one region.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2017-06-08 22:58:17 -05:00 committed by Kumar Gala
commit 1f3f440b22
2 changed files with 10 additions and 6 deletions

View file

@ -108,10 +108,12 @@ void arm_core_mpu_configure(u8_t type, u32_t base, u32_t size)
{
SYS_LOG_DBG("Region info: 0x%x 0x%x", base, size);
/*
* The new MPU regions are are allocated per type after the statically
* configured regions.
* The new MPU regions are allocated per type after the statically
* configured regions. The type is one-indexed rather than
* zero-indexed, therefore we need to subtract by one to get the region
* index.
*/
u32_t region_index = mpu_config.num_regions + type;
u32_t region_index = mpu_config.num_regions + type - 1;
u32_t region_attr = _get_region_attr_by_type(type, size);
/* ARM MPU supports up to 16 Regions */

View file

@ -120,10 +120,12 @@ void arm_core_mpu_configure(u8_t type, u32_t base, u32_t size)
{
SYS_LOG_DBG("Region info: 0x%x 0x%x", base, size);
/*
* The new MPU regions are are allocated per type after the statically
* configured regions.
* The new MPU regions are allocated per type after the statically
* configured regions. The type is one-indexed rather than
* zero-indexed, therefore we need to subtract by one to get the region
* index.
*/
u32_t region_index = mpu_config.num_regions + type;
u32_t region_index = mpu_config.num_regions + type - 1;
u32_t region_attr = _get_region_attr_by_type(type);
u32_t last_region = _get_num_regions() - 1;