You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/05/24 13:33:02 UTC

(nuttx) 02/02: mpfs_mpu: Check that size is valid for MPUCFG

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit cfa544357eb3081e49f54e5fe3eef8392f26d9ab
Author: Jani Paalijarvi <ja...@unikie.com>
AuthorDate: Fri May 24 08:57:41 2024 +0300

    mpfs_mpu: Check that size is valid for MPUCFG
    
    The size must be power-of-two for NAPOT according to the the PMP spec.
    
    Signed-off-by: Jani Paalijarvi <ja...@unikie.com>
---
 arch/risc-v/src/mpfs/mpfs_mpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/risc-v/src/mpfs/mpfs_mpu.c b/arch/risc-v/src/mpfs/mpfs_mpu.c
index 2643c79c0a..2adaf3d911 100644
--- a/arch/risc-v/src/mpfs/mpfs_mpu.c
+++ b/arch/risc-v/src/mpfs/mpfs_mpu.c
@@ -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;
     }