Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac802...
[firefly-linux-kernel-4.4.55.git] / drivers / tty / serial / serial_core.c
index ece2049bd27016487aef8327eee7fb040ee346db..2cf5649a6dc038396636f09098ed6024d5880838 100644 (file)
@@ -1319,9 +1319,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
        uport = state->uart_port;
        port = &state->port;
 
-       pr_debug("uart_close(%d) called\n", uport->line);
+       pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
 
-       if (tty_port_close_start(port, tty, filp) == 0)
+       if (!port->count || tty_port_close_start(port, tty, filp) == 0)
                return;
 
        /*
@@ -1762,7 +1762,7 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co)
 }
 
 /**
- *     uart_parse_options - Parse serial port baud/parity/bits/flow contro.
+ *     uart_parse_options - Parse serial port baud/parity/bits/flow control.
  *     @options: pointer to option string
  *     @baud: pointer to an 'int' variable for the baud rate.
  *     @parity: pointer to an 'int' variable for the parity.
@@ -2609,7 +2609,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 
        /*
         * Register the port whether it's detected or not.  This allows
-        * setserial to be used to alter this ports parameters.
+        * setserial to be used to alter this port's parameters.
         */
        tty_dev = tty_port_register_device_attr(port, drv->tty_driver,
                        uport->line, uport->dev, port, tty_dev_attr_groups);
@@ -2645,6 +2645,7 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)
 {
        struct uart_state *state = drv->state + uport->line;
        struct tty_port *port = &state->port;
+       struct tty_struct *tty;
        int ret = 0;
 
        BUG_ON(in_interrupt());
@@ -2673,8 +2674,17 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)
         */
        tty_unregister_device(drv->tty_driver, uport->line);
 
-       if (port->tty)
+       tty = tty_port_tty_get(port);
+       if (tty) {
                tty_vhangup(port->tty);
+               tty_kref_put(tty);
+       }
+
+       /*
+        * If the port is used as a console, unregister it
+        */
+       if (uart_console(uport))
+               unregister_console(uport->cons);
 
        /*
         * Free the port IO and memory resources, if any.