Utilize ARRAY_SIZE macro

This commit is contained in:
CTCaer 2020-11-15 13:56:45 +02:00
parent 55568b037f
commit 669e42960c
6 changed files with 11 additions and 10 deletions

View file

@ -703,7 +703,7 @@ break_nosleep:
#ifndef CONFIG_SDRAM_COMPRESS_CFG #ifndef CONFIG_SDRAM_COMPRESS_CFG
static void _sdram_patch_model_params(u32 dramid, u32 *params) 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)) if (sdram_cfg_vendor_patches[i].dramid & DRAM_ID(dramid))
params[sdram_cfg_vendor_patches[i].addr] = sdram_cfg_vendor_patches[i].val; params[sdram_cfg_vendor_patches[i].addr] = sdram_cfg_vendor_patches[i].val;
} }

View file

@ -172,7 +172,7 @@ void bpmp_mmu_enable()
// Init BPMP MMU entries. // Init BPMP MMU entries.
BPMP_CACHE_CTRL(BPMP_CACHE_MMU_SHADOW_COPY_MASK) = 0; 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_mmu_set_entry(idx, &mmu_entries[idx], false);
BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_COPY_SHADOW; BPMP_CACHE_CTRL(BPMP_CACHE_MMU_CMD) = MMU_CMD_COPY_SHADOW;

View file

@ -21,8 +21,7 @@
#include <soc/fuse.h> #include <soc/fuse.h>
#include <soc/t210.h> #include <soc/t210.h>
#include <utils/types.h>
#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x))
static const u32 evp_thunk_template[] = { static const u32 evp_thunk_template[] = {
0xe92d0007, // STMFD SP!, {R0-R2} 0xe92d0007, // STMFD SP!, {R0-R2}
@ -145,7 +144,7 @@ static int _patch_hash_one(u32 *word)
{ {
return 3; 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) if (hash_vals[i] == hash)
{ {
@ -234,7 +233,7 @@ int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value))
while (word_count) while (word_count)
{ {
total_read += word_count; total_read += word_count;
if (total_read >= ARRAYSIZE(words)) if (total_read >= ARRAY_SIZE(words))
{ {
break; break;
} }
@ -291,7 +290,7 @@ int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len)
while (word_count) while (word_count)
{ {
total_read += word_count; total_read += word_count;
if (total_read >= ARRAYSIZE(words)) if (total_read >= ARRAY_SIZE(words))
{ {
break; break;
} }

View file

@ -25,6 +25,8 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(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 OFFSET_OF(t, m) ((u32)&((t *)NULL)->m)
#define CONTAINER_OF(mp, t, mn) ((t *)((u32)mp - OFFSET_OF(t, mn))) #define CONTAINER_OF(mp, t, mn) ((t *)((u32)mp - OFFSET_OF(t, mn)))

View file

@ -134,7 +134,7 @@ static const pkg1_id_t _pkg1_ids[] = {
const pkg1_id_t *pkg1_get_latest() 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) const pkg1_id_t *pkg1_identify(u8 *pkg1)

View file

@ -660,7 +660,7 @@ static kip1_id_t _kip_ids[] =
}; };
static kip1_id_t *_kip_id_sets = _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) 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) 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))) if (!memcmp(hash, _pkg2_kernel_ids[i].hash, sizeof(_pkg2_kernel_ids[0].hash)))
return &_pkg2_kernel_ids[i]; return &_pkg2_kernel_ids[i];