Re: [RFC PATCH 14/18] target/riscv: Return bool from pmp_is_in_range

Alistair <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
On Sat, 2026-08-15 at 13:37 -0700, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  target/riscv/tcg/pmp.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
> 
> diff --git a/target/riscv/tcg/pmp.c b/target/riscv/tcg/pmp.c
> index 5bccc60527..5ea0e5b6c3 100644
> --- a/target/riscv/tcg/pmp.c
> +++ b/target/riscv/tcg/pmp.c
> @@ -299,18 +299,10 @@ void pmp_update_rule_nums(CPURISCVState *env)
>      }
>  }
>  
> -static int pmp_is_in_range(CPURISCVState *env, int pmp_index, hwaddr
> addr)
> +static bool pmp_is_in_range(CPURISCVState *env, int pmp_index,
> hwaddr addr)
>  {
> -    int result = 0;
> -
> -    if ((addr >= env->pmp_state.addr[pmp_index].sa) &&
> -        (addr <= env->pmp_state.addr[pmp_index].ea)) {
> -        result = 1;
> -    } else {
> -        result = 0;
> -    }
> -
> -    return result;
> +    return (addr >= env->pmp_state.addr[pmp_index].sa &&
> +            addr <= env->pmp_state.addr[pmp_index].ea);
>  }
>  
>  /*
> @@ -385,10 +377,7 @@ bool pmp_hart_has_privs(CPURISCVState *env,
> hwaddr addr,
>                          pmp_priv_t *allowed_privs,
>                          privilege_mode_t mode)
>  {
> -    int i = 0;
>      int pmp_size = 0;
> -    hwaddr s = 0;
> -    hwaddr e = 0;
>      uint8_t pmp_regions = riscv_cpu_cfg(env)->pmp_regions;
>  
>      /* Short cut if no rules */
> @@ -414,7 +403,9 @@ bool pmp_hart_has_privs(CPURISCVState *env,
> hwaddr addr,
>       * 1.10 draft priv spec states there is an implicit order
>       * from low to high
>       */
> -    for (i = 0; i < pmp_regions; i++) {
> +    for (int i = 0; i < pmp_regions; i++) {
> +        bool s, e;
> +
>          if (pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg) ==
> PMP_AMATCH_OFF) {
>              continue;
>          }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.