Skip to content

Commit

Permalink
mpfs_mpu: Check that size is valid for MPUCFG
Browse files Browse the repository at this point in the history
The size must be power-of-two for NAPOT according to the the PMP spec.

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
  • Loading branch information
jpaali committed May 24, 2024
1 parent e7ba9ec commit 8f8a77b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions arch/risc-v/src/mpfs/mpfs_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ int mpfs_mpu_set(uintptr_t reg, uintptr_t perm, uintptr_t base,
return -EACCES;
}

/* Base must be word aligned, minimum size is 4K */
/* Base must be word aligned,
* minimum size is 4K and it has to be power-of-two
*/

if ((base & 0x07) != 0 || size < 0x1000)
if ((base & 0x07) != 0 || size < 0x1000 || (size & (size - 1)) != 0)
{
return -EINVAL;
}
Expand Down

0 comments on commit 8f8a77b

Please sign in to comment.