lib: utils:Check that hartid is valid

It is possible that hartid may not be sequential and it should not be validated
against SBI_HARTMASK_MAX_BITS. Instead we should check the index of the hartid,
hart index, against SBI_HARTMASK_MAX_BITS.

Signed-off-by: Raj Vishwanathan <Raj.Vishwanathan@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Raj Vishwanathan
2025-02-11 14:00:42 -08:00
committed by Anup Patel
parent 4f12f8b02f
commit 5e90e54a1a
3 changed files with 6 additions and 6 deletions

View File

@@ -473,7 +473,7 @@ static int __fdt_parse_domain(const void *fdt, int domain_offset, void *opaque)
if (err) if (err)
continue; continue;
if (SBI_HARTMASK_MAX_BITS <= val32) if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(val32))
continue; continue;
if (!fdt_node_is_enabled(fdt, cpu_offset)) if (!fdt_node_is_enabled(fdt, cpu_offset))

View File

@@ -1031,7 +1031,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,
if (rc) if (rc)
continue; continue;
if (SBI_HARTMASK_MAX_BITS <= hartid) if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(hartid))
continue; continue;
if (match_hwirq == hwirq) { if (match_hwirq == hwirq) {
@@ -1096,7 +1096,7 @@ int fdt_parse_plmt_node(const void *fdt, int nodeoffset, unsigned long *plmt_bas
if (rc) if (rc)
continue; continue;
if (SBI_HARTMASK_MAX_BITS <= hartid) if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(hartid))
continue; continue;
if (hwirq == IRQ_M_TIMER) if (hwirq == IRQ_M_TIMER)
@@ -1152,7 +1152,7 @@ int fdt_parse_plicsw_node(const void *fdt, int nodeoffset, unsigned long *plicsw
if (rc) if (rc)
continue; continue;
if (SBI_HARTMASK_MAX_BITS <= hartid) if (SBI_HARTMASK_MAX_BITS <= sbi_hartid_to_hartindex(hartid))
continue; continue;
if (hwirq == IRQ_M_SOFT) if (hwirq == IRQ_M_SOFT)

View File

@@ -200,8 +200,8 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
if (rc) if (rc)
continue; continue;
if (SBI_HARTMASK_MAX_BITS <= hartid) if (SBI_HARTMASK_MAX_BITS <= hart_count)
continue; break;
if (!fdt_node_is_enabled(fdt, cpu_offset)) if (!fdt_node_is_enabled(fdt, cpu_offset))
continue; continue;