Skip to content

Commit 761ed4a

Browse files
robherringgregkh
authored andcommitted
tty: serial_core: convert uart_close to use tty_port_close
tty_port_close handles much of the common parts of tty close. Convert uart_close to use it and move the serial_core specific parts into tty_port.shutdown function. This will be needed to use tty_port functions directly from in kernel clients. This change causes ops->stop_rx() to be called after uart_wait_until_sent() is called which I think should be fine. Otherwise, the sequence of the close should be the same. Cc: Peter Hurley <[email protected]> Signed-off-by: Rob Herring <[email protected]> Acked-by: Alan Cox <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b3b5764 commit 761ed4a

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

drivers/tty/serial/serial_core.c

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
14611461
{
14621462
struct uart_state *state = tty->driver_data;
14631463
struct tty_port *port;
1464-
struct uart_port *uport;
14651464

14661465
if (!state) {
14671466
struct uart_driver *drv = tty->driver->driver_state;
@@ -1477,56 +1476,36 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
14771476
port = &state->port;
14781477
pr_debug("uart_close(%d) called\n", tty->index);
14791478

1480-
if (tty_port_close_start(port, tty, filp) == 0)
1481-
return;
1479+
tty_port_close(tty->port, tty, filp);
1480+
}
14821481

1483-
mutex_lock(&port->mutex);
1484-
uport = uart_port_check(state);
1482+
static void uart_tty_port_shutdown(struct tty_port *port)
1483+
{
1484+
struct uart_state *state = container_of(port, struct uart_state, port);
1485+
struct uart_port *uport = uart_port_check(state);
14851486

1487+
spin_lock_irq(&uport->lock);
14861488
/*
14871489
* At this point, we stop accepting input. To do this, we
14881490
* disable the receive line status interrupts.
14891491
*/
1490-
if (tty_port_initialized(port) &&
1491-
!WARN(!uport, "detached port still initialized!\n")) {
1492-
spin_lock_irq(&uport->lock);
1493-
uport->ops->stop_rx(uport);
1494-
spin_unlock_irq(&uport->lock);
1495-
/*
1496-
* Before we drop DTR, make sure the UART transmitter
1497-
* has completely drained; this is especially
1498-
* important if there is a transmit FIFO!
1499-
*/
1500-
uart_wait_until_sent(tty, uport->timeout);
1501-
}
1492+
WARN(!uport, "detached port still initialized!\n");
15021493

1503-
uart_shutdown(tty, state);
1504-
tty_port_tty_set(port, NULL);
1494+
uport->ops->stop_rx(uport);
15051495

1506-
spin_lock_irq(&port->lock);
1496+
spin_unlock_irq(&uport->lock);
15071497

1508-
if (port->blocked_open) {
1509-
spin_unlock_irq(&port->lock);
1510-
if (port->close_delay)
1511-
msleep_interruptible(jiffies_to_msecs(port->close_delay));
1512-
spin_lock_irq(&port->lock);
1513-
} else if (uport && !uart_console(uport)) {
1514-
spin_unlock_irq(&port->lock);
1515-
uart_change_pm(state, UART_PM_STATE_OFF);
1516-
spin_lock_irq(&port->lock);
1517-
}
1518-
spin_unlock_irq(&port->lock);
1519-
tty_port_set_active(port, 0);
1498+
uart_port_shutdown(port);
15201499

15211500
/*
1522-
* Wake up anyone trying to open this port.
1501+
* It's possible for shutdown to be called after suspend if we get
1502+
* a DCD drop (hangup) at just the right time. Clear suspended bit so
1503+
* we don't try to resume a port that has been shutdown.
15231504
*/
1524-
wake_up_interruptible(&port->open_wait);
1505+
tty_port_set_suspended(port, 0);
15251506

1526-
mutex_unlock(&port->mutex);
1507+
uart_change_pm(state, UART_PM_STATE_OFF);
15271508

1528-
tty_ldisc_flush(tty);
1529-
tty->closing = 0;
15301509
}
15311510

15321511
static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
@@ -2446,6 +2425,7 @@ static const struct tty_port_operations uart_port_ops = {
24462425
.carrier_raised = uart_carrier_raised,
24472426
.dtr_rts = uart_dtr_rts,
24482427
.activate = uart_port_activate,
2428+
.shutdown = uart_tty_port_shutdown,
24492429
};
24502430

24512431
/**
@@ -2762,6 +2742,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
27622742
uport->cons = drv->cons;
27632743
uport->minor = drv->tty_driver->minor_start + uport->line;
27642744

2745+
port->console = uart_console(uport);
2746+
27652747
/*
27662748
* If this port is a console, then the spinlock is already
27672749
* initialised.

0 commit comments

Comments
 (0)