lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT drivers
authorAnup Patel <apatel@ventanamicro.com>
Wed, 5 Jul 2023 06:45:15 +0000 (12:15 +0530)
committerAnup Patel <anup@brainfault.org>
Sun, 9 Jul 2023 05:34:57 +0000 (11:04 +0530)
The cold_init() functions of ACLINT drivers should skip the HART
if sbi_hartid_to_scratch() returns NULL because we might be dealing
with a HART that is disabled in the device tree.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Xiang W <wxjstz@126.com>
lib/utils/ipi/aclint_mswi.c
lib/utils/timer/aclint_mtimer.c

index f47b3bcbbb44c66ee506fa1b8b12b2c0dfaa1171..140a49b5f520792ddc8be787bb9479ce682acef7 100644 (file)
@@ -101,8 +101,13 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)
        /* Update MSWI pointer in scratch space */
        for (i = 0; i < mswi->hart_count; i++) {
                scratch = sbi_hartid_to_scratch(mswi->first_hartid + i);
+               /*
+                * We don't need to fail if scratch pointer is not available
+                * because we might be dealing with hartid of a HART disabled
+                * in the device tree.
+                */
                if (!scratch)
-                       return SBI_ENOENT;
+                       continue;
                mswi_set_hart_data_ptr(scratch, mswi);
        }
 
index 13af5d8232d3c443e8515a1427f99d724c72e8dc..271e6252fef9950450384ad6d4b767cedbaee2b0 100644 (file)
@@ -219,8 +219,13 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
        /* Update MTIMER pointer in scratch space */
        for (i = 0; i < mt->hart_count; i++) {
                scratch = sbi_hartid_to_scratch(mt->first_hartid + i);
+               /*
+                * We don't need to fail if scratch pointer is not available
+                * because we might be dealing with hartid of a HART disabled
+                * in the device tree.
+                */
                if (!scratch)
-                       return SBI_ENOENT;
+                       continue;
                mtimer_set_hart_data_ptr(scratch, mt);
        }