diff options
author | Jiri Slaby <jslaby@suse.cz> | 2011-11-09 15:33:49 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-11-15 18:59:01 -0500 |
commit | 1c7b13c4886f5cfaf02fb1052f65ef1a2fe88b9a (patch) | |
tree | 133948b2e66a198cabb66b8d8893073a8284b3a1 /drivers/tty/serial/serial_core.c | |
parent | b39c49a05ec7322c96ec917922eae8b908d2c76f (diff) |
TTY: serial, inline uart_get
We need to expand uart_get into uart_open. We need it to move on with
conversion to use tty_port_open helper. After we do this, the code
will be much more similar to what tty_port_open does.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/tty/serial/serial_core.c')
-rw-r--r-- | drivers/tty/serial/serial_core.c | 66 |
1 files changed, 22 insertions, 44 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 4b1dcd3f2a40..2ca4df4a4836 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c | |||
@@ -1429,33 +1429,6 @@ static void uart_dtr_rts(struct tty_port *port, int onoff) | |||
1429 | uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); | 1429 | uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); |
1430 | } | 1430 | } |
1431 | 1431 | ||
1432 | static struct uart_state *uart_get(struct uart_driver *drv, int line) | ||
1433 | { | ||
1434 | struct uart_state *state; | ||
1435 | struct tty_port *port; | ||
1436 | int ret = 0; | ||
1437 | |||
1438 | state = drv->state + line; | ||
1439 | port = &state->port; | ||
1440 | if (mutex_lock_interruptible(&port->mutex)) { | ||
1441 | ret = -ERESTARTSYS; | ||
1442 | goto err; | ||
1443 | } | ||
1444 | |||
1445 | port->count++; | ||
1446 | if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { | ||
1447 | ret = -ENXIO; | ||
1448 | goto err_unlock; | ||
1449 | } | ||
1450 | return state; | ||
1451 | |||
1452 | err_unlock: | ||
1453 | port->count--; | ||
1454 | mutex_unlock(&port->mutex); | ||
1455 | err: | ||
1456 | return ERR_PTR(ret); | ||
1457 | } | ||
1458 | |||
1459 | /* | 1432 | /* |
1460 | * calls to uart_open are serialised by the BKL in | 1433 | * calls to uart_open are serialised by the BKL in |
1461 | * fs/char_dev.c:chrdev_open() | 1434 | * fs/char_dev.c:chrdev_open() |
@@ -1469,26 +1442,29 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line) | |||
1469 | static int uart_open(struct tty_struct *tty, struct file *filp) | 1442 | static int uart_open(struct tty_struct *tty, struct file *filp) |
1470 | { | 1443 | { |
1471 | struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state; | 1444 | struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state; |
1472 | struct uart_state *state; | ||
1473 | struct tty_port *port; | ||
1474 | int retval, line = tty->index; | 1445 | int retval, line = tty->index; |
1446 | struct uart_state *state = drv->state + line; | ||
1447 | struct tty_port *port = &state->port; | ||
1475 | 1448 | ||
1476 | pr_debug("uart_open(%d) called\n", line); | 1449 | pr_debug("uart_open(%d) called\n", line); |
1477 | 1450 | ||
1478 | /* | 1451 | /* |
1479 | * We take the semaphore inside uart_get to guarantee that we won't | 1452 | * We take the semaphore here to guarantee that we won't be re-entered |
1480 | * be re-entered while allocating the state structure, or while we | 1453 | * while allocating the state structure, or while we request any IRQs |
1481 | * request any IRQs that the driver may need. This also has the nice | 1454 | * that the driver may need. This also has the nice side-effect that |
1482 | * side-effect that it delays the action of uart_hangup, so we can | 1455 | * it delays the action of uart_hangup, so we can guarantee that |
1483 | * guarantee that state->port.tty will always contain something | 1456 | * state->port.tty will always contain something reasonable. |
1484 | * reasonable. | ||
1485 | */ | 1457 | */ |
1486 | state = uart_get(drv, line); | 1458 | if (mutex_lock_interruptible(&port->mutex)) { |
1487 | if (IS_ERR(state)) { | 1459 | retval = -ERESTARTSYS; |
1488 | retval = PTR_ERR(state); | 1460 | goto end; |
1489 | goto fail; | 1461 | } |
1462 | |||
1463 | port->count++; | ||
1464 | if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { | ||
1465 | retval = -ENXIO; | ||
1466 | goto err_dec_count; | ||
1490 | } | 1467 | } |
1491 | port = &state->port; | ||
1492 | 1468 | ||
1493 | /* | 1469 | /* |
1494 | * Once we set tty->driver_data here, we are guaranteed that | 1470 | * Once we set tty->driver_data here, we are guaranteed that |
@@ -1505,9 +1481,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) | |||
1505 | */ | 1481 | */ |
1506 | if (tty_hung_up_p(filp)) { | 1482 | if (tty_hung_up_p(filp)) { |
1507 | retval = -EAGAIN; | 1483 | retval = -EAGAIN; |
1508 | port->count--; | 1484 | goto err_dec_count; |
1509 | mutex_unlock(&port->mutex); | ||
1510 | goto fail; | ||
1511 | } | 1485 | } |
1512 | 1486 | ||
1513 | /* | 1487 | /* |
@@ -1528,8 +1502,12 @@ static int uart_open(struct tty_struct *tty, struct file *filp) | |||
1528 | if (retval == 0) | 1502 | if (retval == 0) |
1529 | retval = tty_port_block_til_ready(port, tty, filp); | 1503 | retval = tty_port_block_til_ready(port, tty, filp); |
1530 | 1504 | ||
1531 | fail: | 1505 | end: |
1532 | return retval; | 1506 | return retval; |
1507 | err_dec_count: | ||
1508 | port->count--; | ||
1509 | mutex_unlock(&port->mutex); | ||
1510 | goto end; | ||
1533 | } | 1511 | } |
1534 | 1512 | ||
1535 | static const char *uart_type(struct uart_port *port) | 1513 | static const char *uart_type(struct uart_port *port) |