[SPARC64]: Prevent registering wrong serial console.
authorDavid S. Miller <davem@sunset.davemloft.net>
Tue, 14 Feb 2006 04:09:10 +0000 (20:09 -0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Mon, 20 Mar 2006 09:12:42 +0000 (01:12 -0800)
If the console is not for a particular Sun serial
controller, set the drv->cons to NULL.

Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/serial/sunsab.c
drivers/serial/sunsu.c
drivers/serial/sunzilog.c

index 8566422..02f62da 100644 (file)
@@ -955,14 +955,13 @@ static struct console sunsab_console = {
        .index  =       -1,
        .data   =       &sunsab_reg,
 };
-#define SUNSAB_CONSOLE (&sunsab_console)
 
-static void __init sunsab_console_init(void)
+static inline struct console *SUNSAB_CONSOLE(void)
 {
        int i;
 
        if (con_is_present())
-               return;
+               return NULL;
 
        for (i = 0; i < num_channels; i++) {
                int this_minor = sunsab_reg.minor + i;
@@ -971,13 +970,14 @@ static void __init sunsab_console_init(void)
                        break;
        }
        if (i == num_channels)
-               return;
+               return NULL;
 
        sunsab_console.index = i;
-       register_console(&sunsab_console);
+
+       return &sunsab_console;
 }
 #else
-#define SUNSAB_CONSOLE         (NULL)
+#define SUNSAB_CONSOLE()       (NULL)
 #define sunsab_console_init()  do { } while (0)
 #endif
 
@@ -1124,7 +1124,6 @@ static int __init sunsab_init(void)
 
        sunsab_reg.minor = sunserial_current_minor;
        sunsab_reg.nr = num_channels;
-       sunsab_reg.cons = SUNSAB_CONSOLE;
 
        ret = uart_register_driver(&sunsab_reg);
        if (ret < 0) {
@@ -1143,10 +1142,10 @@ static int __init sunsab_init(void)
                return ret;
        }
 
+       sunsab_reg.cons = SUNSAB_CONSOLE();
+
        sunserial_current_minor += num_channels;
        
-       sunsab_console_init();
-
        for (i = 0; i < num_channels; i++) {
                struct uart_sunsab_port *up = &sunsab_ports[i];
 
index 4e453fa..3313cb2 100644 (file)
@@ -1464,18 +1464,17 @@ static struct console sunsu_cons = {
        .index  =       -1,
        .data   =       &sunsu_reg,
 };
-#define SUNSU_CONSOLE  (&sunsu_cons)
 
 /*
  *     Register console.
  */
 
-static int __init sunsu_serial_console_init(void)
+static inline struct console *SUNSU_CONSOLE(void)
 {
        int i;
 
        if (con_is_present())
-               return 0;
+               return NULL;
 
        for (i = 0; i < UART_NR; i++) {
                int this_minor = sunsu_reg.minor + i;
@@ -1484,16 +1483,16 @@ static int __init sunsu_serial_console_init(void)
                        break;
        }
        if (i == UART_NR)
-               return 0;
+               return NULL;
        if (sunsu_ports[i].port_node == 0)
-               return 0;
+               return NULL;
 
        sunsu_cons.index = i;
-       register_console(&sunsu_cons);
-       return 0;
+
+       return &sunsu_cons;
 }
 #else
-#define SUNSU_CONSOLE                  (NULL)
+#define SUNSU_CONSOLE()                        (NULL)
 #define sunsu_serial_console_init()    do { } while (0)
 #endif
 
@@ -1523,16 +1522,17 @@ static int __init sunsu_serial_init(void)
        }
 
        sunsu_reg.minor = sunserial_current_minor;
-       sunserial_current_minor += instance;
 
        sunsu_reg.nr = instance;
-       sunsu_reg.cons = SUNSU_CONSOLE;
 
        ret = uart_register_driver(&sunsu_reg);
        if (ret < 0)
                return ret;
 
-       sunsu_serial_console_init();
+       sunserial_current_minor += instance;
+
+       sunsu_reg.cons = SUNSU_CONSOLE();
+
        for (i = 0; i < UART_NR; i++) {
                struct uart_sunsu_port *up = &sunsu_ports[i];
 
index 5cc4d4c..5aa74e7 100644 (file)
@@ -1390,7 +1390,6 @@ static struct console sunzilog_console = {
        .index  =       -1,
        .data   =       &sunzilog_reg,
 };
-#define SUNZILOG_CONSOLE       (&sunzilog_console)
 
 static int __init sunzilog_console_init(void)
 {
@@ -1413,8 +1412,31 @@ static int __init sunzilog_console_init(void)
        register_console(&sunzilog_console);
        return 0;
 }
+
+static inline struct console *SUNZILOG_CONSOLE(void)
+{
+       int i;
+
+       if (con_is_present())
+               return NULL;
+
+       for (i = 0; i < NUM_CHANNELS; i++) {
+               int this_minor = sunzilog_reg.minor + i;
+
+               if ((this_minor - 64) == (serial_console - 1))
+                       break;
+       }
+       if (i == NUM_CHANNELS)
+               return NULL;
+
+       sunzilog_console.index = i;
+       sunzilog_port_table[i].flags |= SUNZILOG_FLAG_IS_CONS;
+
+       return &sunzilog_console;
+}
+
 #else
-#define SUNZILOG_CONSOLE       (NULL)
+#define SUNZILOG_CONSOLE()     (NULL)
 #define sunzilog_console_init() do { } while (0)
 #endif
 
@@ -1666,14 +1688,14 @@ static int __init sunzilog_ports_init(void)
        }
                
        sunzilog_reg.nr = uart_count;
-       sunzilog_reg.cons = SUNZILOG_CONSOLE;
-
        sunzilog_reg.minor = sunserial_current_minor;
-       sunserial_current_minor += uart_count;
 
        ret = uart_register_driver(&sunzilog_reg);
        if (ret == 0) {
-               sunzilog_console_init();
+               sunzilog_reg.cons = SUNZILOG_CONSOLE();
+
+               sunserial_current_minor += uart_count;
+
                for (i = 0; i < NUM_CHANNELS; i++) {
                        struct uart_sunzilog_port *up = &sunzilog_port_table[i];