Skip to content

Commit

Permalink
tty: move the termios object into the tty
Browse files Browse the repository at this point in the history
This will let us sort out a whole pile of tty related races. The
alternative would be to keep points and refcount the termios objects.
However
1. They are tiny anyway
2. Many devices don't use the stored copies
3. We can remove a pty special case

Signed-off-by: Alan Cox <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Alan Cox authored and gregkh committed Jul 16, 2012
1 parent 6d31a88 commit adc8d74
Show file tree
Hide file tree
Showing 65 changed files with 409 additions and 435 deletions.
2 changes: 1 addition & 1 deletion arch/ia64/hp/sim/simserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
{
/* Handle turning off CRTSCTS */
if ((old_termios->c_cflag & CRTSCTS) &&
!(tty->termios->c_cflag & CRTSCTS)) {
!(tty->termios.c_cflag & CRTSCTS)) {
tty->hw_stopped = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/hci_ath.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int ath_wakeup_ar3k(struct tty_struct *tty)
return status;

/* Disable Automatic RTSCTS */
memcpy(&ktermios, tty->termios, sizeof(ktermios));
ktermios = tty->termios;
ktermios.c_cflag &= ~CRTSCTS;
tty_set_termios(tty, &ktermios);

Expand Down
4 changes: 2 additions & 2 deletions drivers/isdn/gigaset/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
goto out;
}

iflag = tty->termios->c_iflag;
cflag = tty->termios->c_cflag;
iflag = tty->termios.c_iflag;
cflag = tty->termios.c_cflag;
old_cflag = old ? old->c_cflag : cflag;
gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
cs->minor_index, iflag, cflag, old_cflag);
Expand Down
16 changes: 8 additions & 8 deletions drivers/isdn/i4l/isdn_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,15 +1009,15 @@ isdn_tty_change_speed(modem_info *info)
quot;
int i;

if (!port->tty || !port->tty->termios)
if (!port->tty)
return;
cflag = port->tty->termios->c_cflag;
cflag = port->tty->termios.c_cflag;

quot = i = cflag & CBAUD;
if (i & CBAUDEX) {
i &= ~CBAUDEX;
if (i < 1 || i > 2)
port->tty->termios->c_cflag &= ~CBAUDEX;
port->tty->termios.c_cflag &= ~CBAUDEX;
else
i += 15;
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ isdn_tty_shutdown(modem_info *info)
#endif
isdn_unlock_drivers();
info->msr &= ~UART_MSR_RI;
if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) {
if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) {
info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
isdn_tty_modem_reset_regs(info, 0);
Expand Down Expand Up @@ -1469,13 +1469,13 @@ isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
if (!old_termios)
isdn_tty_change_speed(info);
else {
if (tty->termios->c_cflag == old_termios->c_cflag &&
tty->termios->c_ispeed == old_termios->c_ispeed &&
tty->termios->c_ospeed == old_termios->c_ospeed)
if (tty->termios.c_cflag == old_termios->c_cflag &&
tty->termios.c_ispeed == old_termios->c_ispeed &&
tty->termios.c_ospeed == old_termios->c_ospeed)
return;
isdn_tty_change_speed(info);
if ((old_termios->c_cflag & CRTSCTS) &&
!(tty->termios->c_cflag & CRTSCTS))
!(tty->termios.c_cflag & CRTSCTS))
tty->hw_stopped = 0;
}
}
Expand Down
20 changes: 10 additions & 10 deletions drivers/mmc/card/sdio_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
if (status & UART_MSR_DCTS) {
port->icount.cts++;
tty = tty_port_tty_get(&port->port);
if (tty && (tty->termios->c_cflag & CRTSCTS)) {
if (tty && (tty->termios.c_cflag & CRTSCTS)) {
int cts = (status & UART_MSR_CTS);
if (tty->hw_stopped) {
if (cts) {
Expand Down Expand Up @@ -671,12 +671,12 @@ static int sdio_uart_activate(struct tty_port *tport, struct tty_struct *tty)
port->ier = UART_IER_RLSI|UART_IER_RDI|UART_IER_RTOIE|UART_IER_UUE;
port->mctrl = TIOCM_OUT2;

sdio_uart_change_speed(port, tty->termios, NULL);
sdio_uart_change_speed(port, &tty->termios, NULL);

if (tty->termios->c_cflag & CBAUD)
if (tty->termios.c_cflag & CBAUD)
sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);

if (tty->termios->c_cflag & CRTSCTS)
if (tty->termios.c_cflag & CRTSCTS)
if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS))
tty->hw_stopped = 1;

Expand Down Expand Up @@ -850,7 +850,7 @@ static void sdio_uart_throttle(struct tty_struct *tty)
{
struct sdio_uart_port *port = tty->driver_data;

if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
if (!I_IXOFF(tty) && !(tty->termios.c_cflag & CRTSCTS))
return;

if (sdio_uart_claim_func(port) != 0)
Expand All @@ -861,7 +861,7 @@ static void sdio_uart_throttle(struct tty_struct *tty)
sdio_uart_start_tx(port);
}

if (tty->termios->c_cflag & CRTSCTS)
if (tty->termios.c_cflag & CRTSCTS)
sdio_uart_clear_mctrl(port, TIOCM_RTS);

sdio_uart_irq(port->func);
Expand All @@ -872,7 +872,7 @@ static void sdio_uart_unthrottle(struct tty_struct *tty)
{
struct sdio_uart_port *port = tty->driver_data;

if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
if (!I_IXOFF(tty) && !(tty->termios.c_cflag & CRTSCTS))
return;

if (sdio_uart_claim_func(port) != 0)
Expand All @@ -887,7 +887,7 @@ static void sdio_uart_unthrottle(struct tty_struct *tty)
}
}

if (tty->termios->c_cflag & CRTSCTS)
if (tty->termios.c_cflag & CRTSCTS)
sdio_uart_set_mctrl(port, TIOCM_RTS);

sdio_uart_irq(port->func);
Expand All @@ -898,12 +898,12 @@ static void sdio_uart_set_termios(struct tty_struct *tty,
struct ktermios *old_termios)
{
struct sdio_uart_port *port = tty->driver_data;
unsigned int cflag = tty->termios->c_cflag;
unsigned int cflag = tty->termios.c_cflag;

if (sdio_uart_claim_func(port) != 0)
return;

sdio_uart_change_speed(port, tty->termios, old_termios);
sdio_uart_change_speed(port, &tty->termios, old_termios);

/* Handle transition to B0 status */
if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
Expand Down
10 changes: 5 additions & 5 deletions drivers/net/irda/irtty-sir.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ static int irtty_change_speed(struct sir_dev *dev, unsigned speed)
tty = priv->tty;

mutex_lock(&tty->termios_mutex);
old_termios = *(tty->termios);
cflag = tty->termios->c_cflag;
old_termios = tty->termios;
cflag = tty->termios.c_cflag;
tty_encode_baud_rate(tty, speed, speed);
if (tty->ops->set_termios)
tty->ops->set_termios(tty, &old_termios);
Expand Down Expand Up @@ -281,15 +281,15 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop)
int cflag;

mutex_lock(&tty->termios_mutex);
old_termios = *(tty->termios);
cflag = tty->termios->c_cflag;
old_termios = tty->termios;
cflag = tty->termios.c_cflag;

if (stop)
cflag &= ~CREAD;
else
cflag |= CREAD;

tty->termios->c_cflag = cflag;
tty->termios.c_cflag = cflag;
if (tty->ops->set_termios)
tty->ops->set_termios(tty, &old_termios);
mutex_unlock(&tty->termios_mutex);
Expand Down
12 changes: 5 additions & 7 deletions drivers/net/usb/hso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,6 @@ static void _hso_serial_set_termios(struct tty_struct *tty,
struct ktermios *old)
{
struct hso_serial *serial = tty->driver_data;
struct ktermios *termios;

if (!serial) {
printk(KERN_ERR "%s: no tty structures", __func__);
Expand All @@ -1119,16 +1118,15 @@ static void _hso_serial_set_termios(struct tty_struct *tty,
/*
* Fix up unsupported bits
*/
termios = tty->termios;
termios->c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */
tty->termios.c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */

termios->c_cflag &=
tty->termios.c_cflag &=
~(CSIZE /* no size */
| PARENB /* disable parity bit */
| CBAUD /* clear current baud rate */
| CBAUDEX); /* clear current buad rate */

termios->c_cflag |= CS8; /* character size 8 bits */
tty->termios.c_cflag |= CS8; /* character size 8 bits */

/* baud rate 115200 */
tty_encode_baud_rate(tty, 115200, 115200);
Expand Down Expand Up @@ -1425,14 +1423,14 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)

if (old)
D5("Termios called with: cflags new[%d] - old[%d]",
tty->termios->c_cflag, old->c_cflag);
tty->termios.c_cflag, old->c_cflag);

/* the actual setup */
spin_lock_irqsave(&serial->serial_lock, flags);
if (serial->port.count)
_hso_serial_set_termios(tty, old);
else
tty->termios = old;
tty->termios = *old;
spin_unlock_irqrestore(&serial->serial_lock, flags);

/* done */
Expand Down
20 changes: 10 additions & 10 deletions drivers/tty/amiserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
custom.adkcon = AC_UARTBRK;
mb();

if (tty->termios->c_cflag & HUPCL)
if (tty->termios.c_cflag & HUPCL)
info->MCR &= ~(SER_DTR|SER_RTS);
rtsdtr_ctrl(info->MCR);

Expand All @@ -670,7 +670,7 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
int bits;
unsigned long flags;

cflag = tty->termios->c_cflag;
cflag = tty->termios.c_cflag;

/* Byte size is always 8 bits plus parity bit if requested */

Expand Down Expand Up @@ -707,8 +707,8 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
/* If the quotient is zero refuse the change */
if (!quot && old_termios) {
/* FIXME: Will need updating for new tty in the end */
tty->termios->c_cflag &= ~CBAUD;
tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
tty->termios.c_cflag &= ~CBAUD;
tty->termios.c_cflag |= (old_termios->c_cflag & CBAUD);
baud = tty_get_baud_rate(tty);
if (!baud)
baud = 9600;
Expand Down Expand Up @@ -984,7 +984,7 @@ static void rs_throttle(struct tty_struct * tty)
if (I_IXOFF(tty))
rs_send_xchar(tty, STOP_CHAR(tty));

if (tty->termios->c_cflag & CRTSCTS)
if (tty->termios.c_cflag & CRTSCTS)
info->MCR &= ~SER_RTS;

local_irq_save(flags);
Expand Down Expand Up @@ -1012,7 +1012,7 @@ static void rs_unthrottle(struct tty_struct * tty)
else
rs_send_xchar(tty, START_CHAR(tty));
}
if (tty->termios->c_cflag & CRTSCTS)
if (tty->termios.c_cflag & CRTSCTS)
info->MCR |= SER_RTS;
local_irq_save(flags);
rtsdtr_ctrl(info->MCR);
Expand Down Expand Up @@ -1330,7 +1330,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
{
struct serial_state *info = tty->driver_data;
unsigned long flags;
unsigned int cflag = tty->termios->c_cflag;
unsigned int cflag = tty->termios.c_cflag;

change_speed(tty, info, old_termios);

Expand All @@ -1347,7 +1347,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
if (!(old_termios->c_cflag & CBAUD) &&
(cflag & CBAUD)) {
info->MCR |= SER_DTR;
if (!(tty->termios->c_cflag & CRTSCTS) ||
if (!(tty->termios.c_cflag & CRTSCTS) ||
!test_bit(TTY_THROTTLED, &tty->flags)) {
info->MCR |= SER_RTS;
}
Expand All @@ -1358,7 +1358,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)

/* Handle turning off CRTSCTS */
if ((old_termios->c_cflag & CRTSCTS) &&
!(tty->termios->c_cflag & CRTSCTS)) {
!(tty->termios.c_cflag & CRTSCTS)) {
tty->hw_stopped = 0;
rs_start(tty);
}
Expand All @@ -1371,7 +1371,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
* or not. Hence, this may change.....
*/
if (!(old_termios->c_cflag & CLOCAL) &&
(tty->termios->c_cflag & CLOCAL))
(tty->termios.c_cflag & CLOCAL))
wake_up_interruptible(&info->open_wait);
#endif
}
Expand Down
19 changes: 8 additions & 11 deletions drivers/tty/cyclades.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
info->port.xmit_buf = NULL;
free_page((unsigned long)temp);
}
if (tty->termios->c_cflag & HUPCL)
if (tty->termios.c_cflag & HUPCL)
cyy_change_rts_dtr(info, 0, TIOCM_RTS | TIOCM_DTR);

cyy_issue_cmd(info, CyCHAN_CTL | CyDIS_RCVR);
Expand Down Expand Up @@ -1488,7 +1488,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
free_page((unsigned long)temp);
}

if (tty->termios->c_cflag & HUPCL)
if (tty->termios.c_cflag & HUPCL)
tty_port_lower_dtr_rts(&info->port);

set_bit(TTY_IO_ERROR, &tty->flags);
Expand Down Expand Up @@ -1999,14 +1999,11 @@ static void cy_set_line_char(struct cyclades_port *info, struct tty_struct *tty)
int baud, baud_rate = 0;
int i;

if (!tty->termios) /* XXX can this happen at all? */
return;

if (info->line == -1)
return;

cflag = tty->termios->c_cflag;
iflag = tty->termios->c_iflag;
cflag = tty->termios.c_cflag;
iflag = tty->termios.c_iflag;

/*
* Set up the tty->alt_speed kludge
Expand Down Expand Up @@ -2825,7 +2822,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
cy_set_line_char(info, tty);

if ((old_termios->c_cflag & CRTSCTS) &&
!(tty->termios->c_cflag & CRTSCTS)) {
!(tty->termios.c_cflag & CRTSCTS)) {
tty->hw_stopped = 0;
cy_start(tty);
}
Expand All @@ -2837,7 +2834,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
* or not. Hence, this may change.....
*/
if (!(old_termios->c_cflag & CLOCAL) &&
(tty->termios->c_cflag & CLOCAL))
(tty->termios.c_cflag & CLOCAL))
wake_up_interruptible(&info->port.open_wait);
#endif
} /* cy_set_termios */
Expand Down Expand Up @@ -2899,7 +2896,7 @@ static void cy_throttle(struct tty_struct *tty)
info->throttle = 1;
}

if (tty->termios->c_cflag & CRTSCTS) {
if (tty->termios.c_cflag & CRTSCTS) {
if (!cy_is_Z(card)) {
spin_lock_irqsave(&card->card_lock, flags);
cyy_change_rts_dtr(info, 0, TIOCM_RTS);
Expand Down Expand Up @@ -2938,7 +2935,7 @@ static void cy_unthrottle(struct tty_struct *tty)
cy_send_xchar(tty, START_CHAR(tty));
}

if (tty->termios->c_cflag & CRTSCTS) {
if (tty->termios.c_cflag & CRTSCTS) {
card = info->card;
if (!cy_is_Z(card)) {
spin_lock_irqsave(&card->card_lock, flags);
Expand Down
2 changes: 1 addition & 1 deletion drivers/tty/hvc/hvsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp)
spin_unlock_irqrestore(&hp->lock, flags);

/* Clear our own DTR */
if (!pv->tty || (pv->tty->termios->c_cflag & HUPCL))
if (!pv->tty || (pv->tty->termios.c_cflag & HUPCL))
hvsilib_write_mctrl(pv, 0);

/* Tear down the connection */
Expand Down
Loading

0 comments on commit adc8d74

Please sign in to comment.