From 669e42960c505716107cb792d6aa2d51d6bc2902 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 15 Nov 2020 13:56:45 +0200 Subject: [PATCH] Utilize ARRAY_SIZE macro --- bdk/mem/sdram.c | 2 +- bdk/soc/bpmp.c | 2 +- bdk/soc/fuse.c | 9 ++++----- bdk/utils/types.h | 2 ++ bootloader/hos/pkg1.c | 2 +- bootloader/hos/pkg2.c | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bdk/mem/sdram.c b/bdk/mem/sdram.c index 3b700f9..5eb5dc3 100644 --- a/bdk/mem/sdram.c +++ b/bdk/mem/sdram.c @@ -703,7 +703,7 @@ break_nosleep: #ifndef CONFIG_SDRAM_COMPRESS_CFG static void _sdram_patch_model_params(u32 dramid, u32 *params) { - for (u32 i = 0; i < sizeof(sdram_cfg_vendor_patches) / sizeof(sdram_vendor_patch_t); i++) + for (u32 i = 0; i < ARRAY_SIZE(sdram_cfg_vendor_patches); i++) if (sdram_cfg_vendor_patches[i].dramid & DRAM_ID(dramid)) params[sdram_cfg_vendor_patches[i].addr] = sdram_cfg_vendor_patches[i].val; } diff --git a/bdk/soc/bpmp.c b/bdk/soc/bpmp.c index 999b0d8..f71089f 100644 --- a/bdk/soc/bpmp.c +++ b/bdk/soc/bpmp.c @@ -172,7 +172,7 @@ void bpmp_mmu_enable() // Init BPMP MMU entries. BPMP_CACHE_CTRL(BPMP_CACHE_MMU_SHADOW_COPY_MASK) = 0; - for (u32 idx = 0; idx < (sizeof(mmu_entries) / sizeof(bpmp_mmu_entry_t)); idx++) + for (u32 idx = 0; idx < ARRAY_SIZE(mmu_entries); idx++) bpmp_mmu_set_entry(idx, &mmu_entries[idx], false); BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_COPY_SHADOW; diff --git a/bdk/soc/fuse.c b/bdk/soc/fuse.c index 97433f2..466a7a2 100644 --- a/bdk/soc/fuse.c +++ b/bdk/soc/fuse.c @@ -21,8 +21,7 @@ #include #include - -#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x)) +#include static const u32 evp_thunk_template[] = { 0xe92d0007, // STMFD SP!, {R0-R2} @@ -145,7 +144,7 @@ static int _patch_hash_one(u32 *word) { return 3; } - for (u32 i = 0; i < ARRAYSIZE(hash_vals); i++) + for (u32 i = 0; i < ARRAY_SIZE(hash_vals); i++) { if (hash_vals[i] == hash) { @@ -234,7 +233,7 @@ int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value)) while (word_count) { total_read += word_count; - if (total_read >= ARRAYSIZE(words)) + if (total_read >= ARRAY_SIZE(words)) { break; } @@ -291,7 +290,7 @@ int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len) while (word_count) { total_read += word_count; - if (total_read >= ARRAYSIZE(words)) + if (total_read >= ARRAY_SIZE(words)) { break; } diff --git a/bdk/utils/types.h b/bdk/utils/types.h index d305464..73603b0 100644 --- a/bdk/utils/types.h +++ b/bdk/utils/types.h @@ -25,6 +25,8 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) + #define OFFSET_OF(t, m) ((u32)&((t *)NULL)->m) #define CONTAINER_OF(mp, t, mn) ((t *)((u32)mp - OFFSET_OF(t, mn))) diff --git a/bootloader/hos/pkg1.c b/bootloader/hos/pkg1.c index 649248a..701a4f5 100644 --- a/bootloader/hos/pkg1.c +++ b/bootloader/hos/pkg1.c @@ -134,7 +134,7 @@ static const pkg1_id_t _pkg1_ids[] = { const pkg1_id_t *pkg1_get_latest() { - return &_pkg1_ids[sizeof(_pkg1_ids) / sizeof(pkg1_id_t) - 2]; + return &_pkg1_ids[ARRAY_SIZE(_pkg1_ids) - 2]; } const pkg1_id_t *pkg1_identify(u8 *pkg1) diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index 29ab8f2..b624e47 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -660,7 +660,7 @@ static kip1_id_t _kip_ids[] = }; static kip1_id_t *_kip_id_sets = _kip_ids; -static u32 _kip_id_sets_cnt = sizeof(_kip_ids) / sizeof(_kip_ids[0]); +static u32 _kip_id_sets_cnt = ARRAY_SIZE(_kip_ids); void pkg2_get_ids(kip1_id_t **ids, u32 *entries) { @@ -783,7 +783,7 @@ static void parse_external_kip_patches() const pkg2_kernel_id_t *pkg2_identify(u8 *hash) { - for (u32 i = 0; i < (sizeof(_pkg2_kernel_ids) / sizeof(pkg2_kernel_id_t)); i++) + for (u32 i = 0; i < ARRAY_SIZE(_pkg2_kernel_ids); i++) { if (!memcmp(hash, _pkg2_kernel_ids[i].hash, sizeof(_pkg2_kernel_ids[0].hash))) return &_pkg2_kernel_ids[i];