Skip to content

Commit

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

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
  • Loading branch information
jpaali committed May 23, 2024
1 parent 6f68887 commit f41fc88
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arch/risc-v/src/common/riscv_pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ static bool pmp_check_region_attrs(uintptr_t base, uintptr_t size,

case PMPCFG_A_NAPOT:
{
/* For NAPOT, both base and size must be properly aligned */
/* For NAPOT, Naturally aligned power-of-two region, >= 8 bytes */

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

0 comments on commit f41fc88

Please sign in to comment.