* [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro.
@ 2008-05-25 11:37 Robert P. J. Day
2008-05-25 16:50 ` Jiri Slaby
0 siblings, 1 reply; 5+ messages in thread
From: Robert P. J. Day @ 2008-05-25 11:37 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Andrew Morton
Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
---
drivers/serial/68328serial.c | 6 +++---
drivers/serial/mcfserial.c | 5 ++---
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index bbf5bc5..71c56c1 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -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;
}
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 56007cc..a0699ba 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -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
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro.
2008-05-25 11:37 [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro Robert P. J. Day
@ 2008-05-25 16:50 ` Jiri Slaby
2008-05-25 17:09 ` Robert P. J. Day
0 siblings, 1 reply; 5+ messages in thread
From: Jiri Slaby @ 2008-05-25 16:50 UTC (permalink / raw)
To: Robert P. J. Day; +Cc: Linux Kernel Mailing List, Andrew Morton
On 05/25/2008 01:37 PM, Robert P. J. Day wrote:
> Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
>
> ---
>
> drivers/serial/68328serial.c | 6 +++---
> drivers/serial/mcfserial.c | 5 ++---
> 2 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
> index bbf5bc5..71c56c1 100644
> --- a/drivers/serial/68328serial.c
> +++ b/drivers/serial/68328serial.c
[...]
> @@ -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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro.
2008-05-25 16:50 ` Jiri Slaby
@ 2008-05-25 17:09 ` Robert P. J. Day
2008-05-25 18:41 ` Joe Perches
0 siblings, 1 reply; 5+ messages in thread
From: Robert P. J. Day @ 2008-05-25 17:09 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Linux Kernel Mailing List, Andrew Morton
On Sun, 25 May 2008, Jiri Slaby wrote:
> On 05/25/2008 01:37 PM, Robert P. J. Day wrote:
> > Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
> >
> > ---
> >
> > drivers/serial/68328serial.c | 6 +++---
> > drivers/serial/mcfserial.c | 5 ++---
> > 2 files changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
> > index bbf5bc5..71c56c1 100644
> > --- a/drivers/serial/68328serial.c
> > +++ b/drivers/serial/68328serial.c
> [...]
> > @@ -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
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro.
2008-05-25 17:09 ` Robert P. J. Day
@ 2008-05-25 18:41 ` Joe Perches
2008-05-26 7:38 ` Robert P. J. Day
0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2008-05-25 18:41 UTC (permalink / raw)
To: Robert P. J. Day; +Cc: Jiri Slaby, Linux Kernel Mailing List, Andrew Morton
On Sun, 2008-05-25 at 13:09 -0400, Robert P. J. Day wrote:
> > > diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
> > > index bbf5bc5..71c56c1 100644
> > > --- a/drivers/serial/68328serial.c
> > > +++ b/drivers/serial/68328serial.c
> > > @@ -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?
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro.
2008-05-25 18:41 ` Joe Perches
@ 2008-05-26 7:38 ` Robert P. J. Day
0 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2008-05-26 7:38 UTC (permalink / raw)
To: Joe Perches; +Cc: Jiri Slaby, Linux Kernel Mailing List, Andrew Morton
On Sun, 25 May 2008, Joe Perches wrote:
> On Sun, 2008-05-25 at 13:09 -0400, Robert P. J. Day wrote:
> > > > diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
> > > > index bbf5bc5..71c56c1 100644
> > > > --- a/drivers/serial/68328serial.c
> > > > +++ b/drivers/serial/68328serial.c
> > > > @@ -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?
> > 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.
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
========================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-05-26 7:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-25 11:37 [PATCH] SERIAL: Simplify code using ARRAY_SIZE() macro Robert P. J. Day
2008-05-25 16:50 ` Jiri Slaby
2008-05-25 17:09 ` Robert P. J. Day
2008-05-25 18:41 ` Joe Perches
2008-05-26 7:38 ` Robert P. J. Day
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®