lib: sbi: improve the definition of SBI_IPI_EVENT_MAX
authorXiang W <wxjstz@126.com>
Mon, 21 Aug 2023 14:11:45 +0000 (22:11 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 6 Sep 2023 11:36:12 +0000 (17:06 +0530)
The previous definition had the assumption that the machine word length
is equal to the word length of LONG. Remove this assumption and add a
static check to prevent errors in subsequent modifications.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
include/sbi/sbi_ipi.h
lib/sbi/sbi_ipi.c

index c64f422c0301be5fe2cad17be06ce75b19512a75..6b5e260b78c7111e24629237d1f4d08bee066a06 100644 (file)
@@ -14,7 +14,7 @@
 
 /* clang-format off */
 
-#define SBI_IPI_EVENT_MAX                      __riscv_xlen
+#define SBI_IPI_EVENT_MAX                      (8 * __SIZEOF_LONG__)
 
 /* clang-format on */
 
index ad09154521fb257eabca749fffbd307d697d30c0..0d8edab020fc6c4ded69ef2d373c18a261f62339 100644 (file)
@@ -27,6 +27,11 @@ struct sbi_ipi_data {
        unsigned long ipi_type;
 };
 
+_Static_assert(
+       8 * sizeof(((struct sbi_ipi_data*)0)->ipi_type) == SBI_IPI_EVENT_MAX,
+       "type of sbi_ipi_data.ipi_type has changed, please redefine SBI_IPI_EVENT_MAX"
+       );
+
 static unsigned long ipi_data_off;
 static const struct sbi_ipi_device *ipi_dev = NULL;
 static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];