Skip to contentSkip to conversation

post: use ARRAY_SIZE

PATCH New Mike Frysinger 2 participants 2 messages May 10, 2011 – Jul 26, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 post: use ARRAY_SIZE

We've got a handy dandy macro already for calculating the number of elements in an array, so use it.

---
 post/board/lwmon/sysmon.c                     |    2 +-
 post/cpu/mpc8xx/ether.c                       |    4 +---
 post/cpu/mpc8xx/spr.c                         |    3 +--
 post/cpu/mpc8xx/uart.c                        |    4 +---
 post/cpu/ppc4xx/spr.c                         |    3 +--
 post/drivers/memory.c                         |    2 +-
 post/lib_powerpc/andi.c                       |    3 +--
 post/lib_powerpc/cmp.c                        |    3 +--
 post/lib_powerpc/cmpi.c                       |    3 +--
 post/lib_powerpc/cr.c                         |   12 ++++--------
 post/lib_powerpc/fpu/mul-subnormal-single-1.c |    2 +-
 post/lib_powerpc/load.c                       |    3 +--
 post/lib_powerpc/multi.c                      |    2 +-
 post/lib_powerpc/rlwimi.c                     |    3 +--
 post/lib_powerpc/rlwinm.c                     |    3 +--
 post/lib_powerpc/rlwnm.c                      |    3 +--
 post/lib_powerpc/srawi.c                      |    3 +--
 post/lib_powerpc/store.c                      |    3 +--
 post/lib_powerpc/three.c                      |    3 +--
 post/lib_powerpc/threei.c                     |    3 +--
 post/lib_powerpc/threex.c                     |    3 +--
 post/lib_powerpc/two.c                        |    3 +--
 post/lib_powerpc/twox.c                       |    3 +--
 post/post.c                                   |    2 +-
 post/tests.c                                  |    2 +-
 25 files changed, 28 insertions(+), 52 deletions(-)
post/board/lwmon/sysmon.c +1 -1
index fc828b2..72224c6 100644
@@ -133,7 +133,7 @@ static sysmon_table_t sysmon_table[] =
     {"+ 5 V standby", "V", &sysmon_pic, NULL, NULL,
      100, 1000, 0, 6040, 0xFF, 0xC8, 0xDE, 0, 0xC8, 0xDE, 0, 0x7C},
 };
-static int sysmon_table_size = sizeof(sysmon_table) / sizeof(sysmon_table[0]);
+static int sysmon_table_size = ARRAY_SIZE(sysmon_table);
 
 static int conversion_done = 0;
 
post/cpu/mpc8xx/ether.c +1 -3
index 43ea817..fcbb300 100644
@@ -67,8 +67,6 @@ static int ctlr_list[][2] = { {CTLR_SCC, 1} };
 static int ctlr_list[][2] = { };
 #endif
 
-#define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
-
 static struct {
 	void (*init) (int index);
 	void (*halt) (int index);
@@ -618,7 +616,7 @@ int ether_post_test (int flags)
 	ctlr_proc[CTLR_SCC].send = scc_send;
 	ctlr_proc[CTLR_SCC].recv = scc_recv;
 
-	for (i = 0; i < CTRL_LIST_SIZE; i++) {
+	for (i = 0; i < ARRAY_SIZE(ctlr_list); i++) {
 		if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
 			res = -1;
 		}
post/cpu/mpc8xx/spr.c +1 -2
index db84dbe..4c1e2af 100644
@@ -108,8 +108,7 @@ static struct
 	{826,	"MD_DBRAM1",	0x00000000,	0x00000000},
 };
 
-static int spr_test_list_size =
-		sizeof (spr_test_list) / sizeof (spr_test_list[0]);
+static int spr_test_list_size = ARRAY_SIZE(spr_test_list);
 
 int spr_post_test (int flags)
 {
post/cpu/mpc8xx/uart.c +1 -3
index f351ac0..7a7a62a 100644
@@ -61,8 +61,6 @@ static int ctlr_list[][2] =
 static int ctlr_list[][2] = { };
 #endif
 
-#define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
-
 static struct {
 	void (*init) (int index);
 	void (*halt) (int index);
@@ -540,7 +538,7 @@ int uart_post_test (int flags)
 	ctlr_proc[CTLR_SCC].putc = scc_putc;
 	ctlr_proc[CTLR_SCC].getc = scc_getc;
 
-	for (i = 0; i < CTRL_LIST_SIZE; i++) {
+	for (i = 0; i < ARRAY_SIZE(ctlr_list); i++) {
 		if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
 			res = -1;
 		}
post/cpu/ppc4xx/spr.c +1 -2
index cb18b64..3f5e965 100644
@@ -156,8 +156,7 @@ static struct {
 	{0x3f3,	"DBDR",		0x00000000,	0x00000000},
 };
 
-static int spr_test_list_size =
-		sizeof (spr_test_list) / sizeof (spr_test_list[0]);
+static int spr_test_list_size = ARRAY_SIZE(spr_test_list);
 
 int spr_post_test (int flags)
 {
post/drivers/memory.c +1 -1
index 3f47449..4cca035 100644
@@ -225,7 +225,7 @@ const unsigned long long otherpattern = 0x0123456789abcdefULL;
 static int memory_post_dataline(unsigned long long * pmem)
 {
 	unsigned long long temp64 = 0;
-	int num_patterns = sizeof(pattern)/ sizeof(pattern[0]);
+	int num_patterns = ARRAY_SIZE(pattern);
 	int i;
 	unsigned int hi, lo, pathi, patlo;
 	int ret = 0;
post/lib_powerpc/andi.c +1 -2
index 52ec7c4..2791cd7 100644
@@ -61,8 +61,7 @@ static struct cpu_post_andi_s
 	0x80000000
     },
 };
-static unsigned int cpu_post_andi_size =
-    sizeof (cpu_post_andi_table) / sizeof (struct cpu_post_andi_s);
+static unsigned int cpu_post_andi_size = ARRAY_SIZE(cpu_post_andi_table);
 
 int cpu_post_test_andi (void)
 {
post/lib_powerpc/cmp.c +1 -2
index 5f6a3b9..ae5b72b 100644
@@ -95,8 +95,7 @@ static struct cpu_post_cmp_s
 	0x04
     },
 };
-static unsigned int cpu_post_cmp_size =
-    sizeof (cpu_post_cmp_table) / sizeof (struct cpu_post_cmp_s);
+static unsigned int cpu_post_cmp_size = ARRAY_SIZE(cpu_post_cmp_table);
 
 int cpu_post_test_cmp (void)
 {
post/lib_powerpc/cmpi.c +1 -2
index 1a2fc3d..4160a2a 100644
@@ -95,8 +95,7 @@ static struct cpu_post_cmpi_s
 	0x04
     },
 };
-static unsigned int cpu_post_cmpi_size =
-    sizeof (cpu_post_cmpi_table) / sizeof (struct cpu_post_cmpi_s);
+static unsigned int cpu_post_cmpi_size = ARRAY_SIZE(cpu_post_cmpi_table);
 
 int cpu_post_test_cmpi (void)
 {
post/lib_powerpc/cr.c +4 -8
index fbee6d5..ada7c7a 100644
@@ -59,8 +59,7 @@ static ulong cpu_post_cr_table1[] =
     0xaaaaaaaa,
     0x55555555,
 };
-static unsigned int cpu_post_cr_size1 =
-    sizeof (cpu_post_cr_table1) / sizeof (ulong);
+static unsigned int cpu_post_cr_size1 = ARRAY_SIZE(cpu_post_cr_table1);
 
 static struct cpu_post_cr_s2 {
     ulong xer;
@@ -76,8 +75,7 @@ static struct cpu_post_cr_s2 {
 	5
     },
 };
-static unsigned int cpu_post_cr_size2 =
-    sizeof (cpu_post_cr_table2) / sizeof (struct cpu_post_cr_s2);
+static unsigned int cpu_post_cr_size2 = ARRAY_SIZE(cpu_post_cr_table2);
 
 static struct cpu_post_cr_s3 {
     ulong cr;
@@ -99,8 +97,7 @@ static struct cpu_post_cr_s3 {
 	0x71234567
     },
 };
-static unsigned int cpu_post_cr_size3 =
-    sizeof (cpu_post_cr_table3) / sizeof (struct cpu_post_cr_s3);
+static unsigned int cpu_post_cr_size3 = ARRAY_SIZE(cpu_post_cr_table3);
 
 static struct cpu_post_cr_s4 {
     ulong cmd;
@@ -240,8 +237,7 @@ static struct cpu_post_cr_s4 {
 	0x0000ffff
     },
 };
-static unsigned int cpu_post_cr_size4 =
-    sizeof (cpu_post_cr_table4) / sizeof (struct cpu_post_cr_s4);
+static unsigned int cpu_post_cr_size4 = ARRAY_SIZE(cpu_post_cr_table4);
 
 int cpu_post_test_cr (void)
 {
post/lib_powerpc/fpu/mul-subnormal-single-1.c +1 -1
index 23a3f30..b3f8deb 100644
@@ -86,7 +86,7 @@ int fpu_post_test_math7 (void)
 {
 	unsigned int i;
 
-	for (i = 0; i < sizeof (expected) / sizeof (expected[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(expected); i++)
 	{
 		tstmul (expected[i].p1, expected[i].p2, expected[i].res);
 		tstmul (expected[i].p2, expected[i].p1, expected[i].res);
post/lib_powerpc/load.c +1 -2
index 98d4373..49924f2 100644
@@ -171,8 +171,7 @@ static struct cpu_post_load_s
 	1
     },
 };
-static unsigned int cpu_post_load_size =
-    sizeof (cpu_post_load_table) / sizeof (struct cpu_post_load_s);
+static unsigned int cpu_post_load_size = ARRAY_SIZE(cpu_post_load_table);
 
 int cpu_post_test_load (void)
 {
post/lib_powerpc/multi.c +1 -1
index e42a7c0..5845616 100644
@@ -57,7 +57,7 @@ int cpu_post_test_multi (void)
 	    ASM_BLR,
 	};
 
-	for (i = 0; i < sizeof(src) / sizeof(src[0]); i ++)
+	for (i = 0; i < ARRAY_SIZE(src); ++i)
 	{
 	    src[i] = i;
 	    dst[i] = 0;
post/lib_powerpc/rlwimi.c +1 -2
index fd628b3..15d96ac 100644
@@ -62,8 +62,7 @@ static struct cpu_post_rlwimi_s
 	0xffaaffff
     },
 };
-static unsigned int cpu_post_rlwimi_size =
-    sizeof (cpu_post_rlwimi_table) / sizeof (struct cpu_post_rlwimi_s);
+static unsigned int cpu_post_rlwimi_size = ARRAY_SIZE(cpu_post_rlwimi_table);
 
 int cpu_post_test_rlwimi (void)
 {
post/lib_powerpc/rlwinm.c +1 -2
index 88a28c6..a04ec52 100644
@@ -59,8 +59,7 @@ static struct cpu_post_rlwinm_s
 	0x0000ff00
    },
 };
-static unsigned int cpu_post_rlwinm_size =
-    sizeof (cpu_post_rlwinm_table) / sizeof (struct cpu_post_rlwinm_s);
+static unsigned int cpu_post_rlwinm_size = ARRAY_SIZE(cpu_post_rlwinm_table);
 
 int cpu_post_test_rlwinm (void)
 {
post/lib_powerpc/rlwnm.c +1 -2
index 60bcb6d..764fe0c 100644
@@ -60,8 +60,7 @@ static struct cpu_post_rlwnm_s
 	0x0000ff00
    },
 };
-static unsigned int cpu_post_rlwnm_size =
-    sizeof (cpu_post_rlwnm_table) / sizeof (struct cpu_post_rlwnm_s);
+static unsigned int cpu_post_rlwnm_size = ARRAY_SIZE(cpu_post_rlwnm_table);
 
 int cpu_post_test_rlwnm (void)
 {
post/lib_powerpc/srawi.c +1 -2
index be153ad..90a1e4d 100644
@@ -61,8 +61,7 @@ static struct cpu_post_srawi_s
 	0xf0000000
     },
 };
-static unsigned int cpu_post_srawi_size =
-    sizeof (cpu_post_srawi_table) / sizeof (struct cpu_post_srawi_s);
+static unsigned int cpu_post_srawi_size = ARRAY_SIZE(cpu_post_srawi_table);
 
 int cpu_post_test_srawi (void)
 {
post/lib_powerpc/store.c +1 -2
index 1956f6b..441389c 100644
@@ -156,8 +156,7 @@ static struct cpu_post_store_s
 	0xff
     },
 };
-static unsigned int cpu_post_store_size =
-    sizeof (cpu_post_store_table) / sizeof (struct cpu_post_store_s);
+static unsigned int cpu_post_store_size = ARRAY_SIZE(cpu_post_store_table);
 
 int cpu_post_test_store (void)
 {
post/lib_powerpc/three.c +1 -2
index 7f8c1e2..4391386 100644
@@ -155,8 +155,7 @@ static struct cpu_post_three_s
 	0x40
     },
 };
-static unsigned int cpu_post_three_size =
-    sizeof (cpu_post_three_table) / sizeof (struct cpu_post_three_s);
+static unsigned int cpu_post_three_size = ARRAY_SIZE(cpu_post_three_table);
 
 int cpu_post_test_three (void)
 {
post/lib_powerpc/threei.c +1 -2
index 31953f9..95b6322 100644
@@ -75,8 +75,7 @@ static struct cpu_post_threei_s
 	0xffff8000
     },
 };
-static unsigned int cpu_post_threei_size =
-    sizeof (cpu_post_threei_table) / sizeof (struct cpu_post_threei_s);
+static unsigned int cpu_post_threei_size = ARRAY_SIZE(cpu_post_threei_table);
 
 int cpu_post_test_threei (void)
 {
post/lib_powerpc/threex.c +1 -2
index 350a12a..7769218 100644
@@ -125,8 +125,7 @@ static struct cpu_post_threex_s
 	0x1000
     },
 };
-static unsigned int cpu_post_threex_size =
-    sizeof (cpu_post_threex_table) / sizeof (struct cpu_post_threex_s);
+static unsigned int cpu_post_threex_size = ARRAY_SIZE(cpu_post_threex_table);
 
 int cpu_post_test_threex (void)
 {
post/lib_powerpc/two.c +1 -2
index 2b11147..7f08880 100644
@@ -81,8 +81,7 @@ static struct cpu_post_two_s
 	~5
     },
 };
-static unsigned int cpu_post_two_size =
-    sizeof (cpu_post_two_table) / sizeof (struct cpu_post_two_s);
+static unsigned int cpu_post_two_size = ARRAY_SIZE(cpu_post_two_table);
 
 int cpu_post_test_two (void)
 {
post/lib_powerpc/twox.c +1 -2
index d6714f9..88140bf 100644
@@ -81,8 +81,7 @@ static struct cpu_post_twox_s
 	12
     },
 };
-static unsigned int cpu_post_twox_size =
-    sizeof (cpu_post_twox_table) / sizeof (struct cpu_post_twox_s);
+static unsigned int cpu_post_twox_size = ARRAY_SIZE(cpu_post_twox_table);
 
 int cpu_post_test_twox (void)
 {
post/post.c +1 -1
index ecea1e1..7660224 100644
@@ -196,7 +196,7 @@ static void post_get_flags (int *test_flags)
 			 POST_CRITICAL };
 	char *var[] = { "post_poweron", "post_normal", "post_slowtest",
 			"post_critical" };
-	int varnum = sizeof (var) / sizeof (var[0]);
+	int varnum = ARRAY_SIZE(var);
 	char list[128];			/* long enough for POST list */
 	char *name;
 	char *s;
post/tests.c +1 -1
index 5f59fbb..71437b6 100644
@@ -305,4 +305,4 @@ struct post_test post_list[] =
 #endif
 };
 
-unsigned int post_list_size = sizeof (post_list) / sizeof (struct post_test);
+unsigned int post_list_size = ARRAY_SIZE(post_list);
Signature · 1 line
1.7.5.rc3
#1 lore raw

PATCH 1/1 post: use ARRAY_SIZE

Dear Mike Frysinger,

Quoted 23 lines · In message <[email protected]> you wrote:

We've got a handy dandy macro already for calculating the number of elements in an array, so use it.

---
 post/board/lwmon/sysmon.c                     |    2 +-
 post/cpu/mpc8xx/ether.c                       |    4 +---
 post/cpu/mpc8xx/spr.c                         |    3 +--
 post/cpu/mpc8xx/uart.c                        |    4 +---
 post/cpu/ppc4xx/spr.c                         |    3 +--
 post/drivers/memory.c                         |    2 +-
 post/lib_powerpc/andi.c                       |    3 +--
 post/lib_powerpc/cmp.c                        |    3 +--
 post/lib_powerpc/cmpi.c                       |    3 +--
 post/lib_powerpc/cr.c                         |   12 ++++--------
 post/lib_powerpc/fpu/mul-subnormal-single-1.c |    2 +-
 post/lib_powerpc/load.c                       |    3 +--
 post/lib_powerpc/multi.c                      |    2 +-
 post/lib_powerpc/rlwimi.c                     |    3 +--
 post/lib_powerpc/rlwinm.c                     |    3 +--
 post/lib_powerpc/rlwnm.c                      |    3 +--
 post/lib_powerpc/srawi.c                      |    3 +--
 post/lib_powerpc/store.c                      |    3 +--
Quoted 8 lines
 post/lib_powerpc/three.c                      |    3 +--
 post/lib_powerpc/threei.c                     |    3 +--
 post/lib_powerpc/threex.c                     |    3 +--
 post/lib_powerpc/two.c                        |    3 +--
 post/lib_powerpc/twox.c                       |    3 +--
 post/post.c                                   |    2 +-
 post/tests.c                                  |    2 +-
 25 files changed, 28 insertions(+), 52 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Brain: an apparatus with which we think we think.    - Ambrose Bierce