From: Vikram Kanigiri Date: Wed, 4 Mar 2015 10:34:27 +0000 (+0000) Subject: Add macro to calculate number of elements in an array X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=a7e98ad5145bb57fd18d199f915c76ef376cf227;p=project%2Fbcm63xx%2Fatf.git Add macro to calculate number of elements in an array This patch defines the ARRAY_SIZE macro for calculating number of elements in an array and uses it where appropriate. Change-Id: I72746a9229f0b259323972b498b9a3999731bc9b --- diff --git a/drivers/io/io_fip.c b/drivers/io/io_fip.c index 0cec8044..9dcd901e 100644 --- a/drivers/io/io_fip.c +++ b/drivers/io/io_fip.c @@ -143,7 +143,7 @@ static int file_to_uuid(const char *filename, uuid_t *uuid) int i; int status = -EINVAL; - for (i = 0; i < (sizeof(name_uuid) / sizeof(name_uuid[0])); i++) { + for (i = 0; i < ARRAY_SIZE(name_uuid); i++) { if (strcmp(filename, name_uuid[i].name) == 0) { copy_uuid(uuid, &name_uuid[i].uuid); status = 0; diff --git a/include/common/bl_common.h b/include/common/bl_common.h index 0959c893..b36c9d35 100644 --- a/include/common/bl_common.h +++ b/include/common/bl_common.h @@ -108,6 +108,8 @@ #include #include +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + /******************************************************************************* * Structure used for telling the next BL how much of a particular type of * memory is available for its use and how much is already used. diff --git a/lib/aarch64/xlat_tables.c b/lib/aarch64/xlat_tables.c index ddc9ba88..fa1a03da 100644 --- a/lib/aarch64/xlat_tables.c +++ b/lib/aarch64/xlat_tables.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,7 @@ void mmap_add_region(unsigned long base_pa, unsigned long base_va, unsigned long size, unsigned attr) { mmap_region_t *mm = mmap; - mmap_region_t *mm_last = mm + sizeof(mmap) / sizeof(mmap[0]) - 1; + mmap_region_t *mm_last = mm + ARRAY_SIZE(mmap) - 1; unsigned long pa_end = base_pa + size - 1; unsigned long va_end = base_va + size - 1; diff --git a/plat/fvp/aarch64/fvp_common.c b/plat/fvp/aarch64/fvp_common.c index fcda2a87..ddaacbaf 100644 --- a/plat/fvp/aarch64/fvp_common.c +++ b/plat/fvp/aarch64/fvp_common.c @@ -115,7 +115,7 @@ const mmap_region_t fvp_mmap[] = { }; #endif -CASSERT((sizeof(fvp_mmap)/sizeof(fvp_mmap[0])) + FVP_BL_REGIONS \ +CASSERT(ARRAY_SIZE(fvp_mmap) + FVP_BL_REGIONS \ <= MAX_MMAP_REGIONS, assert_max_mmap_regions); /* Array of secure interrupts to be configured by the gic driver */ @@ -132,9 +132,6 @@ const unsigned int irq_sec_array[] = { IRQ_SEC_SGI_7 }; -const unsigned int num_sec_irqs = sizeof(irq_sec_array) / - sizeof(irq_sec_array[0]); - /******************************************************************************* * Macro generating the code for the function setting up the pagetables as per * the platform memory map & initialize the mmu, for the given exception level @@ -326,7 +323,7 @@ void fvp_gic_init(void) plat_config.gicd_base, BASE_GICR_BASE, irq_sec_array, - num_sec_irqs); + ARRAY_SIZE(irq_sec_array)); } diff --git a/plat/juno/aarch64/juno_common.c b/plat/juno/aarch64/juno_common.c index 6ea0b155..371323e7 100644 --- a/plat/juno/aarch64/juno_common.c +++ b/plat/juno/aarch64/juno_common.c @@ -114,7 +114,7 @@ static const mmap_region_t juno_mmap[] = { }; #endif -CASSERT((sizeof(juno_mmap)/sizeof(juno_mmap[0])) + JUNO_BL_REGIONS \ +CASSERT(ARRAY_SIZE(juno_mmap) + JUNO_BL_REGIONS \ <= MAX_MMAP_REGIONS, assert_max_mmap_regions); /* Array of secure interrupts to be configured by the gic driver */ @@ -136,9 +136,6 @@ const unsigned int irq_sec_array[] = { IRQ_SEC_SGI_7 }; -const unsigned int num_sec_irqs = sizeof(irq_sec_array) / - sizeof(irq_sec_array[0]); - /******************************************************************************* * Macro generating the code for the function setting up the pagetables as per * the platform memory map & initialize the mmu, for the given exception level @@ -211,5 +208,9 @@ uint64_t plat_get_syscnt_freq(void) void plat_gic_init(void) { - arm_gic_init(GICC_BASE, GICD_BASE, 0, irq_sec_array, num_sec_irqs); + arm_gic_init(GICC_BASE, + GICD_BASE, + 0, + irq_sec_array, + ARRAY_SIZE(irq_sec_array)); }