drivers/serial/serial.c: code maintainability improvments.
PATCH 2/3 drivers/serial/serial.c: code maintainability improvments.
--- drivers/serial/serial.c | 31 +++++++++++++++++++++---------- 1 files changed, 21 insertions(+), 10 deletions(-)
drivers/serial/serial.c +21 -10
@@ -45,24 +45,27 @@ DECLARE_GLOBAL_DATA_PTR;#else #error "No console index specified."#endif /* CONFIG_SERIAL_MULTI */ -#elif (CONFIG_CONS_INDEX <1 ) || (CONFIG_CONS_INDEX >4 ) +#elif CONFIG_CONS_INDEX <1 #error "Invalid console index value."#endif -#if CONFIG_CONS_INDEX ==1 && !defined(CONFIG_SYS_NS16550_COM1 ) -#error "Console port 1 defined but not configured." -#elif CONFIG_CONS_INDEX ==2 && !defined(CONFIG_SYS_NS16550_COM2 ) -#error "Console port 2 defined but not configured." -#elif CONFIG_CONS_INDEX ==3 && !defined(CONFIG_SYS_NS16550_COM3 ) -#error "Console port 3 defined but not configured." -#elif CONFIG_CONS_INDEX ==4 && !defined(CONFIG_SYS_NS16550_COM4 ) -#error "Console port 4 defined but not configured." +#define CONSOLE_PORT_SANITY_CHECK (port) \ + CONFIG_CONS_INDEX == port && !defined(CONFIG_SYS_NS16550_COM##port) + +#if CONSOLE_PORT_SANITY_CHECK (1 ) +#error Console port 1 defined but not configured. +#elif CONSOLE_PORT_SANITY_CHECK (2 ) +#error Console port 2 defined but not configured. +#elif CONSOLE_PORT_SANITY_CHECK (3 ) +#error Console port 3 defined but not configured. +#elif CONSOLE_PORT_SANITY_CHECK (4 ) +#error Console port 4 defined but not configured.#endif /* Note: The port number specified in the functions is 1 based. * the array is 0 based. */ -static NS16550_t serial_ports[4 ] = { +static NS16550_t serial_ports[] = { #ifdef CONFIG_SYS_NS16550_COM1 (NS16550_t)CONFIG_SYS_NS16550_COM1, #else
@@ -85,6 +88,14 @@ static NS16550_t serial_ports[4] = {#endif }; +#define MAX_SER_PORTS ((sizeof(serial_ports)/sizeof(NS16550_t))) + +static inline void sanity_check (void ) +{ +/* This will fail to compile if CONFIG_CONS_INDEX > MAX_SER_DEV */ +BUILD_BUG_ON (CONFIG_CONS_INDEX >MAX_SER_PORTS ); +} +#define PORT serial_ports[port-1]#if defined(CONFIG_CONS_INDEX )#define CONSOLE (serial_ports[CONFIG_CONS_INDEX-1])
Signature · 1 line
1.6.3.3
PATCH 2/3 drivers/serial/serial.c: code maintainability improvments.
Quoted 1 line · On Thu, 1 Apr 2010 20:19:45 +0300 Michael Zaidman <[email protected]>…
+#define
MAX_SER_PORTS((sizeof(serial_ports)/sizeof(NS16550_t)))
one level of parens not needed, no space around operator '/'.
Quoted 1 line
+static inline void
sanity_check(void)
we can avoid this non-function by placing the check in serial_init().
drivers/serial/serial.c static NS16550_t serial_ports[4] = { · line 96
Quoted 3 lines
drivers/serial/serial.c +3
-0+{ +/* This will fail to compile if CONFIG_CONS_INDEX > MAX_SER_DEV */ +BUILD_BUG_ON (CONFIG_CONS_INDEX >MAX_SER_PORTS );
the comment doesn't match the code, and the code looks pretty self-explanatory in the first place. Remove the comment?
Kim
PATCH 2/3 drivers/serial/serial.c: code maintainability improvments.
Hi Kim,
Thanks for your corrections. I fixed all of them in version #2 of the patch here: http://lists.denx.de/pipermail/u-boot/2010-April/069412.html
Regards,
Michael