Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Peter Hurley and committed by
Greg Kroah-Hartman
d41861ca 80f02d54

+157 -150
+2 -3
drivers/ipack/devices/ipoctal.c
··· 629 629 tty_port_hangup(&channel->tty_port); 630 630 631 631 ipoctal_reset_channel(channel); 632 - 633 - clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags); 632 + tty_port_set_initialized(&channel->tty_port, 0); 634 633 wake_up_interruptible(&channel->tty_port.open_wait); 635 634 } 636 635 ··· 641 642 return; 642 643 643 644 ipoctal_reset_channel(channel); 644 - clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags); 645 + tty_port_set_initialized(&channel->tty_port, 0); 645 646 } 646 647 647 648 static void ipoctal_cleanup(struct tty_struct *tty)
+5 -5
drivers/isdn/i4l/isdn_tty.c
··· 1049 1049 static int 1050 1050 isdn_tty_startup(modem_info *info) 1051 1051 { 1052 - if (info->port.flags & ASYNC_INITIALIZED) 1052 + if (tty_port_initialized(&info->port)) 1053 1053 return 0; 1054 1054 isdn_lock_drivers(); 1055 1055 #ifdef ISDN_DEBUG_MODEM_OPEN ··· 1066 1066 */ 1067 1067 isdn_tty_change_speed(info); 1068 1068 1069 - info->port.flags |= ASYNC_INITIALIZED; 1069 + tty_port_set_initialized(&info->port, 1); 1070 1070 info->msr |= (UART_MSR_DSR | UART_MSR_CTS); 1071 1071 info->send_outstanding = 0; 1072 1072 return 0; ··· 1079 1079 static void 1080 1080 isdn_tty_shutdown(modem_info *info) 1081 1081 { 1082 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1082 + if (!tty_port_initialized(&info->port)) 1083 1083 return; 1084 1084 #ifdef ISDN_DEBUG_MODEM_OPEN 1085 1085 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); ··· 1099 1099 if (info->port.tty) 1100 1100 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 1101 1101 1102 - info->port.flags &= ~ASYNC_INITIALIZED; 1102 + tty_port_set_initialized(&info->port, 0); 1103 1103 } 1104 1104 1105 1105 /* isdn_tty_write() is the main send-routine. It is called from the upper ··· 1577 1577 * interrupt driver to stop checking the data ready bit in the 1578 1578 * line status register. 1579 1579 */ 1580 - if (port->flags & ASYNC_INITIALIZED) { 1580 + if (tty_port_initialized(port)) { 1581 1581 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 1582 1582 /* 1583 1583 * Before we drop DTR, make sure the UART transmitter
+5 -7
drivers/s390/char/con3215.c
··· 311 311 */ 312 312 static inline void raw3215_try_io(struct raw3215_info *raw) 313 313 { 314 - if (!(raw->port.flags & ASYNC_INITIALIZED) || 315 - tty_port_suspended(&raw->port)) 314 + if (!tty_port_initialized(&raw->port) || tty_port_suspended(&raw->port)) 316 315 return; 317 316 if (raw->queued_read != NULL) 318 317 raw3215_start_io(raw); ··· 615 616 { 616 617 unsigned long flags; 617 618 618 - if (raw->port.flags & ASYNC_INITIALIZED) 619 + if (tty_port_initialized(&raw->port)) 619 620 return 0; 620 621 raw->line_pos = 0; 621 - raw->port.flags |= ASYNC_INITIALIZED; 622 + tty_port_set_initialized(&raw->port, 1); 622 623 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 623 624 raw3215_try_io(raw); 624 625 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); ··· 634 635 DECLARE_WAITQUEUE(wait, current); 635 636 unsigned long flags; 636 637 637 - if (!(raw->port.flags & ASYNC_INITIALIZED) || 638 - (raw->flags & RAW3215_FIXED)) 638 + if (!tty_port_initialized(&raw->port) || (raw->flags & RAW3215_FIXED)) 639 639 return; 640 640 /* Wait for outstanding requests, then free irq */ 641 641 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); ··· 648 650 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 649 651 remove_wait_queue(&raw->empty_wait, &wait); 650 652 set_current_state(TASK_RUNNING); 651 - raw->port.flags &= ~ASYNC_INITIALIZED; 653 + tty_port_set_initialized(&raw->port, 1); 652 654 } 653 655 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 654 656 }
+7 -7
drivers/tty/amiserial.c
··· 525 525 526 526 local_irq_save(flags); 527 527 528 - if (port->flags & ASYNC_INITIALIZED) { 528 + if (tty_port_initialized(port)) { 529 529 free_page(page); 530 530 goto errout; 531 531 } ··· 586 586 */ 587 587 change_speed(tty, info, NULL); 588 588 589 - port->flags |= ASYNC_INITIALIZED; 589 + tty_port_set_initialized(port, 1); 590 590 local_irq_restore(flags); 591 591 return 0; 592 592 ··· 604 604 unsigned long flags; 605 605 struct serial_state *state; 606 606 607 - if (!(info->tport.flags & ASYNC_INITIALIZED)) 607 + if (!tty_port_initialized(&info->tport)) 608 608 return; 609 609 610 610 state = info; ··· 645 645 646 646 set_bit(TTY_IO_ERROR, &tty->flags); 647 647 648 - info->tport.flags &= ~ASYNC_INITIALIZED; 648 + tty_port_set_initialized(&info->tport, 0); 649 649 local_irq_restore(flags); 650 650 } 651 651 ··· 1084 1084 port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1085 1085 1086 1086 check_and_exit: 1087 - if (port->flags & ASYNC_INITIALIZED) { 1087 + if (tty_port_initialized(port)) { 1088 1088 if (change_spd) { 1089 1089 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1090 1090 tty->alt_speed = 57600; ··· 1390 1390 * line status register. 1391 1391 */ 1392 1392 state->read_status_mask &= ~UART_LSR_DR; 1393 - if (port->flags & ASYNC_INITIALIZED) { 1393 + if (tty_port_initialized(port)) { 1394 1394 /* disable receive interrupts */ 1395 1395 custom.intena = IF_RBF; 1396 1396 mb(); ··· 1538 1538 1539 1539 local_irq_save(flags); 1540 1540 status = ciab.pra; 1541 - control = (state->tport.flags & ASYNC_INITIALIZED) ? state->MCR : status; 1541 + control = tty_port_initialized(&state->tport) ? state->MCR : status; 1542 1542 local_irq_restore(flags); 1543 1543 1544 1544 stat_buf[0] = 0;
+7 -7
drivers/tty/cyclades.c
··· 1279 1279 1280 1280 spin_lock_irqsave(&card->card_lock, flags); 1281 1281 1282 - if (info->port.flags & ASYNC_INITIALIZED) 1282 + if (tty_port_initialized(&info->port)) 1283 1283 goto errout; 1284 1284 1285 1285 if (!info->type) { ··· 1364 1364 /* enable send, recv, modem !!! */ 1365 1365 } 1366 1366 1367 - info->port.flags |= ASYNC_INITIALIZED; 1367 + tty_port_set_initialized(&info->port, 1); 1368 1368 1369 1369 clear_bit(TTY_IO_ERROR, &tty->flags); 1370 1370 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; ··· 1424 1424 struct cyclades_card *card; 1425 1425 unsigned long flags; 1426 1426 1427 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1427 + if (!tty_port_initialized(&info->port)) 1428 1428 return; 1429 1429 1430 1430 card = info->card; ··· 1448 1448 some later date (after testing)!!! */ 1449 1449 1450 1450 set_bit(TTY_IO_ERROR, &tty->flags); 1451 - info->port.flags &= ~ASYNC_INITIALIZED; 1451 + tty_port_set_initialized(&info->port, 0); 1452 1452 spin_unlock_irqrestore(&card->card_lock, flags); 1453 1453 } else { 1454 1454 #ifdef CY_DEBUG_OPEN ··· 1473 1473 tty_port_lower_dtr_rts(&info->port); 1474 1474 1475 1475 set_bit(TTY_IO_ERROR, &tty->flags); 1476 - info->port.flags &= ~ASYNC_INITIALIZED; 1476 + tty_port_set_initialized(&info->port, 0); 1477 1477 1478 1478 spin_unlock_irqrestore(&card->card_lock, flags); 1479 1479 } ··· 1711 1711 /* Stop accepting input */ 1712 1712 cyy_writeb(info, CyCAR, channel & 0x03); 1713 1713 cyy_writeb(info, CySRER, cyy_readb(info, CySRER) & ~CyRxData); 1714 - if (info->port.flags & ASYNC_INITIALIZED) { 1714 + if (tty_port_initialized(&info->port)) { 1715 1715 /* Waiting for on-board buffers to be empty before 1716 1716 closing the port */ 1717 1717 spin_unlock_irqrestore(&card->card_lock, flags); ··· 2334 2334 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 2335 2335 2336 2336 check_and_exit: 2337 - if (info->port.flags & ASYNC_INITIALIZED) { 2337 + if (tty_port_initialized(&info->port)) { 2338 2338 cy_set_line_char(info, tty); 2339 2339 ret = 0; 2340 2340 } else {
+3 -3
drivers/tty/isicom.c
··· 438 438 439 439 for (; count > 0; count--, port++) { 440 440 /* port not active or tx disabled to force flow control */ 441 - if (!(port->port.flags & ASYNC_INITIALIZED) || 442 - !(port->status & ISI_TXOK)) 441 + if (!tty_port_initialized(&port->port) || 442 + !(port->status & ISI_TXOK)) 443 443 continue; 444 444 445 445 txcount = min_t(short, TX_SIZE, port->xmit_cnt); ··· 553 553 return IRQ_HANDLED; 554 554 } 555 555 port = card->ports + channel; 556 - if (!(port->port.flags & ASYNC_INITIALIZED)) { 556 + if (!tty_port_initialized(&port->port)) { 557 557 outw(0x0000, base+0x04); /* enable interrupts */ 558 558 spin_unlock(&card->card_lock); 559 559 return IRQ_HANDLED;
+5 -5
drivers/tty/moxa.c
··· 912 912 913 913 /* pci hot-un-plug support */ 914 914 for (a = 0; a < brd->numPorts; a++) 915 - if (brd->ports[a].port.flags & ASYNC_INITIALIZED) 915 + if (tty_port_initialized(&brd->ports[a].port)) 916 916 tty_port_tty_hangup(&brd->ports[a].port, false); 917 917 918 918 for (a = 0; a < MAX_PORTS_PER_BOARD; a++) ··· 921 921 while (1) { 922 922 opened = 0; 923 923 for (a = 0; a < brd->numPorts; a++) 924 - if (brd->ports[a].port.flags & ASYNC_INITIALIZED) 924 + if (tty_port_initialized(&brd->ports[a].port)) 925 925 opened++; 926 926 mutex_unlock(&moxa_openlock); 927 927 if (!opened) ··· 1192 1192 tty->driver_data = ch; 1193 1193 tty_port_tty_set(&ch->port, tty); 1194 1194 mutex_lock(&ch->port.mutex); 1195 - if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1195 + if (!tty_port_initialized(&ch->port)) { 1196 1196 ch->statusflags = 0; 1197 1197 moxa_set_tty_param(tty, &tty->termios); 1198 1198 MoxaPortLineCtrl(ch, 1, 1); 1199 1199 MoxaPortEnable(ch); 1200 1200 MoxaSetFifo(ch, ch->type == PORT_16550A); 1201 - ch->port.flags |= ASYNC_INITIALIZED; 1201 + tty_port_set_initialized(&ch->port, 1); 1202 1202 } 1203 1203 mutex_unlock(&ch->port.mutex); 1204 1204 mutex_unlock(&moxa_openlock); ··· 1379 1379 { 1380 1380 struct tty_struct *tty = tty_port_tty_get(&p->port); 1381 1381 void __iomem *ofsAddr; 1382 - unsigned int inited = p->port.flags & ASYNC_INITIALIZED; 1382 + unsigned int inited = tty_port_initialized(&p->port); 1383 1383 u16 intr; 1384 1384 1385 1385 if (tty) {
+6 -8
drivers/tty/mxser.c
··· 1081 1081 mutex_lock(&port->mutex); 1082 1082 mxser_close_port(port); 1083 1083 mxser_flush_buffer(tty); 1084 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 1085 - if (C_HUPCL(tty)) 1086 - tty_port_lower_dtr_rts(port); 1087 - } 1084 + if (tty_port_initialized(port) && C_HUPCL(tty)) 1085 + tty_port_lower_dtr_rts(port); 1088 1086 mxser_shutdown_port(port); 1089 - clear_bit(ASYNCB_INITIALIZED, &port->flags); 1087 + tty_port_set_initialized(port, 0); 1090 1088 mutex_unlock(&port->mutex); 1091 1089 info->closing = 0; 1092 1090 /* Right now the tty_port set is done outside of the close_end helper ··· 1280 1282 1281 1283 process_txrx_fifo(info); 1282 1284 1283 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 1285 + if (tty_port_initialized(port)) { 1284 1286 if (flags != (port->flags & ASYNC_SPD_MASK)) { 1285 1287 spin_lock_irqsave(&info->slock, sl_flags); 1286 1288 mxser_change_speed(tty, NULL); ··· 1289 1291 } else { 1290 1292 retval = mxser_activate(port, tty); 1291 1293 if (retval == 0) 1292 - set_bit(ASYNCB_INITIALIZED, &port->flags); 1294 + tty_port_set_initialized(port, 1); 1293 1295 } 1294 1296 return retval; 1295 1297 } ··· 2249 2251 iir &= MOXA_MUST_IIR_MASK; 2250 2252 tty = tty_port_tty_get(&port->port); 2251 2253 if (!tty || port->closing || 2252 - !(port->port.flags & ASYNC_INITIALIZED)) { 2254 + !tty_port_initialized(&port->port)) { 2253 2255 status = inb(port->ioaddr + UART_LSR); 2254 2256 outb(0x27, port->ioaddr + UART_FCR); 2255 2257 inb(port->ioaddr + UART_MSR);
+3 -5
drivers/tty/n_gsm.c
··· 2949 2949 dlci->modem_rx = 0; 2950 2950 /* We could in theory open and close before we wait - eg if we get 2951 2951 a DM straight back. This is ok as that will have caused a hangup */ 2952 - set_bit(ASYNCB_INITIALIZED, &port->flags); 2952 + tty_port_set_initialized(port, 1); 2953 2953 /* Start sending off SABM messages */ 2954 2954 gsm_dlci_begin_open(dlci); 2955 2955 /* And wait for virtual carrier */ ··· 2972 2972 if (tty_port_close_start(&dlci->port, tty, filp) == 0) 2973 2973 return; 2974 2974 gsm_dlci_begin_close(dlci); 2975 - if (test_bit(ASYNCB_INITIALIZED, &dlci->port.flags)) { 2976 - if (C_HUPCL(tty)) 2977 - tty_port_lower_dtr_rts(&dlci->port); 2978 - } 2975 + if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) 2976 + tty_port_lower_dtr_rts(&dlci->port); 2979 2977 tty_port_close_end(&dlci->port, tty); 2980 2978 tty_port_tty_set(&dlci->port, NULL); 2981 2979 return;
+5 -5
drivers/tty/rocket.c
··· 495 495 if (!info) 496 496 return; 497 497 498 - if ((info->port.flags & ASYNC_INITIALIZED) == 0) { 498 + if (!tty_port_initialized(&info->port)) { 499 499 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 500 500 "info->flags & NOT_INIT\n"); 501 501 return; ··· 920 920 /* 921 921 * Info->count is now 1; so it's safe to sleep now. 922 922 */ 923 - if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { 923 + if (!tty_port_initialized(port)) { 924 924 cp = &info->channel; 925 925 sSetRxTrigger(cp, TRIG_1); 926 926 if (sGetChanStatus(cp) & CD_ACT) ··· 944 944 sEnRxFIFO(cp); 945 945 sEnTransmit(cp); 946 946 947 - set_bit(ASYNCB_INITIALIZED, &info->port.flags); 947 + tty_port_set_initialized(&info->port, 1); 948 948 949 949 /* 950 950 * Set up the tty->alt_speed kludge ··· 1042 1042 } 1043 1043 } 1044 1044 spin_lock_irq(&port->lock); 1045 - port->flags &= ~ASYNC_INITIALIZED; 1046 1045 tty->closing = 0; 1047 1046 spin_unlock_irq(&port->lock); 1047 + tty_port_set_initialized(port, 0); 1048 1048 tty_port_set_active(port, 0); 1049 1049 mutex_unlock(&port->mutex); 1050 1050 tty_port_tty_set(port, NULL); ··· 1513 1513 sDisCTSFlowCtl(cp); 1514 1514 sDisTxSoftFlowCtl(cp); 1515 1515 sClrTxXOFF(cp); 1516 - clear_bit(ASYNCB_INITIALIZED, &info->port.flags); 1516 + tty_port_set_initialized(&info->port, 0); 1517 1517 1518 1518 wake_up_interruptible(&info->port.open_wait); 1519 1519 }
+8 -9
drivers/tty/serial/crisv10.c
··· 2599 2599 2600 2600 /* if it was already initialized, skip this */ 2601 2601 2602 - if (info->port.flags & ASYNC_INITIALIZED) { 2602 + if (tty_port_initialized(&info->port)) { 2603 2603 local_irq_restore(flags); 2604 2604 free_page(xmit_page); 2605 2605 return 0; ··· 2703 2703 e100_rts(info, 1); 2704 2704 e100_dtr(info, 1); 2705 2705 2706 - info->port.flags |= ASYNC_INITIALIZED; 2706 + tty_port_set_initialized(&info->port, 1); 2707 2707 2708 2708 local_irq_restore(flags); 2709 2709 return 0; ··· 2745 2745 info->tr_running = 0; 2746 2746 } 2747 2747 2748 - if (!(info->port.flags & ASYNC_INITIALIZED)) 2748 + if (!tty_port_initialized(&info->port)) 2749 2749 return; 2750 2750 2751 2751 #ifdef SERIAL_DEBUG_OPEN ··· 2776 2776 if (info->port.tty) 2777 2777 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 2778 2778 2779 - info->port.flags &= ~ASYNC_INITIALIZED; 2779 + tty_port_set_initialized(&info->port, 0); 2780 2780 local_irq_restore(flags); 2781 2781 } 2782 2782 ··· 3273 3273 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 3274 3274 3275 3275 check_and_exit: 3276 - if (info->port.flags & ASYNC_INITIALIZED) { 3276 + if (tty_port_initialized(&info->port)) 3277 3277 change_speed(info); 3278 - } else 3278 + else 3279 3279 retval = startup(info); 3280 3280 return retval; 3281 3281 } ··· 3628 3628 e100_disable_rx(info); 3629 3629 e100_disable_rx_irq(info); 3630 3630 3631 - if (info->port.flags & ASYNC_INITIALIZED) { 3631 + if (tty_port_initialized(&info->port)) { 3632 3632 /* 3633 3633 * Before we drop DTR, make sure the UART transmitter 3634 3634 * has completely drained; this is especially ··· 3787 3787 e100_dtr(info, 1); 3788 3788 local_irq_restore(flags); 3789 3789 set_current_state(TASK_INTERRUPTIBLE); 3790 - if (tty_hung_up_p(filp) || 3791 - !(info->port.flags & ASYNC_INITIALIZED)) { 3790 + if (tty_hung_up_p(filp) || !tty_port_initialized(&info->port)) { 3792 3791 #ifdef SERIAL_DO_RESTART 3793 3792 if (info->port.flags & ASYNC_HUP_NOTIFY) 3794 3793 retval = -EAGAIN;
+13 -11
drivers/tty/serial/serial_core.c
··· 196 196 struct tty_port *port = &state->port; 197 197 int retval; 198 198 199 - if (port->flags & ASYNC_INITIALIZED) 199 + if (tty_port_initialized(port)) 200 200 return 0; 201 201 202 202 /* ··· 207 207 208 208 retval = uart_port_startup(tty, state, init_hw); 209 209 if (!retval) { 210 - set_bit(ASYNCB_INITIALIZED, &port->flags); 210 + tty_port_set_initialized(port, 1); 211 211 clear_bit(TTY_IO_ERROR, &tty->flags); 212 212 } else if (retval > 0) 213 213 retval = 0; ··· 231 231 if (tty) 232 232 set_bit(TTY_IO_ERROR, &tty->flags); 233 233 234 - if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { 234 + if (tty_port_initialized(port)) { 235 + tty_port_set_initialized(port, 0); 236 + 235 237 /* 236 238 * Turn off DTR and RTS early. 237 239 */ ··· 888 886 retval = 0; 889 887 if (uport->type == PORT_UNKNOWN) 890 888 goto exit; 891 - if (port->flags & ASYNC_INITIALIZED) { 889 + if (tty_port_initialized(port)) { 892 890 if (((old_flags ^ uport->flags) & UPF_SPD_MASK) || 893 891 old_custom_divisor != uport->custom_divisor) { 894 892 /* ··· 1392 1390 * At this point, we stop accepting input. To do this, we 1393 1391 * disable the receive line status interrupts. 1394 1392 */ 1395 - if (port->flags & ASYNC_INITIALIZED) { 1393 + if (tty_port_initialized(port)) { 1396 1394 spin_lock_irq(&uport->lock); 1397 1395 uport->ops->stop_rx(uport); 1398 1396 spin_unlock_irq(&uport->lock); ··· 2005 2003 2006 2004 uport->suspended = 1; 2007 2005 2008 - if (port->flags & ASYNC_INITIALIZED) { 2006 + if (tty_port_initialized(port)) { 2009 2007 const struct uart_ops *ops = uport->ops; 2010 2008 int tries; 2011 2009 2012 2010 tty_port_set_suspended(port, 1); 2013 - clear_bit(ASYNCB_INITIALIZED, &port->flags); 2011 + tty_port_set_initialized(port, 0); 2014 2012 2015 2013 spin_lock_irq(&uport->lock); 2016 2014 ops->stop_tx(uport); ··· 2109 2107 ops->set_mctrl(uport, uport->mctrl); 2110 2108 ops->start_tx(uport); 2111 2109 spin_unlock_irq(&uport->lock); 2112 - set_bit(ASYNCB_INITIALIZED, &port->flags); 2110 + tty_port_set_initialized(port, 1); 2113 2111 } else { 2114 2112 /* 2115 2113 * Failed to resume - maybe hardware went away? ··· 2250 2248 ret = 0; 2251 2249 mutex_lock(&tport->mutex); 2252 2250 /* 2253 - * We don't set ASYNCB_INITIALIZED as we only initialized the 2254 - * hw, e.g. state->xmit is still uninitialized. 2251 + * We don't set initialized as we only initialized the hw, 2252 + * e.g. state->xmit is still uninitialized. 2255 2253 */ 2256 - if (!test_bit(ASYNCB_INITIALIZED, &tport->flags)) 2254 + if (!tty_port_initialized(tport)) 2257 2255 ret = port->ops->poll_init(port); 2258 2256 mutex_unlock(&tport->mutex); 2259 2257 if (ret)
+22 -24
drivers/tty/synclink.c
··· 1749 1749 static int startup(struct mgsl_struct * info) 1750 1750 { 1751 1751 int retval = 0; 1752 - 1752 + 1753 1753 if ( debug_level >= DEBUG_LEVEL_INFO ) 1754 1754 printk("%s(%d):mgsl_startup(%s)\n",__FILE__,__LINE__,info->device_name); 1755 - 1756 - if (info->port.flags & ASYNC_INITIALIZED) 1755 + 1756 + if (tty_port_initialized(&info->port)) 1757 1757 return 0; 1758 - 1758 + 1759 1759 if (!info->xmit_buf) { 1760 1760 /* allocate a page of memory for a transmit buffer */ 1761 1761 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); ··· 1788 1788 1789 1789 /* program hardware for current parameters */ 1790 1790 mgsl_change_params(info); 1791 - 1791 + 1792 1792 if (info->port.tty) 1793 1793 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); 1794 1794 1795 - info->port.flags |= ASYNC_INITIALIZED; 1796 - 1795 + tty_port_set_initialized(&info->port, 1); 1796 + 1797 1797 return 0; 1798 - 1799 1798 } /* end of startup() */ 1800 1799 1801 1800 /* shutdown() ··· 1807 1808 static void shutdown(struct mgsl_struct * info) 1808 1809 { 1809 1810 unsigned long flags; 1810 - 1811 - if (!(info->port.flags & ASYNC_INITIALIZED)) 1811 + 1812 + if (!tty_port_initialized(&info->port)) 1812 1813 return; 1813 1814 1814 1815 if (debug_level >= DEBUG_LEVEL_INFO) ··· 1852 1853 1853 1854 spin_unlock_irqrestore(&info->irq_spinlock,flags); 1854 1855 1855 - mgsl_release_resources(info); 1856 - 1856 + mgsl_release_resources(info); 1857 + 1857 1858 if (info->port.tty) 1858 1859 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 1859 1860 1860 - info->port.flags &= ~ASYNC_INITIALIZED; 1861 - 1861 + tty_port_set_initialized(&info->port, 0); 1862 1862 } /* end of shutdown() */ 1863 1863 1864 1864 static void mgsl_program_hw(struct mgsl_struct *info) ··· 3082 3084 goto cleanup; 3083 3085 3084 3086 mutex_lock(&info->port.mutex); 3085 - if (info->port.flags & ASYNC_INITIALIZED) 3087 + if (tty_port_initialized(&info->port)) 3086 3088 mgsl_wait_until_sent(tty, info->timeout); 3087 3089 mgsl_flush_buffer(tty); 3088 3090 tty_ldisc_flush(tty); ··· 3120 3122 if (debug_level >= DEBUG_LEVEL_INFO) 3121 3123 printk("%s(%d):mgsl_wait_until_sent(%s) entry\n", 3122 3124 __FILE__,__LINE__, info->device_name ); 3123 - 3125 + 3124 3126 if (mgsl_paranoia_check(info, tty->name, "mgsl_wait_until_sent")) 3125 3127 return; 3126 3128 3127 - if (!(info->port.flags & ASYNC_INITIALIZED)) 3129 + if (!tty_port_initialized(&info->port)) 3128 3130 goto exit; 3129 - 3131 + 3130 3132 orig_jiffies = jiffies; 3131 - 3133 + 3132 3134 /* Set check interval to 1/5 of estimated time to 3133 3135 * send a character, and make it at least 1. The check 3134 3136 * interval should also be less than the timeout. ··· 3288 3290 port->count--; 3289 3291 spin_unlock_irqrestore(&info->irq_spinlock, flags); 3290 3292 port->blocked_open++; 3291 - 3293 + 3292 3294 while (1) { 3293 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 3295 + if (C_BAUD(tty) && tty_port_initialized(port)) 3294 3296 tty_port_raise_dtr_rts(port); 3295 - 3297 + 3296 3298 set_current_state(TASK_INTERRUPTIBLE); 3297 - 3298 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ 3299 + 3300 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 3299 3301 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 3300 3302 -EAGAIN : -ERESTARTSYS; 3301 3303 break;
+8 -8
drivers/tty/synclinkmp.c
··· 812 812 goto cleanup; 813 813 814 814 mutex_lock(&info->port.mutex); 815 - if (info->port.flags & ASYNC_INITIALIZED) 815 + if (tty_port_initialized(&info->port)) 816 816 wait_until_sent(tty, info->timeout); 817 817 818 818 flush_buffer(tty); ··· 1061 1061 if (sanity_check(info, tty->name, "wait_until_sent")) 1062 1062 return; 1063 1063 1064 - if (!test_bit(ASYNCB_INITIALIZED, &info->port.flags)) 1064 + if (!tty_port_initialized(&info->port)) 1065 1065 goto exit; 1066 1066 1067 1067 orig_jiffies = jiffies; ··· 2636 2636 if ( debug_level >= DEBUG_LEVEL_INFO ) 2637 2637 printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name); 2638 2638 2639 - if (info->port.flags & ASYNC_INITIALIZED) 2639 + if (tty_port_initialized(&info->port)) 2640 2640 return 0; 2641 2641 2642 2642 if (!info->tx_buf) { ··· 2662 2662 if (info->port.tty) 2663 2663 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); 2664 2664 2665 - info->port.flags |= ASYNC_INITIALIZED; 2665 + tty_port_set_initialized(&info->port, 1); 2666 2666 2667 2667 return 0; 2668 2668 } ··· 2673 2673 { 2674 2674 unsigned long flags; 2675 2675 2676 - if (!(info->port.flags & ASYNC_INITIALIZED)) 2676 + if (!tty_port_initialized(&info->port)) 2677 2677 return; 2678 2678 2679 2679 if (debug_level >= DEBUG_LEVEL_INFO) ··· 2705 2705 if (info->port.tty) 2706 2706 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 2707 2707 2708 - info->port.flags &= ~ASYNC_INITIALIZED; 2708 + tty_port_set_initialized(&info->port, 0); 2709 2709 } 2710 2710 2711 2711 static void program_hw(SLMP_INFO *info) ··· 3308 3308 port->blocked_open++; 3309 3309 3310 3310 while (1) { 3311 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 3311 + if (C_BAUD(tty) && tty_port_initialized(port)) 3312 3312 tty_port_raise_dtr_rts(port); 3313 3313 3314 3314 set_current_state(TASK_INTERRUPTIBLE); 3315 3315 3316 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ 3316 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 3317 3317 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 3318 3318 -EAGAIN : -ERESTARTSYS; 3319 3319 break;
+7 -6
drivers/tty/tty_port.c
··· 204 204 if (port->console) 205 205 goto out; 206 206 207 - if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { 207 + if (tty_port_initialized(port)) { 208 + tty_port_set_initialized(port, 0); 208 209 /* 209 210 * Drop DTR/RTS if HUPCL is set. This causes any attached 210 211 * modem to hang up the line. ··· 394 393 395 394 while (1) { 396 395 /* Indicate we are open */ 397 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 396 + if (C_BAUD(tty) && tty_port_initialized(port)) 398 397 tty_port_raise_dtr_rts(port); 399 398 400 399 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); 401 400 /* Check for a hangup or uninitialised port. 402 401 Return accordingly */ 403 - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 402 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 404 403 if (port->flags & ASYNC_HUP_NOTIFY) 405 404 retval = -EAGAIN; 406 405 else ··· 481 480 482 481 tty->closing = 1; 483 482 484 - if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { 483 + if (tty_port_initialized(port)) { 485 484 /* Don't block on a stalled port, just pull the chain */ 486 485 if (tty->flow_stopped) 487 486 tty_driver_flush_buffer(tty); ··· 579 578 580 579 mutex_lock(&port->mutex); 581 580 582 - if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { 581 + if (!tty_port_initialized(port)) { 583 582 clear_bit(TTY_IO_ERROR, &tty->flags); 584 583 if (port->ops->activate) { 585 584 int retval = port->ops->activate(port, tty); ··· 588 587 return retval; 589 588 } 590 589 } 591 - set_bit(ASYNCB_INITIALIZED, &port->flags); 590 + tty_port_set_initialized(port, 1); 592 591 } 593 592 mutex_unlock(&port->mutex); 594 593 return tty_port_block_til_ready(port, tty, filp);
+2 -2
drivers/usb/class/cdc-acm.c
··· 1680 1680 if (--acm->susp_count) 1681 1681 goto out; 1682 1682 1683 - if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { 1683 + if (tty_port_initialized(&acm->port)) { 1684 1684 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); 1685 1685 1686 1686 for (;;) { ··· 1710 1710 { 1711 1711 struct acm *acm = usb_get_intfdata(intf); 1712 1712 1713 - if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) 1713 + if (tty_port_initialized(&acm->port)) 1714 1714 tty_port_tty_hangup(&acm->port, false); 1715 1715 1716 1716 return acm_resume(intf);
+2 -2
drivers/usb/serial/console.c
··· 127 127 info->port = port; 128 128 129 129 ++port->port.count; 130 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { 130 + if (!tty_port_initialized(&port->port)) { 131 131 if (serial->type->set_termios) { 132 132 /* 133 133 * allocate a fake tty so the driver can initialize ··· 168 168 tty_port_tty_set(&port->port, NULL); 169 169 tty_kref_put(tty); 170 170 } 171 - set_bit(ASYNCB_INITIALIZED, &port->port.flags); 171 + tty_port_set_initialized(&port->port, 1); 172 172 } 173 173 /* Now that any required fake tty operations are completed restore 174 174 * the tty port count */
+3 -3
drivers/usb/serial/generic.c
··· 473 473 * Use tty-port initialised flag to detect all hangups including the 474 474 * one generated at USB-device disconnect. 475 475 */ 476 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 476 + if (!tty_port_initialized(&port->port)) 477 477 return true; 478 478 479 479 spin_lock_irqsave(&port->lock, flags); ··· 503 503 504 504 ret = wait_event_interruptible(port->port.delta_msr_wait, 505 505 usb_serial_generic_msr_changed(tty, arg, &cnow)); 506 - if (!ret && !test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 506 + if (!ret && !tty_port_initialized(&port->port)) 507 507 ret = -EIO; 508 508 509 509 return ret; ··· 606 606 607 607 for (i = 0; i < serial->num_ports; i++) { 608 608 port = serial->port[i]; 609 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 609 + if (!tty_port_initialized(&port->port)) 610 610 continue; 611 611 612 612 if (port->bulk_in_size) {
+3 -3
drivers/usb/serial/mxuport.c
··· 503 503 return; 504 504 } 505 505 506 - if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { 506 + if (tty_port_initialized(&demux_port->port)) { 507 507 ch = data + HEADER_SIZE; 508 508 mxuport_process_read_urb_data(demux_port, ch, rcv_len); 509 509 } else { ··· 544 544 } 545 545 546 546 demux_port = serial->port[rcv_port]; 547 - if (test_bit(ASYNCB_INITIALIZED, &demux_port->port.flags)) { 547 + if (tty_port_initialized(&demux_port->port)) { 548 548 ch = data + HEADER_SIZE; 549 549 rcv_event = get_unaligned_be16(data + 2); 550 550 mxuport_process_read_urb_event(demux_port, ch, ··· 1339 1339 1340 1340 for (i = 0; i < serial->num_ports; i++) { 1341 1341 port = serial->port[i]; 1342 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 1342 + if (!tty_port_initialized(&port->port)) 1343 1343 continue; 1344 1344 1345 1345 r = usb_serial_generic_write_start(port, GFP_NOIO);
+2 -2
drivers/usb/serial/sierra.c
··· 776 776 777 777 /* 778 778 * Need to take susp_lock to make sure port is not already being 779 - * resumed, but no need to hold it due to ASYNC_INITIALIZED. 779 + * resumed, but no need to hold it due to initialized 780 780 */ 781 781 spin_lock_irq(&intfdata->susp_lock); 782 782 if (--intfdata->open_ports == 0) ··· 1039 1039 for (i = 0; i < serial->num_ports; i++) { 1040 1040 port = serial->port[i]; 1041 1041 1042 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 1042 + if (!tty_port_initialized(&port->port)) 1043 1043 continue; 1044 1044 1045 1045 err = sierra_submit_delayed_urbs(port);
+1 -1
drivers/usb/serial/usb-serial.c
··· 254 254 * 255 255 * Shut down a USB serial port. Serialized against activate by the 256 256 * tport mutex and kept to matching open/close pairs 257 - * of calls by the ASYNCB_INITIALIZED flag. 257 + * of calls by the initialized flag. 258 258 * 259 259 * Not called if tty is console. 260 260 */
+2 -2
drivers/usb/serial/usb_wwan.c
··· 464 464 465 465 /* 466 466 * Need to take susp_lock to make sure port is not already being 467 - * resumed, but no need to hold it due to ASYNC_INITIALIZED. 467 + * resumed, but no need to hold it due to initialized 468 468 */ 469 469 spin_lock_irq(&intfdata->susp_lock); 470 470 if (--intfdata->open_ports == 0) ··· 682 682 for (i = 0; i < serial->num_ports; i++) { 683 683 port = serial->port[i]; 684 684 685 - if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) 685 + if (!tty_port_initialized(&port->port)) 686 686 continue; 687 687 688 688 portdata = usb_get_serial_port_data(port);
+13
include/linux/tty.h
··· 610 610 clear_bit(TTY_PORT_SUSPENDED, &port->iflags); 611 611 } 612 612 613 + static inline bool tty_port_initialized(struct tty_port *port) 614 + { 615 + return test_bit(TTY_PORT_INITIALIZED, &port->iflags); 616 + } 617 + 618 + static inline void tty_port_set_initialized(struct tty_port *port, bool val) 619 + { 620 + if (val) 621 + set_bit(TTY_PORT_INITIALIZED, &port->iflags); 622 + else 623 + clear_bit(TTY_PORT_INITIALIZED, &port->iflags); 624 + } 625 + 613 626 extern struct tty_struct *tty_port_tty_get(struct tty_port *port); 614 627 extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); 615 628 extern int tty_port_carrier_raised(struct tty_port *port);
+8 -7
net/irda/ircomm/ircomm_tty.c
··· 220 220 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); 221 221 222 222 /* Check if already open */ 223 - if (test_and_set_bit(ASYNCB_INITIALIZED, &self->port.flags)) { 223 + if (tty_port_initialized(&self->port)) { 224 224 pr_debug("%s(), already open so break out!\n", __func__); 225 225 return 0; 226 226 } 227 + tty_port_set_initialized(&self->port, 1); 227 228 228 229 /* Register with IrCOMM */ 229 230 irda_notify_init(&notify); ··· 258 257 259 258 return 0; 260 259 err: 261 - clear_bit(ASYNCB_INITIALIZED, &self->port.flags); 260 + tty_port_set_initialized(&self->port, 0); 262 261 return ret; 263 262 } 264 263 ··· 319 318 spin_unlock_irqrestore(&port->lock, flags); 320 319 321 320 while (1) { 322 - if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) 321 + if (C_BAUD(tty) && tty_port_initialized(port)) 323 322 tty_port_raise_dtr_rts(port); 324 323 325 324 set_current_state(TASK_INTERRUPTIBLE); 326 325 327 - if (tty_hung_up_p(filp) || 328 - !test_bit(ASYNCB_INITIALIZED, &port->flags)) { 326 + if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { 329 327 retval = (port->flags & ASYNC_HUP_NOTIFY) ? 330 328 -EAGAIN : -ERESTARTSYS; 331 329 break; ··· 876 876 IRDA_ASSERT(self != NULL, return;); 877 877 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 878 878 879 - if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags)) 879 + if (!tty_port_initialized(&self->port)) 880 880 return; 881 + tty_port_set_initialized(&self->port, 0); 881 882 882 883 ircomm_tty_detach_cable(self); 883 884 ··· 1260 1259 seq_printf(m, "%cASYNC_CHECK_CD", sep); 1261 1260 sep = '|'; 1262 1261 } 1263 - if (self->port.flags & ASYNC_INITIALIZED) { 1262 + if (tty_port_initialized(&self->port)) { 1264 1263 seq_printf(m, "%cASYNC_INITIALIZED", sep); 1265 1264 sep = '|'; 1266 1265 }
+1 -1
net/irda/ircomm/ircomm_tty_ioctl.c
··· 324 324 325 325 check_and_exit: 326 326 327 - if (self->flags & ASYNC_INITIALIZED) { 327 + if (tty_port_initialized(self)) { 328 328 if (((old_state.flags & ASYNC_SPD_MASK) != 329 329 (self->flags & ASYNC_SPD_MASK)) || 330 330 (old_driver.custom_divisor != driver->custom_divisor)) {