[PATCH 1/1] lib: sbi: fix sbi_domain_get_assigned_hartmask()

Anup Patel anup at brainfault.org
Fri Oct 6 04:36:01 PDT 2023


On Wed, Sep 27, 2023 at 7:45 PM Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> '1' is a 32 bit integer. When shifting it by more than 31 bits it becomes
> zero and we get an incorrect return value.
>
> Addresses-Coverity-ID: 1568356 Bad bit shift operation
> Fixes: 296e70d69da7 ("lib: sbi: Extend sbi_hartmask to support both hartid and hartindex")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>

Looks good to me.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/sbi_domain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index b1f485d..fd4a296 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -76,7 +76,7 @@ ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom,
>         ulong ret = 0;
>         for (int i = 0; i < 8 * sizeof(ret); i++) {
>                 if (sbi_domain_is_assigned_hart(dom, hbase + i))
> -                       ret |= 1 << i;
> +                       ret |= 1UL << i;
>         }
>
>         return ret;
> --
> 2.40.1
>



More information about the opensbi mailing list