SERIAL: Simplify code using ARRAY_SIZE() macro.
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
@@ -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
@@ -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
========================================================================
Quoted 12 lines · Robert P. J. Day
Signed-off-by Robert P. J. Day <[email protected]>---
drivers/serial/68328serial.c | 6 +++--- drivers/serial/mcfserial.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)drivers/serial/68328serial.c +0
-0
[...]
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?
Quoted 14 lines · Jiri Slaby
Quoted 12 lines · Robert P. J. Day
Signed-off-by Robert P. J. Day <[email protected]>---
drivers/serial/68328serial.c | 6 +++--- drivers/serial/mcfserial.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)drivers/serial/68328serial.c +0
-0[...]
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
========================================================================
Quoted 7 lines · Robert P. J. Day
Quoted 7 lines
Quoted 7 lines
drivers/serial/68328serial.c +0
-0@@ -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
-1again: -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.
Quoted 14 lines · Joe Perches
Quoted 7 lines · Robert P. J. Day
Quoted 7 lines
Quoted 7 lines
drivers/serial/68328serial.c +0
-0@@ -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
-1again: -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
andMCFRS_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_PORTSseems 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
========================================================================