[PATCH] lib: utils/irqchip: Add sanity checks in imsic_get_data() and imsic_get_target_file()

Anup Patel anup at brainfault.org
Thu May 23 05:30:18 PDT 2024


On Thu, May 16, 2024 at 2:03 PM Cyan Yang <cyan.yang at sifive.com> wrote:
>
> Add extra sanity checks to prevent the caller getting the invalid result from
> imsic_get_data() or imsic_get_target_file() when imsic is not initialized
> correctly.
>
> Signed-off-by: Cyan Yang <cyan.yang at sifive.com>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/utils/irqchip/imsic.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c
> index 02e3a33..7d6993e 100644
> --- a/lib/utils/irqchip/imsic.c
> +++ b/lib/utils/irqchip/imsic.c
> @@ -123,6 +123,9 @@ struct imsic_data *imsic_get_data(u32 hartid)
>  {
>         struct sbi_scratch *scratch;
>
> +       if (!imsic_ptr_offset)
> +               return NULL;
> +
>         scratch = sbi_hartid_to_scratch(hartid);
>         if (!scratch)
>                 return NULL;
> @@ -134,6 +137,9 @@ int imsic_get_target_file(u32 hartid)
>  {
>         struct sbi_scratch *scratch;
>
> +       if (!imsic_file_offset)
> +               return SBI_ENOENT;
> +
>         scratch = sbi_hartid_to_scratch(hartid);
>         if (!scratch)
>                 return SBI_ENOENT;
> --
> 2.39.3 (Apple Git-146)
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list