Skip to contentSkip to conversation

SERIAL: Simplify code using ARRAY_SIZE() macro.

PATCH In review Robert P. J. Day 3 participants 5 messages May 25, 2008 – May 26, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SERIAL: Simplify code using ARRAY_SIZE() macro.

---

 drivers/serial/68328serial.c |    6 +++---
 drivers/serial/mcfserial.c   |    5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/serial/68328serial.c +3 -3
index bbf5bc5..71c56c1 100644
@@ -154,7 +154,7 @@ static int baud_table[] = {
 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
 	9600, 19200, 38400, 57600, 115200, 0 };
 
-#define BAUD_TABLE_SIZE (sizeof(baud_table)/sizeof(baud_table[0]))
+#define BAUD_TABLE_SIZE ARRAY_SIZE(baud_table)
 
 /* Sets or clears DTR/RTS on the requested line */
 static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
@@ -1413,10 +1413,10 @@ static void m68328_set_baud(void)
 	USTCNT = ustcnt & ~USTCNT_TXEN;
 
 again:
-	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+	for (i = 0; i < BAUD_TABLE_SIZE); i++)
 		if (baud_table[i] == m68328_console_baud)
 			break;
-	if (i >= sizeof(baud_table) / sizeof(baud_table[0])) {
+	if (i >= BAUD_TABLE_SIZE) {
 		m68328_console_baud = 9600;
 		goto again;
 	}
drivers/serial/mcfserial.c +2 -3
index 56007cc..a0699ba 100644
@@ -137,7 +137,7 @@ static struct mcf_serial mcfrs_table[] = {
 };
 
 
-#define	NR_PORTS	(sizeof(mcfrs_table) / sizeof(struct mcf_serial))
+#define	NR_PORTS	ARRAY_SIZE(mcfrs_table)
 
 /*
  * This is used to figure out the divisor speeds and the timeouts.
@@ -146,8 +146,7 @@ static int mcfrs_baud_table[] = {
 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
 	9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
 };
-#define MCFRS_BAUD_TABLE_SIZE \
-			(sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
+#define MCFRS_BAUD_TABLE_SIZE ARRAY_SIZE(mcfrs_baud_table)
 
 
 #ifdef CONFIG_MAGIC_SYSRQ

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================

#1 lore raw
Quoted 12 lines · Robert P. J. Day

---

 drivers/serial/68328serial.c |    6 +++---
 drivers/serial/mcfserial.c   |    5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/serial/68328serial.c +0 -0
index bbf5bc5..71c56c1 100644

[...]

drivers/serial/68328serial.c static void m68328_set_baud(void) · line 1416

Quoted 6 lines
drivers/serial/68328serial.c +1 -1
@@ -1413,10 +1413,10 @@ static void m68328_set_baud(void)
 	USTCNT = ustcnt & ~USTCNT_TXEN;
 
 again:
-	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+	for (i = 0; i < BAUD_TABLE_SIZE); i++)

typo? does this compile?

#2 lore raw
Quoted 14 lines · Jiri Slaby
Quoted 12 lines · Robert P. J. Day

---

 drivers/serial/68328serial.c |    6 +++---
 drivers/serial/mcfserial.c   |    5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/serial/68328serial.c +0 -0
index bbf5bc5..71c56c1 100644

[...]

Quoted 8 lines

drivers/serial/68328serial.c static void m68328_set_baud(void) · line 1416

Quoted 6 lines
drivers/serial/68328serial.c +1 -1
@@ -1413,10 +1413,10 @@ static void m68328_set_baud(void)
 	USTCNT = ustcnt & ~USTCNT_TXEN;
 
 again:
-	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+	for (i = 0; i < BAUD_TABLE_SIZE); i++)

typo? does this compile?

oh, gack, my bad. it compiled, then i figured i'd innocently fix up some white space and pooched it. sorry. will resubmit.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================

#3 lore raw
Quoted 7 lines · Robert P. J. Day
Quoted 7 lines
Quoted 7 lines
drivers/serial/68328serial.c +0 -0
index bbf5bc5..71c56c1 100644
@@ -1413,10 +1413,10 @@ static void m68328_set_baud(void)
 	USTCNT = ustcnt & ~USTCNT_TXEN;
 
Quoted 5 lines
Quoted 4 lines

drivers/serial/68328serial.c static void m68328_set_baud(void) · line 1416

Quoted 3 lines
drivers/serial/68328serial.c +1 -1
 again:
-	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+	for (i = 0; i < BAUD_TABLE_SIZE); i++)

typo? does this compile?

will resubmit.

There are only two uses of BAUD_TABLE_SIZE
and MCFRS_BAUD_TABLE_SIZE.

I think it better to avoid

	#define SOME_SIZE ARRAY_SIZE(some_array)

and use ARRAY_SIZE(some_array) where possible.

NR_PORTS seems to be an exception.

#4 lore raw
Quoted 14 lines · Joe Perches
Quoted 7 lines · Robert P. J. Day
Quoted 7 lines
Quoted 7 lines
drivers/serial/68328serial.c +0 -0
index bbf5bc5..71c56c1 100644
@@ -1413,10 +1413,10 @@ static void m68328_set_baud(void)
 	USTCNT = ustcnt & ~USTCNT_TXEN;
 
Quoted 5 lines
Quoted 4 lines

drivers/serial/68328serial.c static void m68328_set_baud(void) · line 1416

Quoted 3 lines
drivers/serial/68328serial.c +1 -1
 again:
-	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)
+	for (i = 0; i < BAUD_TABLE_SIZE); i++)

typo? does this compile?

will resubmit.

Quoted 8 lines

There are only two uses of BAUD_TABLE_SIZE
and MCFRS_BAUD_TABLE_SIZE.

I think it better to avoid

	#define SOME_SIZE ARRAY_SIZE(some_array)

and use ARRAY_SIZE(some_array) where possible.

NR_PORTS seems to be an exception.

yes, that cleanup could probably be simplified even further.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================