tty: Replace ASYNC_INITIALIZED bit and update atomically
Replace ASYNC_INITIALIZED bit in the tty_port::flags field with TTY_PORT_INITIALIZED bit in the tty_port::iflags field. Introduce helpers tty_port_set_initialized() and tty_port_initialized() to abstract atomic bit ops. Note: the transforms for test_and_set_bit() and test_and_clear_bit() are unnecessary as the state transitions are already mutually exclusive; the tty lock prevents concurrent open/close/hangup. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
80f02d5424
commit
d41861ca19
@@ -220,10 +220,11 @@ static int ircomm_tty_startup(struct ircomm_tty_cb *self)
|
||||
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
||||
|
||||
/* Check if already open */
|
||||
if (test_and_set_bit(ASYNCB_INITIALIZED, &self->port.flags)) {
|
||||
if (tty_port_initialized(&self->port)) {
|
||||
pr_debug("%s(), already open so break out!\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
tty_port_set_initialized(&self->port, 1);
|
||||
|
||||
/* Register with IrCOMM */
|
||||
irda_notify_init(¬ify);
|
||||
@@ -257,7 +258,7 @@ static int ircomm_tty_startup(struct ircomm_tty_cb *self)
|
||||
|
||||
return 0;
|
||||
err:
|
||||
clear_bit(ASYNCB_INITIALIZED, &self->port.flags);
|
||||
tty_port_set_initialized(&self->port, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -318,13 +319,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
||||
spin_unlock_irqrestore(&port->lock, flags);
|
||||
|
||||
while (1) {
|
||||
if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags))
|
||||
if (C_BAUD(tty) && tty_port_initialized(port))
|
||||
tty_port_raise_dtr_rts(port);
|
||||
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
|
||||
if (tty_hung_up_p(filp) ||
|
||||
!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
|
||||
if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
|
||||
retval = (port->flags & ASYNC_HUP_NOTIFY) ?
|
||||
-EAGAIN : -ERESTARTSYS;
|
||||
break;
|
||||
@@ -876,8 +876,9 @@ static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
||||
|
||||
if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags))
|
||||
if (!tty_port_initialized(&self->port))
|
||||
return;
|
||||
tty_port_set_initialized(&self->port, 0);
|
||||
|
||||
ircomm_tty_detach_cable(self);
|
||||
|
||||
@@ -1259,7 +1260,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
|
||||
seq_printf(m, "%cASYNC_CHECK_CD", sep);
|
||||
sep = '|';
|
||||
}
|
||||
if (self->port.flags & ASYNC_INITIALIZED) {
|
||||
if (tty_port_initialized(&self->port)) {
|
||||
seq_printf(m, "%cASYNC_INITIALIZED", sep);
|
||||
sep = '|';
|
||||
}
|
||||
|
@@ -324,7 +324,7 @@ static int ircomm_tty_set_serial_info(struct ircomm_tty_cb *self,
|
||||
|
||||
check_and_exit:
|
||||
|
||||
if (self->flags & ASYNC_INITIALIZED) {
|
||||
if (tty_port_initialized(self)) {
|
||||
if (((old_state.flags & ASYNC_SPD_MASK) !=
|
||||
(self->flags & ASYNC_SPD_MASK)) ||
|
||||
(old_driver.custom_divisor != driver->custom_divisor)) {
|
||||
|
Reference in New Issue
Block a user