8250: Fix oops from setserial
authorAlan Cox <alan@linux.intel.com>
Thu, 28 May 2009 13:01:35 +0000 (14:01 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 29 May 2009 15:42:38 +0000 (08:42 -0700)
If you setserial a port which has never been initialised we change the type
but don't update the I/O method pointers. The same problem is true if you
change the io type of a port - but nobody ever does that so nobody noticed!

Remember the old type and when attaching if the type has changed reload the
port accessor pointers. We can't do it blindly as some 8250 drivers load custom
accessors and we must not stomp those.

Tested-by: Victor Seryodkin <vvscore@gmail.com>
Closes-bug: #13367
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/serial/8250.c

index b4b39811b44544cc76a4c71e00c5c02567a765c2..a0127e93ade0a424c6125383150dd342e61710fc 100644 (file)
@@ -137,6 +137,7 @@ struct uart_8250_port {
        unsigned char           mcr;
        unsigned char           mcr_mask;       /* mask of user bits */
        unsigned char           mcr_force;      /* mask of forced bits */
        unsigned char           mcr;
        unsigned char           mcr_mask;       /* mask of user bits */
        unsigned char           mcr_force;      /* mask of forced bits */
+       unsigned char           cur_iotype;     /* Running I/O type */
 
        /*
         * Some bits in registers are cleared on a read, so they must
 
        /*
         * Some bits in registers are cleared on a read, so they must
@@ -471,6 +472,7 @@ static void io_serial_out(struct uart_port *p, int offset, int value)
 
 static void set_io_from_upio(struct uart_port *p)
 {
 
 static void set_io_from_upio(struct uart_port *p)
 {
+       struct uart_8250_port *up = (struct uart_8250_port *)p;
        switch (p->iotype) {
        case UPIO_HUB6:
                p->serial_in = hub6_serial_in;
        switch (p->iotype) {
        case UPIO_HUB6:
                p->serial_in = hub6_serial_in;
@@ -509,6 +511,8 @@ static void set_io_from_upio(struct uart_port *p)
                p->serial_out = io_serial_out;
                break;
        }
                p->serial_out = io_serial_out;
                break;
        }
+       /* Remember loaded iotype */
+       up->cur_iotype = p->iotype;
 }
 
 static void
 }
 
 static void
@@ -1937,6 +1941,9 @@ static int serial8250_startup(struct uart_port *port)
        up->capabilities = uart_config[up->port.type].flags;
        up->mcr = 0;
 
        up->capabilities = uart_config[up->port.type].flags;
        up->mcr = 0;
 
+       if (up->port.iotype != up->cur_iotype)
+               set_io_from_upio(port);
+
        if (up->port.type == PORT_16C950) {
                /* Wake up and initialize UART */
                up->acr = 0;
        if (up->port.type == PORT_16C950) {
                /* Wake up and initialize UART */
                up->acr = 0;
@@ -2563,6 +2570,9 @@ static void serial8250_config_port(struct uart_port *port, int flags)
        if (ret < 0)
                probeflags &= ~PROBE_RSA;
 
        if (ret < 0)
                probeflags &= ~PROBE_RSA;
 
+       if (up->port.iotype != up->cur_iotype)
+               set_io_from_upio(port);
+
        if (flags & UART_CONFIG_TYPE)
                autoconfig(up, probeflags);
        if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
        if (flags & UART_CONFIG_TYPE)
                autoconfig(up, probeflags);
        if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
@@ -2671,6 +2681,11 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
 {
        int i;
 
 {
        int i;
 
+       for (i = 0; i < nr_uarts; i++) {
+               struct uart_8250_port *up = &serial8250_ports[i];
+               up->cur_iotype = 0xFF;
+       }
+
        serial8250_isa_init_ports();
 
        for (i = 0; i < nr_uarts; i++) {
        serial8250_isa_init_ports();
 
        for (i = 0; i < nr_uarts; i++) {