tty: serial: 8250: Cleanup p->em485 in serial8250_unregister_port
authorMatwey V. Kornilov <matwey@sai.msu.ru>
Mon, 15 Feb 2016 18:42:12 +0000 (21:42 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Mar 2016 00:11:14 +0000 (16:11 -0800)
Formally, currently there is no memory leak, but if
serial8250_ports[line] is reused with other 8250 driver, then em485
will be already activated and it will cause issues.

Fixes: e490c9144cfa ("tty: Add software emulated RS485 support for 8250")
Signed-off-by: Matwey V. Kornilov <matwey@sai.msu.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_core.c

index 77752216de0e895b3a6e29019d4e580aef455f36..2f4f5ee651db63c040255347b56d0ac385e36415 100644 (file)
@@ -1074,6 +1074,15 @@ void serial8250_unregister_port(int line)
        struct uart_8250_port *uart = &serial8250_ports[line];
 
        mutex_lock(&serial_mutex);
+
+       if (uart->em485) {
+               unsigned long flags;
+
+               spin_lock_irqsave(&uart->port.lock, flags);
+               serial8250_em485_destroy(uart);
+               spin_unlock_irqrestore(&uart->port.lock, flags);
+       }
+
        uart_remove_one_port(&serial8250_reg, &uart->port);
        if (serial8250_isa_devs) {
                uart->port.flags &= ~UPF_BOOT_AUTOCONF;