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

tty: The big operations rework

- Operations are now a shared const function block as with most other Linux
objects

- Introduce wrappers for some optional functions to get consistent behaviour

- Wrap put_char which used to be patched by the tty layer

- Document which functions are needed/optional

- Make put_char report success/fail

- Cache the driver->ops pointer in the tty as tty->ops

- Remove various surplus lock calls we no longer need

- Remove proc_write method as noted by Alexey Dobriyan

- Introduce some missing sanity checks where certain driver/ldisc
combinations would oops as they didn't check needed methods were present

[akpm@linux-foundation.org: fix fs/compat_ioctl.c build]
[akpm@linux-foundation.org: fix isicom]
[akpm@linux-foundation.org: fix arch/ia64/hp/sim/simserial.c build]
[akpm@linux-foundation.org: fix kgdb]
Signed-off-by: Alan Cox <alan@redhat.com>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alan Cox and committed by
Linus Torvalds
f34d7a5b 251b8dd7

+539 -666
+7 -4
arch/ia64/hp/sim/simserial.c
··· 210 210 printk(KERN_ERR "simserial: do_softint called\n"); 211 211 } 212 212 213 - static void rs_put_char(struct tty_struct *tty, unsigned char ch) 213 + static int rs_put_char(struct tty_struct *tty, unsigned char ch) 214 214 { 215 215 struct async_struct *info = (struct async_struct *)tty->driver_data; 216 216 unsigned long flags; 217 217 218 - if (!tty || !info->xmit.buf) return; 218 + if (!tty || !info->xmit.buf) 219 + return 0; 219 220 220 221 local_irq_save(flags); 221 222 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) { 222 223 local_irq_restore(flags); 223 - return; 224 + return 0; 224 225 } 225 226 info->xmit.buf[info->xmit.head] = ch; 226 227 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1); 227 228 local_irq_restore(flags); 229 + return 1; 228 230 } 229 231 230 232 static void transmit_chars(struct async_struct *info, int *intr_done) ··· 623 621 * the line discipline to only process XON/XOFF characters. 624 622 */ 625 623 shutdown(info); 626 - if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); 624 + if (tty->ops->flush_buffer) 625 + tty->ops->flush_buffer(tty); 627 626 if (tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty); 628 627 info->event = 0; 629 628 info->tty = NULL;
+5 -8
drivers/bluetooth/hci_ldisc.c
··· 143 143 int len; 144 144 145 145 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 146 - len = tty->driver->write(tty, skb->data, skb->len); 146 + len = tty->ops->write(tty, skb->data, skb->len); 147 147 hdev->stat.byte_tx += len; 148 148 149 149 skb_pull(skb, len); ··· 190 190 191 191 /* Flush any pending characters in the driver and discipline. */ 192 192 tty_ldisc_flush(tty); 193 - if (tty->driver && tty->driver->flush_buffer) 194 - tty->driver->flush_buffer(tty); 193 + tty_driver_flush_buffer(tty); 195 194 196 195 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 197 196 hu->proto->flush(hu); ··· 284 285 285 286 if (tty->ldisc.flush_buffer) 286 287 tty->ldisc.flush_buffer(tty); 287 - 288 - if (tty->driver && tty->driver->flush_buffer) 289 - tty->driver->flush_buffer(tty); 288 + tty_driver_flush_buffer(tty); 290 289 291 290 return 0; 292 291 } ··· 371 374 spin_unlock(&hu->rx_lock); 372 375 373 376 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 374 - tty->driver->unthrottle) 375 - tty->driver->unthrottle(tty); 377 + tty->ops->unthrottle) 378 + tty->ops->unthrottle(tty); 376 379 } 377 380 378 381 static int hci_uart_register_dev(struct hci_uart *hu)
+6 -6
drivers/char/ip2/ip2main.c
··· 169 169 static int ip2_open(PTTY, struct file *); 170 170 static void ip2_close(PTTY, struct file *); 171 171 static int ip2_write(PTTY, const unsigned char *, int); 172 - static void ip2_putchar(PTTY, unsigned char); 172 + static int ip2_putchar(PTTY, unsigned char); 173 173 static void ip2_flush_chars(PTTY); 174 174 static int ip2_write_room(PTTY); 175 175 static int ip2_chars_in_buf(PTTY); ··· 1616 1616 1617 1617 serviceOutgoingFifo ( pCh->pMyBord ); 1618 1618 1619 - if ( tty->driver->flush_buffer ) 1620 - tty->driver->flush_buffer(tty); 1621 - if ( tty->ldisc.flush_buffer ) 1622 - tty->ldisc.flush_buffer(tty); 1619 + if ( tty->driver->ops->flush_buffer ) 1620 + tty->driver->ops->flush_buffer(tty); 1621 + tty_ldisc_flush(tty); 1623 1622 tty->closing = 0; 1624 1623 1625 1624 pCh->pTTY = NULL; ··· 1737 1738 /* */ 1738 1739 /* */ 1739 1740 /******************************************************************************/ 1740 - static void 1741 + static int 1741 1742 ip2_putchar( PTTY tty, unsigned char ch ) 1742 1743 { 1743 1744 i2ChanStrPtr pCh = tty->driver_data; ··· 1752 1753 ip2_flush_chars( tty ); 1753 1754 } else 1754 1755 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags); 1756 + return 1; 1755 1757 1756 1758 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch ); 1757 1759 }
+8 -7
drivers/char/isicom.c
··· 1140 1140 } 1141 1141 1142 1142 /* put_char et all */ 1143 - static void isicom_put_char(struct tty_struct *tty, unsigned char ch) 1143 + static int isicom_put_char(struct tty_struct *tty, unsigned char ch) 1144 1144 { 1145 1145 struct isi_port *port = tty->driver_data; 1146 1146 struct isi_board *card = port->card; 1147 1147 unsigned long flags; 1148 1148 1149 1149 if (isicom_paranoia_check(port, tty->name, "isicom_put_char")) 1150 - return; 1150 + return 0; 1151 1151 1152 1152 if (!port->xmit_buf) 1153 - return; 1153 + return 0; 1154 1154 1155 1155 spin_lock_irqsave(&card->card_lock, flags); 1156 - if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) 1157 - goto out; 1156 + if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 1157 + spin_unlock_irqrestore(&card->card_lock, flags); 1158 + return 0; 1159 + } 1158 1160 1159 1161 port->xmit_buf[port->xmit_head++] = ch; 1160 1162 port->xmit_head &= (SERIAL_XMIT_SIZE - 1); 1161 1163 port->xmit_cnt++; 1162 1164 spin_unlock_irqrestore(&card->card_lock, flags); 1163 - out: 1164 - return; 1165 + return 1; 1165 1166 } 1166 1167 1167 1168 /* flush_chars et all */
+1 -1
drivers/char/keyboard.c
··· 1230 1230 1231 1231 if (rep && 1232 1232 (!vc_kbd_mode(kbd, VC_REPEAT) || 1233 - (tty && !L_ECHO(tty) && tty->driver->chars_in_buffer(tty)))) { 1233 + (tty && !L_ECHO(tty) && tty_chars_in_buffer(tty)))) { 1234 1234 /* 1235 1235 * Don't repeat a key if the input buffers are not empty and the 1236 1236 * characters get aren't echoed locally. This makes key repeat
+4 -7
drivers/char/n_hdlc.c
··· 342 342 #endif 343 343 344 344 /* Flush any pending characters in the driver and discipline. */ 345 - 346 345 if (tty->ldisc.flush_buffer) 347 - tty->ldisc.flush_buffer (tty); 346 + tty->ldisc.flush_buffer(tty); 348 347 349 - if (tty->driver->flush_buffer) 350 - tty->driver->flush_buffer (tty); 348 + tty_driver_flush_buffer(tty); 351 349 352 350 if (debuglevel >= DEBUG_LEVEL_INFO) 353 351 printk("%s(%d)n_hdlc_tty_open() success\n",__FILE__,__LINE__); ··· 397 399 398 400 /* Send the next block of data to device */ 399 401 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 400 - actual = tty->driver->write(tty, tbuf->buf, tbuf->count); 402 + actual = tty->ops->write(tty, tbuf->buf, tbuf->count); 401 403 402 404 /* rollback was possible and has been done */ 403 405 if (actual == -ERESTARTSYS) { ··· 750 752 751 753 case TIOCOUTQ: 752 754 /* get the pending tx byte count in the driver */ 753 - count = tty->driver->chars_in_buffer ? 754 - tty->driver->chars_in_buffer(tty) : 0; 755 + count = tty_chars_in_buffer(tty); 755 756 /* add size of next output frame in queue */ 756 757 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock,flags); 757 758 if (n_hdlc->tx_buf_list.head)
+7 -10
drivers/char/n_r3964.c
··· 376 376 if (tty == NULL) 377 377 return; 378 378 379 - if (tty->driver->put_char) { 380 - tty->driver->put_char(tty, ch); 379 + /* FIXME: put_char should not be called from an IRQ */ 380 + if (tty->ops->put_char) { 381 + tty->ops->put_char(tty, ch); 381 382 } 382 383 pInfo->bcc ^= ch; 383 384 } ··· 387 386 { 388 387 struct tty_struct *tty = pInfo->tty; 389 388 390 - if (tty == NULL) 389 + if (tty == NULL || tty->ops->flush_chars == NULL) 391 390 return; 392 - 393 - if (tty->driver->flush_chars) { 394 - tty->driver->flush_chars(tty); 395 - } 391 + tty->ops->flush_chars(tty); 396 392 } 397 393 398 394 static void trigger_transmit(struct r3964_info *pInfo) ··· 447 449 struct r3964_block_header *pBlock = pInfo->tx_first; 448 450 int room = 0; 449 451 450 - if ((tty == NULL) || (pBlock == NULL)) { 452 + if (tty == NULL || pBlock == NULL) { 451 453 return; 452 454 } 453 455 454 - if (tty->driver->write_room) 455 - room = tty->driver->write_room(tty); 456 + room = tty_write_room(tty); 456 457 457 458 TRACE_PS("transmit_block %p, room %d, length %d", 458 459 pBlock, room, pBlock->length);
+43 -60
drivers/char/n_tty.c
··· 149 149 { 150 150 if (tty->count && 151 151 test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 152 - tty->driver->unthrottle) 153 - tty->driver->unthrottle(tty); 152 + tty->ops->unthrottle) 153 + tty->ops->unthrottle(tty); 154 154 } 155 155 156 156 /** ··· 273 273 { 274 274 int space, spaces; 275 275 276 - space = tty->driver->write_room(tty); 276 + space = tty_write_room(tty); 277 277 if (!space) 278 278 return -1; 279 279 ··· 286 286 if (O_ONLCR(tty)) { 287 287 if (space < 2) 288 288 return -1; 289 - tty->driver->put_char(tty, '\r'); 289 + tty_put_char(tty, '\r'); 290 290 tty->column = 0; 291 291 } 292 292 tty->canon_column = tty->column; ··· 308 308 if (space < spaces) 309 309 return -1; 310 310 tty->column += spaces; 311 - tty->driver->write(tty, " ", spaces); 311 + tty->ops->write(tty, " ", spaces); 312 312 return 0; 313 313 } 314 314 tty->column += spaces; ··· 325 325 break; 326 326 } 327 327 } 328 - tty->driver->put_char(tty, c); 328 + tty_put_char(tty, c); 329 329 unlock_kernel(); 330 330 return 0; 331 331 } ··· 352 352 int i; 353 353 const unsigned char *cp; 354 354 355 - space = tty->driver->write_room(tty); 355 + space = tty_write_room(tty); 356 356 if (!space) 357 357 return 0; 358 358 if (nr > space) ··· 390 390 } 391 391 } 392 392 break_out: 393 - if (tty->driver->flush_chars) 394 - tty->driver->flush_chars(tty); 395 - i = tty->driver->write(tty, buf, i); 393 + if (tty->ops->flush_chars) 394 + tty->ops->flush_chars(tty); 395 + i = tty->ops->write(tty, buf, i); 396 396 unlock_kernel(); 397 397 return i; 398 398 } 399 399 400 - 401 - /** 402 - * put_char - write character to driver 403 - * @c: character (or part of unicode symbol) 404 - * @tty: terminal device 405 - * 406 - * Queue a byte to the driver layer for output 407 - */ 408 - 409 - static inline void put_char(unsigned char c, struct tty_struct *tty) 410 - { 411 - tty->driver->put_char(tty, c); 412 - } 413 400 414 401 /** 415 402 * echo_char - echo characters ··· 410 423 static void echo_char(unsigned char c, struct tty_struct *tty) 411 424 { 412 425 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') { 413 - put_char('^', tty); 414 - put_char(c ^ 0100, tty); 426 + tty_put_char(tty, '^'); 427 + tty_put_char(tty, c ^ 0100); 415 428 tty->column += 2; 416 429 } else 417 430 opost(c, tty); ··· 420 433 static inline void finish_erasing(struct tty_struct *tty) 421 434 { 422 435 if (tty->erasing) { 423 - put_char('/', tty); 436 + tty_put_char(tty, '/'); 424 437 tty->column++; 425 438 tty->erasing = 0; 426 439 } ··· 504 517 if (L_ECHO(tty)) { 505 518 if (L_ECHOPRT(tty)) { 506 519 if (!tty->erasing) { 507 - put_char('\\', tty); 520 + tty_put_char(tty, '\\'); 508 521 tty->column++; 509 522 tty->erasing = 1; 510 523 } ··· 512 525 echo_char(c, tty); 513 526 while (--cnt > 0) { 514 527 head = (head+1) & (N_TTY_BUF_SIZE-1); 515 - put_char(tty->read_buf[head], tty); 528 + tty_put_char(tty, tty->read_buf[head]); 516 529 } 517 530 } else if (kill_type == ERASE && !L_ECHOE(tty)) { 518 531 echo_char(ERASE_CHAR(tty), tty); ··· 540 553 /* Now backup to that column. */ 541 554 while (tty->column > col) { 542 555 /* Can't use opost here. */ 543 - put_char('\b', tty); 556 + tty_put_char(tty, '\b'); 544 557 if (tty->column > 0) 545 558 tty->column--; 546 559 } 547 560 } else { 548 561 if (iscntrl(c) && L_ECHOCTL(tty)) { 549 - put_char('\b', tty); 550 - put_char(' ', tty); 551 - put_char('\b', tty); 562 + tty_put_char(tty, '\b'); 563 + tty_put_char(tty, ' '); 564 + tty_put_char(tty, '\b'); 552 565 if (tty->column > 0) 553 566 tty->column--; 554 567 } 555 568 if (!iscntrl(c) || L_ECHOCTL(tty)) { 556 - put_char('\b', tty); 557 - put_char(' ', tty); 558 - put_char('\b', tty); 569 + tty_put_char(tty, '\b'); 570 + tty_put_char(tty, ' '); 571 + tty_put_char(tty, '\b'); 559 572 if (tty->column > 0) 560 573 tty->column--; 561 574 } ··· 586 599 kill_pgrp(tty->pgrp, sig, 1); 587 600 if (flush || !L_NOFLSH(tty)) { 588 601 n_tty_flush_buffer(tty); 589 - if (tty->driver->flush_buffer) 590 - tty->driver->flush_buffer(tty); 602 + tty_driver_flush_buffer(tty); 591 603 } 592 604 } 593 605 ··· 718 732 tty->lnext = 0; 719 733 if (L_ECHO(tty)) { 720 734 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 721 - put_char('\a', tty); /* beep if no space */ 735 + tty_put_char(tty, '\a'); /* beep if no space */ 722 736 return; 723 737 } 724 738 /* Record the column of first canon char. */ ··· 762 776 */ 763 777 if (!L_NOFLSH(tty)) { 764 778 n_tty_flush_buffer(tty); 765 - if (tty->driver->flush_buffer) 766 - tty->driver->flush_buffer(tty); 779 + tty_driver_flush_buffer(tty); 767 780 } 768 781 if (L_ECHO(tty)) 769 782 echo_char(c, tty); ··· 791 806 if (L_ECHO(tty)) { 792 807 finish_erasing(tty); 793 808 if (L_ECHOCTL(tty)) { 794 - put_char('^', tty); 795 - put_char('\b', tty); 809 + tty_put_char(tty, '^'); 810 + tty_put_char(tty, '\b'); 796 811 } 797 812 } 798 813 return; ··· 813 828 if (c == '\n') { 814 829 if (L_ECHO(tty) || L_ECHONL(tty)) { 815 830 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) 816 - put_char('\a', tty); 831 + tty_put_char(tty, '\a'); 817 832 opost('\n', tty); 818 833 } 819 834 goto handle_newline; ··· 831 846 */ 832 847 if (L_ECHO(tty)) { 833 848 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) 834 - put_char('\a', tty); 849 + tty_put_char(tty, '\a'); 835 850 /* Record the column of first canon char. */ 836 851 if (tty->canon_head == tty->read_head) 837 852 tty->canon_column = tty->column; ··· 861 876 finish_erasing(tty); 862 877 if (L_ECHO(tty)) { 863 878 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 864 - put_char('\a', tty); /* beep if no space */ 879 + tty_put_char(tty, '\a'); /* beep if no space */ 865 880 return; 866 881 } 867 882 if (c == '\n') ··· 965 980 break; 966 981 } 967 982 } 968 - if (tty->driver->flush_chars) 969 - tty->driver->flush_chars(tty); 983 + if (tty->ops->flush_chars) 984 + tty->ops->flush_chars(tty); 970 985 } 971 986 972 987 n_tty_set_room(tty); ··· 985 1000 if (tty->receive_room < TTY_THRESHOLD_THROTTLE) { 986 1001 /* check TTY_THROTTLED first so it indicates our state */ 987 1002 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 988 - tty->driver->throttle) 989 - tty->driver->throttle(tty); 1003 + tty->ops->throttle) 1004 + tty->ops->throttle(tty); 990 1005 } 991 1006 } 992 1007 ··· 1071 1086 tty->real_raw = 0; 1072 1087 } 1073 1088 n_tty_set_room(tty); 1089 + /* The termios change make the tty ready for I/O */ 1090 + wake_up_interruptible(&tty->write_wait); 1091 + wake_up_interruptible(&tty->read_wait); 1074 1092 } 1075 1093 1076 1094 /** ··· 1501 1513 break; 1502 1514 b++; nr--; 1503 1515 } 1504 - if (tty->driver->flush_chars) 1505 - tty->driver->flush_chars(tty); 1516 + if (tty->ops->flush_chars) 1517 + tty->ops->flush_chars(tty); 1506 1518 } else { 1507 1519 while (nr > 0) { 1508 - c = tty->driver->write(tty, b, nr); 1520 + c = tty->ops->write(tty, b, nr); 1509 1521 if (c < 0) { 1510 1522 retval = c; 1511 1523 goto break_out; ··· 1542 1554 * 1543 1555 * This code must be sure never to sleep through a hangup. 1544 1556 * Called without the kernel lock held - fine 1545 - * 1546 - * FIXME: if someone changes the VMIN or discipline settings for the 1547 - * terminal while another process is in poll() the poll does not 1548 - * recompute the new limits. Possibly set_termios should issue 1549 - * a read wakeup to fix this bug. 1550 1557 */ 1551 1558 1552 1559 static unsigned int normal_poll(struct tty_struct *tty, struct file *file, ··· 1565 1582 else 1566 1583 tty->minimum_to_wake = 1; 1567 1584 } 1568 - if (!tty_is_writelocked(tty) && 1569 - tty->driver->chars_in_buffer(tty) < WAKEUP_CHARS && 1570 - tty->driver->write_room(tty) > 0) 1585 + if (tty->ops->write && !tty_is_writelocked(tty) && 1586 + tty_chars_in_buffer(tty) < WAKEUP_CHARS && 1587 + tty_write_room(tty) > 0) 1571 1588 mask |= POLLOUT | POLLWRNORM; 1572 1589 return mask; 1573 1590 }
+72 -102
drivers/char/tty_io.c
··· 1108 1108 a reference to the old ldisc. If we ended up flipping back 1109 1109 to the existing ldisc we have two references to it */ 1110 1110 1111 - if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) 1112 - tty->driver->set_ldisc(tty); 1111 + if (tty->ldisc.num != o_ldisc.num && tty->ops->set_ldisc) 1112 + tty->ops->set_ldisc(tty); 1113 1113 1114 1114 tty_ldisc_put(o_ldisc.num); 1115 1115 ··· 1181 1181 if (*str == '\0') 1182 1182 str = NULL; 1183 1183 1184 - if (tty_line >= 0 && tty_line <= p->num && p->poll_init && 1185 - !p->poll_init(p, tty_line, str)) { 1186 - 1184 + if (tty_line >= 0 && tty_line <= p->num && p->ops && 1185 + p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { 1187 1186 res = p; 1188 1187 *line = tty_line; 1189 1188 break; ··· 1451 1452 /* We may have no line discipline at this point */ 1452 1453 if (ld->flush_buffer) 1453 1454 ld->flush_buffer(tty); 1454 - if (tty->driver->flush_buffer) 1455 - tty->driver->flush_buffer(tty); 1455 + tty_driver_flush_buffer(tty); 1456 1456 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && 1457 1457 ld->write_wakeup) 1458 1458 ld->write_wakeup(tty); ··· 1514 1516 * So we just call close() the right number of times. 1515 1517 */ 1516 1518 if (cons_filp) { 1517 - if (tty->driver->close) 1519 + if (tty->ops->close) 1518 1520 for (n = 0; n < closecount; n++) 1519 - tty->driver->close(tty, cons_filp); 1520 - } else if (tty->driver->hangup) 1521 - (tty->driver->hangup)(tty); 1521 + tty->ops->close(tty, cons_filp); 1522 + } else if (tty->ops->hangup) 1523 + (tty->ops->hangup)(tty); 1522 1524 /* 1523 1525 * We don't want to have driver/ldisc interactions beyond 1524 1526 * the ones we did here. The driver layer expects no ··· 1750 1752 wake_up_interruptible(&tty->link->read_wait); 1751 1753 } 1752 1754 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 1753 - if (tty->driver->stop) 1754 - (tty->driver->stop)(tty); 1755 + if (tty->ops->stop) 1756 + (tty->ops->stop)(tty); 1755 1757 } 1756 1758 1757 1759 EXPORT_SYMBOL(stop_tty); ··· 1784 1786 wake_up_interruptible(&tty->link->read_wait); 1785 1787 } 1786 1788 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 1787 - if (tty->driver->start) 1788 - (tty->driver->start)(tty); 1789 + if (tty->ops->start) 1790 + (tty->ops->start)(tty); 1789 1791 /* If we have a running line discipline it may need kicking */ 1790 1792 tty_wakeup(tty); 1791 1793 } ··· 1970 1972 tty = (struct tty_struct *)file->private_data; 1971 1973 if (tty_paranoia_check(tty, inode, "tty_write")) 1972 1974 return -EIO; 1973 - if (!tty || !tty->driver->write || 1975 + if (!tty || !tty->ops->write || 1974 1976 (test_bit(TTY_IO_ERROR, &tty->flags))) 1975 1977 return -EIO; 1976 - 1978 + /* Short term debug to catch buggy drivers */ 1979 + if (tty->ops->write_room == NULL) 1980 + printk(KERN_ERR "tty driver %s lacks a write_room method.\n", 1981 + tty->driver->name); 1977 1982 ld = tty_ldisc_ref_wait(tty); 1978 1983 if (!ld->write) 1979 1984 ret = -EIO; ··· 2123 2122 goto fail_no_mem; 2124 2123 initialize_tty_struct(tty); 2125 2124 tty->driver = driver; 2125 + tty->ops = driver->ops; 2126 2126 tty->index = idx; 2127 2127 tty_line_name(driver, idx, tty->name); 2128 2128 ··· 2154 2152 goto free_mem_out; 2155 2153 initialize_tty_struct(o_tty); 2156 2154 o_tty->driver = driver->other; 2155 + o_tty->ops = driver->ops; 2157 2156 o_tty->index = idx; 2158 2157 tty_line_name(driver->other, idx, o_tty->name); 2159 2158 ··· 2459 2456 } 2460 2457 } 2461 2458 #endif 2462 - if (tty->driver->close) 2463 - tty->driver->close(tty, filp); 2459 + if (tty->ops->close) 2460 + tty->ops->close(tty, filp); 2464 2461 2465 2462 /* 2466 2463 * Sanity check: if tty->count is going to zero, there shouldn't be ··· 2743 2740 printk(KERN_DEBUG "opening %s...", tty->name); 2744 2741 #endif 2745 2742 if (!retval) { 2746 - if (tty->driver->open) 2747 - retval = tty->driver->open(tty, filp); 2743 + if (tty->ops->open) 2744 + retval = tty->ops->open(tty, filp); 2748 2745 else 2749 2746 retval = -ENODEV; 2750 2747 } ··· 2843 2840 goto out1; 2844 2841 2845 2842 check_tty_count(tty, "tty_open"); 2846 - retval = ptm_driver->open(tty, filp); 2843 + retval = ptm_driver->ops->open(tty, filp); 2847 2844 if (!retval) 2848 2845 return 0; 2849 2846 out1: ··· 3339 3336 3340 3337 static int send_break(struct tty_struct *tty, unsigned int duration) 3341 3338 { 3342 - int retval = -EINTR; 3343 - 3344 - lock_kernel(); 3345 3339 if (tty_write_lock(tty, 0) < 0) 3346 - goto out; 3347 - tty->driver->break_ctl(tty, -1); 3340 + return -EINTR; 3341 + tty->ops->break_ctl(tty, -1); 3348 3342 if (!signal_pending(current)) 3349 3343 msleep_interruptible(duration); 3350 - tty->driver->break_ctl(tty, 0); 3344 + tty->ops->break_ctl(tty, 0); 3351 3345 tty_write_unlock(tty); 3352 3346 if (!signal_pending(current)) 3353 - retval = 0; 3354 - out: 3355 - unlock_kernel(); 3356 - return retval; 3347 + return -EINTR; 3348 + return 0; 3357 3349 } 3358 3350 3359 3351 /** 3360 - * tiocmget - get modem status 3352 + * tty_tiocmget - get modem status 3361 3353 * @tty: tty device 3362 3354 * @file: user file pointer 3363 3355 * @p: pointer to result ··· 3367 3369 { 3368 3370 int retval = -EINVAL; 3369 3371 3370 - if (tty->driver->tiocmget) { 3371 - lock_kernel(); 3372 - retval = tty->driver->tiocmget(tty, file); 3373 - unlock_kernel(); 3372 + if (tty->ops->tiocmget) { 3373 + retval = tty->ops->tiocmget(tty, file); 3374 3374 3375 3375 if (retval >= 0) 3376 3376 retval = put_user(retval, p); ··· 3377 3381 } 3378 3382 3379 3383 /** 3380 - * tiocmset - set modem status 3384 + * tty_tiocmset - set modem status 3381 3385 * @tty: tty device 3382 3386 * @file: user file pointer 3383 3387 * @cmd: command - clear bits, set bits or set all ··· 3394 3398 { 3395 3399 int retval = -EINVAL; 3396 3400 3397 - if (tty->driver->tiocmset) { 3401 + if (tty->ops->tiocmset) { 3398 3402 unsigned int set, clear, val; 3399 3403 3400 3404 retval = get_user(val, p); ··· 3418 3422 set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; 3419 3423 clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; 3420 3424 3421 - lock_kernel(); 3422 - retval = tty->driver->tiocmset(tty, file, set, clear); 3423 - unlock_kernel(); 3425 + retval = tty->ops->tiocmset(tty, file, set, clear); 3424 3426 } 3425 3427 return retval; 3426 3428 } ··· 3449 3455 3450 3456 retval = -EINVAL; 3451 3457 3452 - if (!tty->driver->break_ctl) { 3458 + if (!tty->ops->break_ctl) { 3453 3459 switch (cmd) { 3454 3460 case TIOCSBRK: 3455 3461 case TIOCCBRK: 3456 - if (tty->driver->ioctl) 3457 - retval = tty->driver->ioctl(tty, file, cmd, arg); 3462 + if (tty->ops->ioctl) 3463 + retval = tty->ops->ioctl(tty, file, cmd, arg); 3464 + if (retval != -EINVAL && retval != -ENOIOCTLCMD) 3465 + printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name); 3458 3466 return retval; 3459 3467 3460 3468 /* These two ioctl's always return success; even if */ 3461 3469 /* the driver doesn't support them. */ 3462 3470 case TCSBRK: 3463 3471 case TCSBRKP: 3464 - if (!tty->driver->ioctl) 3472 + if (!tty->ops->ioctl) 3465 3473 return 0; 3466 - lock_kernel(); 3467 - retval = tty->driver->ioctl(tty, file, cmd, arg); 3468 - unlock_kernel(); 3474 + retval = tty->ops->ioctl(tty, file, cmd, arg); 3475 + if (retval != -EINVAL && retval != -ENOIOCTLCMD) 3476 + printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name); 3469 3477 if (retval == -ENOIOCTLCMD) 3470 3478 retval = 0; 3471 3479 return retval; ··· 3487 3491 if (retval) 3488 3492 return retval; 3489 3493 if (cmd != TIOCCBRK) { 3490 - lock_kernel(); 3491 3494 tty_wait_until_sent(tty, 0); 3492 - unlock_kernel(); 3493 3495 if (signal_pending(current)) 3494 3496 return -EINTR; 3495 3497 } ··· 3525 3531 case TIOCGSID: 3526 3532 return tiocgsid(tty, real_tty, p); 3527 3533 case TIOCGETD: 3528 - /* FIXME: check this is ok */ 3529 3534 return put_user(tty->ldisc.num, (int __user *)p); 3530 3535 case TIOCSETD: 3531 3536 return tiocsetd(tty, p); ··· 3536 3543 * Break handling 3537 3544 */ 3538 3545 case TIOCSBRK: /* Turn break on, unconditionally */ 3539 - lock_kernel(); 3540 - tty->driver->break_ctl(tty, -1); 3541 - unlock_kernel(); 3546 + if (tty->ops->break_ctl) 3547 + tty->ops->break_ctl(tty, -1); 3542 3548 return 0; 3543 3549 3544 3550 case TIOCCBRK: /* Turn break off, unconditionally */ 3545 - lock_kernel(); 3546 - tty->driver->break_ctl(tty, 0); 3547 - unlock_kernel(); 3551 + if (tty->ops->break_ctl) 3552 + tty->ops->break_ctl(tty, 0); 3548 3553 return 0; 3549 3554 case TCSBRK: /* SVID version: non-zero arg --> no break */ 3550 3555 /* non-zero arg means wait for all output data ··· 3571 3580 } 3572 3581 break; 3573 3582 } 3574 - if (tty->driver->ioctl) { 3575 - retval = (tty->driver->ioctl)(tty, file, cmd, arg); 3583 + if (tty->ops->ioctl) { 3584 + retval = (tty->ops->ioctl)(tty, file, cmd, arg); 3576 3585 if (retval != -ENOIOCTLCMD) 3577 3586 return retval; 3578 3587 } ··· 3599 3608 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3600 3609 return -EINVAL; 3601 3610 3602 - if (tty->driver->compat_ioctl) { 3603 - retval = (tty->driver->compat_ioctl)(tty, file, cmd, arg); 3611 + if (tty->ops->compat_ioctl) { 3612 + retval = (tty->ops->compat_ioctl)(tty, file, cmd, arg); 3604 3613 if (retval != -ENOIOCTLCMD) 3605 3614 return retval; 3606 3615 } ··· 3650 3659 3651 3660 tty_ldisc_flush(tty); 3652 3661 3653 - if (tty->driver->flush_buffer) 3654 - tty->driver->flush_buffer(tty); 3662 + tty_driver_flush_buffer(tty); 3655 3663 3656 3664 read_lock(&tasklist_lock); 3657 3665 /* Kill the entire session */ ··· 3861 3871 INIT_WORK(&tty->SAK_work, do_SAK_work); 3862 3872 } 3863 3873 3864 - /* 3865 - * The default put_char routine if the driver did not define one. 3874 + /** 3875 + * tty_put_char - write one character to a tty 3876 + * @tty: tty 3877 + * @ch: character 3878 + * 3879 + * Write one byte to the tty using the provided put_char method 3880 + * if present. Returns the number of characters successfully output. 3881 + * 3882 + * Note: the specific put_char operation in the driver layer may go 3883 + * away soon. Don't call it directly, use this method 3866 3884 */ 3867 3885 3868 - static void tty_default_put_char(struct tty_struct *tty, unsigned char ch) 3886 + int tty_put_char(struct tty_struct *tty, unsigned char ch) 3869 3887 { 3870 - tty->driver->write(tty, &ch, 1); 3888 + if (tty->ops->put_char) 3889 + return tty->ops->put_char(tty, ch); 3890 + return tty->ops->write(tty, &ch, 1); 3871 3891 } 3892 + 3893 + EXPORT_SYMBOL_GPL(tty_put_char); 3872 3894 3873 3895 static struct class *tty_class; 3874 3896 ··· 3964 3962 void tty_set_operations(struct tty_driver *driver, 3965 3963 const struct tty_operations *op) 3966 3964 { 3967 - driver->open = op->open; 3968 - driver->close = op->close; 3969 - driver->write = op->write; 3970 - driver->put_char = op->put_char; 3971 - driver->flush_chars = op->flush_chars; 3972 - driver->write_room = op->write_room; 3973 - driver->chars_in_buffer = op->chars_in_buffer; 3974 - driver->ioctl = op->ioctl; 3975 - driver->compat_ioctl = op->compat_ioctl; 3976 - driver->set_termios = op->set_termios; 3977 - driver->throttle = op->throttle; 3978 - driver->unthrottle = op->unthrottle; 3979 - driver->stop = op->stop; 3980 - driver->start = op->start; 3981 - driver->hangup = op->hangup; 3982 - driver->break_ctl = op->break_ctl; 3983 - driver->flush_buffer = op->flush_buffer; 3984 - driver->set_ldisc = op->set_ldisc; 3985 - driver->wait_until_sent = op->wait_until_sent; 3986 - driver->send_xchar = op->send_xchar; 3987 - driver->read_proc = op->read_proc; 3988 - driver->write_proc = op->write_proc; 3989 - driver->tiocmget = op->tiocmget; 3990 - driver->tiocmset = op->tiocmset; 3991 - #ifdef CONFIG_CONSOLE_POLL 3992 - driver->poll_init = op->poll_init; 3993 - driver->poll_get_char = op->poll_get_char; 3994 - driver->poll_put_char = op->poll_put_char; 3995 - #endif 3996 - } 3997 - 3965 + driver->ops = op; 3966 + }; 3998 3967 3999 3968 EXPORT_SYMBOL(alloc_tty_driver); 4000 3969 EXPORT_SYMBOL(put_tty_driver); ··· 4027 4054 kfree(p); 4028 4055 return error; 4029 4056 } 4030 - 4031 - if (!driver->put_char) 4032 - driver->put_char = tty_default_put_char; 4033 4057 4034 4058 mutex_lock(&tty_mutex); 4035 4059 list_add(&driver->tty_drivers, &tty_drivers);
+42 -20
drivers/char/tty_ioctl.c
··· 40 40 #define TERMIOS_OLD 8 41 41 42 42 43 + int tty_chars_in_buffer(struct tty_struct *tty) 44 + { 45 + if (tty->ops->chars_in_buffer) 46 + return tty->ops->chars_in_buffer(tty); 47 + else 48 + return 0; 49 + } 50 + 51 + EXPORT_SYMBOL(tty_chars_in_buffer); 52 + 53 + int tty_write_room(struct tty_struct *tty) 54 + { 55 + if (tty->ops->write_room) 56 + return tty->ops->write_room(tty); 57 + return 2048; 58 + } 59 + 60 + EXPORT_SYMBOL(tty_write_room); 61 + 62 + void tty_driver_flush_buffer(struct tty_struct *tty) 63 + { 64 + if (tty->ops->flush_buffer) 65 + tty->ops->flush_buffer(tty); 66 + } 67 + 68 + EXPORT_SYMBOL(tty_driver_flush_buffer); 69 + 70 + 43 71 /** 44 72 * tty_wait_until_sent - wait for I/O to finish 45 73 * @tty: tty we are waiting for ··· 86 58 87 59 printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf)); 88 60 #endif 89 - if (!tty->driver->chars_in_buffer) 90 - return; 91 61 if (!timeout) 92 62 timeout = MAX_SCHEDULE_TIMEOUT; 93 - lock_kernel(); 94 63 if (wait_event_interruptible_timeout(tty->write_wait, 95 - !tty->driver->chars_in_buffer(tty), timeout) >= 0) { 96 - if (tty->driver->wait_until_sent) 97 - tty->driver->wait_until_sent(tty, timeout); 64 + !tty_chars_in_buffer(tty), timeout) >= 0) { 65 + if (tty->ops->wait_until_sent) 66 + tty->ops->wait_until_sent(tty, timeout); 98 67 } 99 - unlock_kernel(); 100 68 } 101 69 EXPORT_SYMBOL(tty_wait_until_sent); 102 70 ··· 468 444 } 469 445 } 470 446 471 - if (tty->driver->set_termios) 472 - (*tty->driver->set_termios)(tty, &old_termios); 447 + if (tty->ops->set_termios) 448 + (*tty->ops->set_termios)(tty, &old_termios); 473 449 else 474 450 tty_termios_copy_hw(tty->termios, &old_termios); 475 451 ··· 772 748 { 773 749 int was_stopped = tty->stopped; 774 750 775 - if (tty->driver->send_xchar) { 776 - tty->driver->send_xchar(tty, ch); 751 + if (tty->ops->send_xchar) { 752 + tty->ops->send_xchar(tty, ch); 777 753 return 0; 778 754 } 779 755 ··· 782 758 783 759 if (was_stopped) 784 760 start_tty(tty); 785 - tty->driver->write(tty, &ch, 1); 761 + tty->ops->write(tty, &ch, 1); 786 762 if (was_stopped) 787 763 stop_tty(tty); 788 764 tty_write_unlock(tty); ··· 802 778 { 803 779 int ret = 0; 804 780 int bit = arg ? CLOCAL : 0; 805 - struct ktermios old = *tty->termios; 781 + struct ktermios old; 806 782 807 783 mutex_lock(&tty->termios_mutex); 784 + old = *tty->termios; 808 785 tty->termios->c_cflag &= ~CLOCAL; 809 786 tty->termios->c_cflag |= bit; 810 - if (tty->driver->set_termios) 811 - tty->driver->set_termios(tty, &old); 787 + if (tty->ops->set_termios) 788 + tty->ops->set_termios(tty, &old); 812 789 if ((tty->termios->c_cflag & CLOCAL) != bit) 813 790 ret = -EINVAL; 814 791 mutex_unlock(&tty->termios_mutex); ··· 951 926 ld->flush_buffer(tty); 952 927 /* fall through */ 953 928 case TCOFLUSH: 954 - if (tty->driver->flush_buffer) 955 - tty->driver->flush_buffer(tty); 929 + tty_driver_flush_buffer(tty); 956 930 break; 957 931 default: 958 932 tty_ldisc_deref(ld); ··· 1008 984 case TCFLSH: 1009 985 return tty_perform_flush(tty, arg); 1010 986 case TIOCOUTQ: 1011 - return put_user(tty->driver->chars_in_buffer ? 1012 - tty->driver->chars_in_buffer(tty) : 0, 1013 - (int __user *) arg); 987 + return put_user(tty_chars_in_buffer(tty), (int __user *) arg); 1014 988 case TIOCINQ: 1015 989 retval = tty->read_cnt; 1016 990 if (L_ICANON(tty))
+1 -1
drivers/input/serio/serport.c
··· 46 46 static int serport_serio_write(struct serio *serio, unsigned char data) 47 47 { 48 48 struct serport *serport = serio->port_data; 49 - return -(serport->tty->driver->write(serport->tty, &data, 1) != 1); 49 + return -(serport->tty->ops->write(serport->tty, &data, 1) != 1); 50 50 } 51 51 52 52 static int serport_serio_open(struct serio *serio)
+8 -7
drivers/isdn/gigaset/ser-gigaset.c
··· 68 68 struct tty_struct *tty = cs->hw.ser->tty; 69 69 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ 70 70 struct sk_buff *skb = bcs->tx_skb; 71 - int sent; 71 + int sent = -EOPNOTSUPP; 72 72 73 73 if (!tty || !tty->driver || !skb) 74 - return -EFAULT; 74 + return -EINVAL; 75 75 76 76 if (!skb->len) { 77 77 dev_kfree_skb_any(skb); ··· 80 80 } 81 81 82 82 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 83 - sent = tty->driver->write(tty, skb->data, skb->len); 83 + if (tty->ops->write) 84 + sent = tty->ops->write(tty, skb->data, skb->len); 84 85 gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent); 85 86 if (sent < 0) { 86 87 /* error */ ··· 121 120 122 121 if (cb->len) { 123 122 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 124 - sent = tty->driver->write(tty, cb->buf + cb->offset, cb->len); 123 + sent = tty->ops->write(tty, cb->buf + cb->offset, cb->len); 125 124 if (sent < 0) { 126 125 /* error */ 127 126 gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent); ··· 441 440 struct tty_struct *tty = cs->hw.ser->tty; 442 441 unsigned int set, clear; 443 442 444 - if (!tty || !tty->driver || !tty->driver->tiocmset) 445 - return -EFAULT; 443 + if (!tty || !tty->driver || !tty->ops->tiocmset) 444 + return -EINVAL; 446 445 set = new_state & ~old_state; 447 446 clear = old_state & ~new_state; 448 447 if (!set && !clear) 449 448 return 0; 450 449 gig_dbg(DEBUG_IF, "tiocmset set %x clear %x", set, clear); 451 - return tty->driver->tiocmset(tty, NULL, set, clear); 450 + return tty->ops->tiocmset(tty, NULL, set, clear); 452 451 } 453 452 454 453 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
+19 -17
drivers/net/hamradio/6pack.c
··· 148 148 149 149 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) { 150 150 sp->led_state = 0x70; 151 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 151 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 152 152 sp->tx_enable = 1; 153 - actual = sp->tty->driver->write(sp->tty, sp->xbuff, sp->status2); 153 + actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); 154 154 sp->xleft -= actual; 155 155 sp->xhead += actual; 156 156 sp->led_state = 0x60; 157 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 157 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 158 158 sp->status2 = 0; 159 159 } else 160 160 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100); ··· 220 220 */ 221 221 if (sp->duplex == 1) { 222 222 sp->led_state = 0x70; 223 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 223 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 224 224 sp->tx_enable = 1; 225 - actual = sp->tty->driver->write(sp->tty, sp->xbuff, count); 225 + actual = sp->tty->ops->write(sp->tty, sp->xbuff, count); 226 226 sp->xleft = count - actual; 227 227 sp->xhead = sp->xbuff + actual; 228 228 sp->led_state = 0x60; 229 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 229 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 230 230 } else { 231 231 sp->xleft = count; 232 232 sp->xhead = sp->xbuff; ··· 444 444 } 445 445 446 446 if (sp->tx_enable) { 447 - actual = tty->driver->write(tty, sp->xhead, sp->xleft); 447 + actual = tty->ops->write(tty, sp->xhead, sp->xleft); 448 448 sp->xleft -= actual; 449 449 sp->xhead += actual; 450 450 } ··· 492 492 493 493 sp_put(sp); 494 494 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 495 - && tty->driver->unthrottle) 496 - tty->driver->unthrottle(tty); 495 + && tty->ops->unthrottle) 496 + tty->ops->unthrottle(tty); 497 497 } 498 498 499 499 /* ··· 554 554 /* resync the TNC */ 555 555 556 556 sp->led_state = 0x60; 557 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 558 - sp->tty->driver->write(sp->tty, &resync_cmd, 1); 557 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 558 + sp->tty->ops->write(sp->tty, &resync_cmd, 1); 559 559 560 560 561 561 /* Start resync timer again -- the TNC might be still absent */ ··· 573 573 574 574 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP); 575 575 576 - sp->tty->driver->write(sp->tty, &inbyte, 1); 576 + sp->tty->ops->write(sp->tty, &inbyte, 1); 577 577 578 578 del_timer(&sp->resync_t); 579 579 sp->resync_t.data = (unsigned long) sp; ··· 601 601 602 602 if (!capable(CAP_NET_ADMIN)) 603 603 return -EPERM; 604 + if (tty->ops->write == NULL) 605 + return -EOPNOTSUPP; 604 606 605 607 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", sp_setup); 606 608 if (!dev) { ··· 916 914 } else { /* output watchdog char if idle */ 917 915 if ((sp->status2 != 0) && (sp->duplex == 1)) { 918 916 sp->led_state = 0x70; 919 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 917 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 920 918 sp->tx_enable = 1; 921 - actual = sp->tty->driver->write(sp->tty, sp->xbuff, sp->status2); 919 + actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2); 922 920 sp->xleft -= actual; 923 921 sp->xhead += actual; 924 922 sp->led_state = 0x60; ··· 928 926 } 929 927 930 928 /* needed to trigger the TNC watchdog */ 931 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 929 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 932 930 933 931 /* if the state byte has been received, the TNC is present, 934 932 so the resync timer can be reset. */ ··· 958 956 if ((sp->status & SIXP_RX_DCD_MASK) == 959 957 SIXP_RX_DCD_MASK) { 960 958 sp->led_state = 0x68; 961 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 959 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 962 960 } 963 961 } else { 964 962 sp->led_state = 0x60; 965 963 /* fill trailing bytes with zeroes */ 966 - sp->tty->driver->write(sp->tty, &sp->led_state, 1); 964 + sp->tty->ops->write(sp->tty, &sp->led_state, 1); 967 965 rest = sp->rx_count; 968 966 if (rest != 0) 969 967 for (i = rest; i <= 3; i++)
+8 -7
drivers/net/hamradio/mkiss.c
··· 516 516 spin_unlock_bh(&ax->buflock); 517 517 518 518 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); 519 - actual = ax->tty->driver->write(ax->tty, ax->xbuff, count); 519 + actual = ax->tty->ops->write(ax->tty, ax->xbuff, count); 520 520 ax->stats.tx_packets++; 521 521 ax->stats.tx_bytes += actual; 522 522 ··· 546 546 } 547 547 548 548 printk(KERN_ERR "mkiss: %s: transmit timed out, %s?\n", dev->name, 549 - (ax->tty->driver->chars_in_buffer(ax->tty) || ax->xleft) ? 549 + (ax->tty->ops->chars_in_buffer(ax->tty) || ax->xleft) ? 550 550 "bad line quality" : "driver error"); 551 551 552 552 ax->xleft = 0; ··· 736 736 737 737 if (!capable(CAP_NET_ADMIN)) 738 738 return -EPERM; 739 + if (tty->ops->write == NULL) 740 + return -EOPNOTSUPP; 739 741 740 742 dev = alloc_netdev(sizeof(struct mkiss), "ax%d", ax_setup); 741 743 if (!dev) { ··· 756 754 tty->disc_data = ax; 757 755 tty->receive_room = 65535; 758 756 759 - if (tty->driver->flush_buffer) 760 - tty->driver->flush_buffer(tty); 757 + tty_driver_flush_buffer(tty); 761 758 762 759 /* Restore default settings */ 763 760 dev->type = ARPHRD_AX25; ··· 937 936 938 937 mkiss_put(ax); 939 938 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 940 - && tty->driver->unthrottle) 941 - tty->driver->unthrottle(tty); 939 + && tty->ops->unthrottle) 940 + tty->ops->unthrottle(tty); 942 941 } 943 942 944 943 /* ··· 963 962 goto out; 964 963 } 965 964 966 - actual = tty->driver->write(tty, ax->xhead, ax->xleft); 965 + actual = tty->ops->write(tty, ax->xhead, ax->xleft); 967 966 ax->xleft -= actual; 968 967 ax->xhead += actual; 969 968
+27 -68
drivers/net/irda/irtty-sir.c
··· 64 64 IRDA_ASSERT(priv != NULL, return -1;); 65 65 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); 66 66 67 - return priv->tty->driver->chars_in_buffer(priv->tty); 67 + return tty_chars_in_buffer(priv->tty); 68 68 } 69 69 70 70 /* Wait (sleep) until underlaying hardware finished transmission ··· 93 93 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); 94 94 95 95 tty = priv->tty; 96 - if (tty->driver->wait_until_sent) { 97 - lock_kernel(); 98 - tty->driver->wait_until_sent(tty, msecs_to_jiffies(100)); 99 - unlock_kernel(); 96 + if (tty->ops->wait_until_sent) { 97 + tty->ops->wait_until_sent(tty, msecs_to_jiffies(100)); 100 98 } 101 99 else { 102 100 msleep(USBSERIAL_TX_DONE_DELAY); ··· 123 125 124 126 tty = priv->tty; 125 127 126 - lock_kernel(); 128 + mutex_lock(&tty->termios_mutex); 127 129 old_termios = *(tty->termios); 128 130 cflag = tty->termios->c_cflag; 129 - 130 - cflag &= ~CBAUD; 131 - 132 - IRDA_DEBUG(2, "%s(), Setting speed to %d\n", __FUNCTION__, speed); 133 - 134 - switch (speed) { 135 - case 1200: 136 - cflag |= B1200; 137 - break; 138 - case 2400: 139 - cflag |= B2400; 140 - break; 141 - case 4800: 142 - cflag |= B4800; 143 - break; 144 - case 19200: 145 - cflag |= B19200; 146 - break; 147 - case 38400: 148 - cflag |= B38400; 149 - break; 150 - case 57600: 151 - cflag |= B57600; 152 - break; 153 - case 115200: 154 - cflag |= B115200; 155 - break; 156 - case 9600: 157 - default: 158 - cflag |= B9600; 159 - break; 160 - } 161 - 162 - tty->termios->c_cflag = cflag; 163 - if (tty->driver->set_termios) 164 - tty->driver->set_termios(tty, &old_termios); 165 - unlock_kernel(); 166 - 131 + tty_encode_baud_rate(tty, speed, speed); 132 + if (tty->ops->set_termios) 133 + tty->ops->set_termios(tty, &old_termios); 167 134 priv->io.speed = speed; 135 + mutex_unlock(&tty->termios_mutex); 168 136 169 137 return 0; 170 138 } ··· 166 202 * This function is not yet defined for all tty driver, so 167 203 * let's be careful... Jean II 168 204 */ 169 - IRDA_ASSERT(priv->tty->driver->tiocmset != NULL, return -1;); 170 - priv->tty->driver->tiocmset(priv->tty, NULL, set, clear); 205 + IRDA_ASSERT(priv->tty->ops->tiocmset != NULL, return -1;); 206 + priv->tty->ops->tiocmset(priv->tty, NULL, set, clear); 171 207 172 208 return 0; 173 209 } ··· 189 225 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); 190 226 191 227 tty = priv->tty; 192 - if (!tty->driver->write) 228 + if (!tty->ops->write) 193 229 return 0; 194 230 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 195 - if (tty->driver->write_room) { 196 - writelen = tty->driver->write_room(tty); 197 - if (writelen > len) 198 - writelen = len; 199 - } 200 - else 231 + writelen = tty_write_room(tty); 232 + if (writelen > len) 201 233 writelen = len; 202 - return tty->driver->write(tty, ptr, writelen); 234 + return tty->ops->write(tty, ptr, writelen); 203 235 } 204 236 205 237 /* ------------------------------------------------------- */ ··· 281 321 struct ktermios old_termios; 282 322 int cflag; 283 323 284 - lock_kernel(); 324 + mutex_lock(&tty->termios_mutex); 285 325 old_termios = *(tty->termios); 286 326 cflag = tty->termios->c_cflag; 287 327 ··· 291 331 cflag |= CREAD; 292 332 293 333 tty->termios->c_cflag = cflag; 294 - if (tty->driver->set_termios) 295 - tty->driver->set_termios(tty, &old_termios); 296 - unlock_kernel(); 334 + if (tty->ops->set_termios) 335 + tty->ops->set_termios(tty, &old_termios); 336 + mutex_unlock(&tty->termios_mutex); 297 337 } 298 338 299 339 /*****************************************************************/ ··· 319 359 320 360 tty = priv->tty; 321 361 322 - if (tty->driver->start) 323 - tty->driver->start(tty); 362 + if (tty->ops->start) 363 + tty->ops->start(tty); 324 364 /* Make sure we can receive more data */ 325 365 irtty_stop_receiver(tty, FALSE); 326 366 ··· 348 388 349 389 /* Make sure we don't receive more data */ 350 390 irtty_stop_receiver(tty, TRUE); 351 - if (tty->driver->stop) 352 - tty->driver->stop(tty); 391 + if (tty->ops->stop) 392 + tty->ops->stop(tty); 353 393 354 394 mutex_unlock(&irtty_mutex); 355 395 ··· 443 483 444 484 /* stop the underlying driver */ 445 485 irtty_stop_receiver(tty, TRUE); 446 - if (tty->driver->stop) 447 - tty->driver->stop(tty); 486 + if (tty->ops->stop) 487 + tty->ops->stop(tty); 448 488 449 - if (tty->driver->flush_buffer) 450 - tty->driver->flush_buffer(tty); 489 + tty_driver_flush_buffer(tty); 451 490 452 491 /* apply mtt override */ 453 492 sir_tty_drv.qos_mtt_bits = qos_mtt_bits; ··· 523 564 /* Stop tty */ 524 565 irtty_stop_receiver(tty, TRUE); 525 566 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 526 - if (tty->driver->stop) 527 - tty->driver->stop(tty); 567 + if (tty->ops->stop) 568 + tty->ops->stop(tty); 528 569 529 570 kfree(priv); 530 571
+6 -3
drivers/net/ppp_async.c
··· 158 158 struct asyncppp *ap; 159 159 int err; 160 160 161 + if (tty->ops->write == NULL) 162 + return -EOPNOTSUPP; 163 + 161 164 err = -ENOMEM; 162 165 ap = kzalloc(sizeof(*ap), GFP_KERNEL); 163 166 if (!ap) ··· 362 359 tasklet_schedule(&ap->tsk); 363 360 ap_put(ap); 364 361 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 365 - && tty->driver->unthrottle) 366 - tty->driver->unthrottle(tty); 362 + && tty->ops->unthrottle) 363 + tty->ops->unthrottle(tty); 367 364 } 368 365 369 366 static void ··· 679 676 if (!tty_stuffed && ap->optr < ap->olim) { 680 677 avail = ap->olim - ap->optr; 681 678 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 682 - sent = tty->driver->write(tty, ap->optr, avail); 679 + sent = tty->ops->write(tty, ap->optr, avail); 683 680 if (sent < 0) 684 681 goto flush; /* error, e.g. loss of CD */ 685 682 ap->optr += sent;
+6 -3
drivers/net/ppp_synctty.c
··· 207 207 struct syncppp *ap; 208 208 int err; 209 209 210 + if (tty->ops->write == NULL) 211 + return -EOPNOTSUPP; 212 + 210 213 ap = kzalloc(sizeof(*ap), GFP_KERNEL); 211 214 err = -ENOMEM; 212 215 if (!ap) ··· 402 399 tasklet_schedule(&ap->tsk); 403 400 sp_put(ap); 404 401 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 405 - && tty->driver->unthrottle) 406 - tty->driver->unthrottle(tty); 402 + && tty->ops->unthrottle) 403 + tty->ops->unthrottle(tty); 407 404 } 408 405 409 406 static void ··· 656 653 tty_stuffed = 0; 657 654 if (!tty_stuffed && ap->tpkt) { 658 655 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 659 - sent = tty->driver->write(tty, ap->tpkt->data, ap->tpkt->len); 656 + sent = tty->ops->write(tty, ap->tpkt->data, ap->tpkt->len); 660 657 if (sent < 0) 661 658 goto flush; /* error, e.g. loss of CD */ 662 659 if (sent < ap->tpkt->len) {
+8 -5
drivers/net/slip.c
··· 396 396 397 397 /* Order of next two lines is *very* important. 398 398 * When we are sending a little amount of data, 399 - * the transfer may be completed inside driver.write() 399 + * the transfer may be completed inside the ops->write() 400 400 * routine, because it's running with interrupts enabled. 401 401 * In this case we *never* got WRITE_WAKEUP event, 402 402 * if we did not request it before write operation. 403 403 * 14 Oct 1994 Dmitry Gorodchanin. 404 404 */ 405 405 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 406 - actual = sl->tty->driver->write(sl->tty, sl->xbuff, count); 406 + actual = sl->tty->ops->write(sl->tty, sl->xbuff, count); 407 407 #ifdef SL_CHECK_TRANSMIT 408 408 sl->dev->trans_start = jiffies; 409 409 #endif ··· 437 437 return; 438 438 } 439 439 440 - actual = tty->driver->write(tty, sl->xhead, sl->xleft); 440 + actual = tty->ops->write(tty, sl->xhead, sl->xleft); 441 441 sl->xleft -= actual; 442 442 sl->xhead += actual; 443 443 } ··· 462 462 } 463 463 printk(KERN_WARNING "%s: transmit timed out, %s?\n", 464 464 dev->name, 465 - (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? 465 + (tty_chars_in_buffer(sl->tty) || sl->xleft) ? 466 466 "bad line quality" : "driver error"); 467 467 sl->xleft = 0; 468 468 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); ··· 829 829 830 830 if (!capable(CAP_NET_ADMIN)) 831 831 return -EPERM; 832 + 833 + if (tty->ops->write == NULL) 834 + return -EOPNOTSUPP; 832 835 833 836 /* RTnetlink lock is misused here to serialize concurrent 834 837 opens of slip channels. There are better ways, but it is ··· 1435 1432 /* put END into tty queue. Is it right ??? */ 1436 1433 if (!netif_queue_stopped(sl->dev)) { 1437 1434 /* if device busy no outfill */ 1438 - sl->tty->driver->write(sl->tty, &s, 1); 1435 + sl->tty->ops->write(sl->tty, &s, 1); 1439 1436 } 1440 1437 } else 1441 1438 set_bit(SLF_OUTWAIT, &sl->flags);
+135 -144
drivers/net/wan/x25_asy.c
··· 17 17 #include <linux/module.h> 18 18 19 19 #include <asm/system.h> 20 - #include <asm/uaccess.h> 20 + #include <linux/uaccess.h> 21 21 #include <linux/bitops.h> 22 22 #include <linux/string.h> 23 23 #include <linux/mm.h> ··· 95 95 x25_asy_devs[i] = dev; 96 96 return sl; 97 97 } else { 98 - printk("x25_asy_alloc() - register_netdev() failure.\n"); 98 + printk(KERN_WARNING "x25_asy_alloc() - register_netdev() failure.\n"); 99 99 free_netdev(dev); 100 100 } 101 101 } ··· 112 112 kfree(sl->xbuff); 113 113 sl->xbuff = NULL; 114 114 115 - if (!test_and_clear_bit(SLF_INUSE, &sl->flags)) { 116 - printk("%s: x25_asy_free for already free unit.\n", sl->dev->name); 117 - } 115 + if (!test_and_clear_bit(SLF_INUSE, &sl->flags)) 116 + printk(KERN_ERR "%s: x25_asy_free for already free unit.\n", 117 + sl->dev->name); 118 118 } 119 119 120 120 static int x25_asy_change_mtu(struct net_device *dev, int newmtu) 121 121 { 122 122 struct x25_asy *sl = dev->priv; 123 123 unsigned char *xbuff, *rbuff; 124 - int len = 2* newmtu; 124 + int len = 2 * newmtu; 125 125 126 126 xbuff = kmalloc(len + 4, GFP_ATOMIC); 127 127 rbuff = kmalloc(len + 4, GFP_ATOMIC); 128 128 129 - if (xbuff == NULL || rbuff == NULL) 130 - { 131 - printk("%s: unable to grow X.25 buffers, MTU change cancelled.\n", 129 + if (xbuff == NULL || rbuff == NULL) { 130 + printk(KERN_WARNING "%s: unable to grow X.25 buffers, MTU change cancelled.\n", 132 131 dev->name); 133 132 kfree(xbuff); 134 133 kfree(rbuff); ··· 192 193 int err; 193 194 194 195 count = sl->rcount; 195 - sl->stats.rx_bytes+=count; 196 - 196 + sl->stats.rx_bytes += count; 197 + 197 198 skb = dev_alloc_skb(count+1); 198 - if (skb == NULL) 199 - { 200 - printk("%s: memory squeeze, dropping packet.\n", sl->dev->name); 199 + if (skb == NULL) { 200 + printk(KERN_WARNING "%s: memory squeeze, dropping packet.\n", 201 + sl->dev->name); 201 202 sl->stats.rx_dropped++; 202 203 return; 203 204 } 204 - skb_push(skb,1); /* LAPB internal control */ 205 - memcpy(skb_put(skb,count), sl->rbuff, count); 205 + skb_push(skb, 1); /* LAPB internal control */ 206 + memcpy(skb_put(skb, count), sl->rbuff, count); 206 207 skb->protocol = x25_type_trans(skb, sl->dev); 207 - if((err=lapb_data_received(skb->dev, skb))!=LAPB_OK) 208 - { 208 + err = lapb_data_received(skb->dev, skb); 209 + if (err != LAPB_OK) { 209 210 kfree_skb(skb); 210 - printk(KERN_DEBUG "x25_asy: data received err - %d\n",err); 211 - } 212 - else 213 - { 211 + printk(KERN_DEBUG "x25_asy: data received err - %d\n", err); 212 + } else { 214 213 netif_rx(skb); 215 214 sl->dev->last_rx = jiffies; 216 215 sl->stats.rx_packets++; ··· 221 224 unsigned char *p; 222 225 int actual, count, mtu = sl->dev->mtu; 223 226 224 - if (len > mtu) 225 - { /* Sigh, shouldn't occur BUT ... */ 227 + if (len > mtu) { 228 + /* Sigh, shouldn't occur BUT ... */ 226 229 len = mtu; 227 - printk ("%s: truncating oversized transmit packet!\n", sl->dev->name); 230 + printk(KERN_DEBUG "%s: truncating oversized transmit packet!\n", 231 + sl->dev->name); 228 232 sl->stats.tx_dropped++; 229 233 x25_asy_unlock(sl); 230 234 return; ··· 243 245 * 14 Oct 1994 Dmitry Gorodchanin. 244 246 */ 245 247 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 246 - actual = sl->tty->driver->write(sl->tty, sl->xbuff, count); 248 + actual = sl->tty->ops->write(sl->tty, sl->xbuff, count); 247 249 sl->xleft = count - actual; 248 250 sl->xhead = sl->xbuff + actual; 249 251 /* VSV */ ··· 263 265 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev)) 264 266 return; 265 267 266 - if (sl->xleft <= 0) 267 - { 268 + if (sl->xleft <= 0) { 268 269 /* Now serial buffer is almost free & we can start 269 270 * transmission of another packet */ 270 271 sl->stats.tx_packets++; ··· 272 275 return; 273 276 } 274 277 275 - actual = tty->driver->write(tty, sl->xhead, sl->xleft); 278 + actual = tty->ops->write(tty, sl->xhead, sl->xleft); 276 279 sl->xleft -= actual; 277 280 sl->xhead += actual; 278 281 } 279 282 280 283 static void x25_asy_timeout(struct net_device *dev) 281 284 { 282 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 285 + struct x25_asy *sl = dev->priv; 283 286 284 287 spin_lock(&sl->lock); 285 288 if (netif_queue_stopped(dev)) { ··· 287 290 * 14 Oct 1994 Dmitry Gorodchanin. 288 291 */ 289 292 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, 290 - (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? 293 + (tty_chars_in_buffer(sl->tty) || sl->xleft) ? 291 294 "bad line quality" : "driver error"); 292 295 sl->xleft = 0; 293 296 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); ··· 300 303 301 304 static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev) 302 305 { 303 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 306 + struct x25_asy *sl = dev->priv; 304 307 int err; 305 308 306 309 if (!netif_running(sl->dev)) { 307 - printk("%s: xmit call when iface is down\n", dev->name); 310 + printk(KERN_ERR "%s: xmit call when iface is down\n", 311 + dev->name); 308 312 kfree_skb(skb); 309 313 return 0; 310 314 } 311 - 312 - switch(skb->data[0]) 313 - { 314 - case 0x00:break; 315 - case 0x01: /* Connection request .. do nothing */ 316 - if((err=lapb_connect_request(dev))!=LAPB_OK) 317 - printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err); 318 - kfree_skb(skb); 319 - return 0; 320 - case 0x02: /* Disconnect request .. do nothing - hang up ?? */ 321 - if((err=lapb_disconnect_request(dev))!=LAPB_OK) 322 - printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err); 323 - default: 324 - kfree_skb(skb); 325 - return 0; 315 + 316 + switch (skb->data[0]) { 317 + case 0x00: 318 + break; 319 + case 0x01: /* Connection request .. do nothing */ 320 + err = lapb_connect_request(dev); 321 + if (err != LAPB_OK) 322 + printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err); 323 + kfree_skb(skb); 324 + return 0; 325 + case 0x02: /* Disconnect request .. do nothing - hang up ?? */ 326 + err = lapb_disconnect_request(dev); 327 + if (err != LAPB_OK) 328 + printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err); 329 + default: 330 + kfree_skb(skb); 331 + return 0; 326 332 } 327 - skb_pull(skb,1); /* Remove control byte */ 333 + skb_pull(skb, 1); /* Remove control byte */ 328 334 /* 329 335 * If we are busy already- too bad. We ought to be able 330 336 * to queue things at this point, to allow for a little ··· 338 338 * So, no queues ! 339 339 * 14 Oct 1994 Dmitry Gorodchanin. 340 340 */ 341 - 342 - if((err=lapb_data_request(dev,skb))!=LAPB_OK) 343 - { 344 - printk(KERN_ERR "lapbeth: lapb_data_request error - %d\n", err); 341 + 342 + err = lapb_data_request(dev, skb); 343 + if (err != LAPB_OK) { 344 + printk(KERN_ERR "x25_asy: lapb_data_request error - %d\n", err); 345 345 kfree_skb(skb); 346 346 return 0; 347 347 } ··· 357 357 * Called when I frame data arrives. We did the work above - throw it 358 358 * at the net layer. 359 359 */ 360 - 360 + 361 361 static int x25_asy_data_indication(struct net_device *dev, struct sk_buff *skb) 362 362 { 363 363 skb->dev->last_rx = jiffies; ··· 369 369 * busy cases too well. Its tricky to see how to do this nicely - 370 370 * perhaps lapb should allow us to bounce this ? 371 371 */ 372 - 372 + 373 373 static void x25_asy_data_transmit(struct net_device *dev, struct sk_buff *skb) 374 374 { 375 - struct x25_asy *sl=dev->priv; 376 - 375 + struct x25_asy *sl = dev->priv; 376 + 377 377 spin_lock(&sl->lock); 378 - if (netif_queue_stopped(sl->dev) || sl->tty == NULL) 379 - { 378 + if (netif_queue_stopped(sl->dev) || sl->tty == NULL) { 380 379 spin_unlock(&sl->lock); 381 380 printk(KERN_ERR "x25_asy: tbusy drop\n"); 382 381 kfree_skb(skb); 383 382 return; 384 383 } 385 384 /* We were not busy, so we are now... :-) */ 386 - if (skb != NULL) 387 - { 385 + if (skb != NULL) { 388 386 x25_asy_lock(sl); 389 - sl->stats.tx_bytes+=skb->len; 387 + sl->stats.tx_bytes += skb->len; 390 388 x25_asy_encaps(sl, skb->data, skb->len); 391 389 dev_kfree_skb(skb); 392 390 } ··· 394 396 /* 395 397 * LAPB connection establish/down information. 396 398 */ 397 - 399 + 398 400 static void x25_asy_connected(struct net_device *dev, int reason) 399 401 { 400 402 struct x25_asy *sl = dev->priv; 401 403 struct sk_buff *skb; 402 404 unsigned char *ptr; 403 405 404 - if ((skb = dev_alloc_skb(1)) == NULL) { 405 - printk(KERN_ERR "lapbeth: out of memory\n"); 406 + skb = dev_alloc_skb(1); 407 + if (skb == NULL) { 408 + printk(KERN_ERR "x25_asy: out of memory\n"); 406 409 return; 407 410 } 408 411 ··· 421 422 struct sk_buff *skb; 422 423 unsigned char *ptr; 423 424 424 - if ((skb = dev_alloc_skb(1)) == NULL) { 425 + skb = dev_alloc_skb(1); 426 + if (skb == NULL) { 425 427 printk(KERN_ERR "x25_asy: out of memory\n"); 426 428 return; 427 429 } ··· 449 449 /* Open the low-level part of the X.25 channel. Easy! */ 450 450 static int x25_asy_open(struct net_device *dev) 451 451 { 452 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 452 + struct x25_asy *sl = dev->priv; 453 453 unsigned long len; 454 454 int err; 455 455 ··· 466 466 len = dev->mtu * 2; 467 467 468 468 sl->rbuff = kmalloc(len + 4, GFP_KERNEL); 469 - if (sl->rbuff == NULL) { 469 + if (sl->rbuff == NULL) 470 470 goto norbuff; 471 - } 472 471 sl->xbuff = kmalloc(len + 4, GFP_KERNEL); 473 - if (sl->xbuff == NULL) { 472 + if (sl->xbuff == NULL) 474 473 goto noxbuff; 475 - } 476 474 477 475 sl->buffsize = len; 478 476 sl->rcount = 0; ··· 478 480 sl->flags &= (1 << SLF_INUSE); /* Clear ESCAPE & ERROR flags */ 479 481 480 482 netif_start_queue(dev); 481 - 483 + 482 484 /* 483 485 * Now attach LAPB 484 486 */ 485 - if((err=lapb_register(dev, &x25_asy_callbacks))==LAPB_OK) 487 + err = lapb_register(dev, &x25_asy_callbacks); 488 + if (err == LAPB_OK) 486 489 return 0; 487 490 488 491 /* Cleanup */ ··· 498 499 /* Close the low-level part of the X.25 channel. Easy! */ 499 500 static int x25_asy_close(struct net_device *dev) 500 501 { 501 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 502 + struct x25_asy *sl = dev->priv; 502 503 int err; 503 504 504 505 spin_lock(&sl->lock); 505 - if (sl->tty) 506 + if (sl->tty) 506 507 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 507 508 508 509 netif_stop_queue(dev); 509 510 sl->rcount = 0; 510 511 sl->xleft = 0; 511 - if((err=lapb_unregister(dev))!=LAPB_OK) 512 - printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n",err); 512 + err = lapb_unregister(dev); 513 + if (err != LAPB_OK) 514 + printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n", 515 + err); 513 516 spin_unlock(&sl->lock); 514 517 return 0; 515 518 } ··· 522 521 * a block of X.25 data has been received, which can now be decapsulated 523 522 * and sent on to some IP layer for further processing. 524 523 */ 525 - 526 - static void x25_asy_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) 524 + 525 + static void x25_asy_receive_buf(struct tty_struct *tty, 526 + const unsigned char *cp, char *fp, int count) 527 527 { 528 528 struct x25_asy *sl = (struct x25_asy *) tty->disc_data; 529 529 ··· 535 533 /* Read the characters out of the buffer */ 536 534 while (count--) { 537 535 if (fp && *fp++) { 538 - if (!test_and_set_bit(SLF_ERROR, &sl->flags)) { 536 + if (!test_and_set_bit(SLF_ERROR, &sl->flags)) 539 537 sl->stats.rx_errors++; 540 - } 541 538 cp++; 542 539 continue; 543 540 } ··· 557 556 struct x25_asy *sl = (struct x25_asy *) tty->disc_data; 558 557 int err; 559 558 559 + if (tty->ops->write == NULL) 560 + return -EOPNOTSUPP; 561 + 560 562 /* First make sure we're not already connected. */ 561 - if (sl && sl->magic == X25_ASY_MAGIC) { 563 + if (sl && sl->magic == X25_ASY_MAGIC) 562 564 return -EEXIST; 563 - } 564 565 565 566 /* OK. Find a free X.25 channel to use. */ 566 - if ((sl = x25_asy_alloc()) == NULL) { 567 + sl = x25_asy_alloc(); 568 + if (sl == NULL) 567 569 return -ENFILE; 568 - } 569 570 570 571 sl->tty = tty; 571 572 tty->disc_data = sl; 572 573 tty->receive_room = 65536; 573 - if (tty->driver->flush_buffer) { 574 - tty->driver->flush_buffer(tty); 575 - } 574 + tty_driver_flush_buffer(tty); 576 575 tty_ldisc_flush(tty); 577 576 578 577 /* Restore default settings */ 579 578 sl->dev->type = ARPHRD_X25; 580 - 581 - /* Perform the low-level X.25 async init */ 582 - if ((err = x25_asy_open(sl->dev))) 583 - return err; 584 579 580 + /* Perform the low-level X.25 async init */ 581 + err = x25_asy_open(sl->dev); 582 + if (err) 583 + return err; 585 584 /* Done. We have linked the TTY line to a channel. */ 586 585 return sl->dev->base_addr; 587 586 } ··· 602 601 return; 603 602 604 603 if (sl->dev->flags & IFF_UP) 605 - { 606 - (void) dev_close(sl->dev); 607 - } 604 + dev_close(sl->dev); 608 605 609 606 tty->disc_data = NULL; 610 607 sl->tty = NULL; ··· 612 613 613 614 static struct net_device_stats *x25_asy_get_stats(struct net_device *dev) 614 615 { 615 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 616 - 616 + struct x25_asy *sl = dev->priv; 617 617 return &sl->stats; 618 618 } 619 619 ··· 639 641 * character sequence, according to the X.25 protocol. 640 642 */ 641 643 642 - while (len-- > 0) 643 - { 644 - switch(c = *s++) 645 - { 646 - case X25_END: 647 - *ptr++ = X25_ESC; 648 - *ptr++ = X25_ESCAPE(X25_END); 649 - break; 650 - case X25_ESC: 651 - *ptr++ = X25_ESC; 652 - *ptr++ = X25_ESCAPE(X25_ESC); 653 - break; 654 - default: 655 - *ptr++ = c; 656 - break; 644 + while (len-- > 0) { 645 + switch (c = *s++) { 646 + case X25_END: 647 + *ptr++ = X25_ESC; 648 + *ptr++ = X25_ESCAPE(X25_END); 649 + break; 650 + case X25_ESC: 651 + *ptr++ = X25_ESC; 652 + *ptr++ = X25_ESCAPE(X25_ESC); 653 + break; 654 + default: 655 + *ptr++ = c; 656 + break; 657 657 } 658 658 } 659 659 *ptr++ = X25_END; ··· 661 665 static void x25_asy_unesc(struct x25_asy *sl, unsigned char s) 662 666 { 663 667 664 - switch(s) 665 - { 666 - case X25_END: 667 - if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) 668 - { 669 - x25_asy_bump(sl); 670 - } 671 - clear_bit(SLF_ESCAPE, &sl->flags); 672 - sl->rcount = 0; 673 - return; 674 - 675 - case X25_ESC: 676 - set_bit(SLF_ESCAPE, &sl->flags); 677 - return; 678 - 679 - case X25_ESCAPE(X25_ESC): 680 - case X25_ESCAPE(X25_END): 681 - if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) 682 - s = X25_UNESCAPE(s); 683 - break; 668 + switch (s) { 669 + case X25_END: 670 + if (!test_and_clear_bit(SLF_ERROR, &sl->flags) 671 + && sl->rcount > 2) 672 + x25_asy_bump(sl); 673 + clear_bit(SLF_ESCAPE, &sl->flags); 674 + sl->rcount = 0; 675 + return; 676 + case X25_ESC: 677 + set_bit(SLF_ESCAPE, &sl->flags); 678 + return; 679 + case X25_ESCAPE(X25_ESC): 680 + case X25_ESCAPE(X25_END): 681 + if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) 682 + s = X25_UNESCAPE(s); 683 + break; 684 684 } 685 - if (!test_bit(SLF_ERROR, &sl->flags)) 686 - { 687 - if (sl->rcount < sl->buffsize) 688 - { 685 + if (!test_bit(SLF_ERROR, &sl->flags)) { 686 + if (sl->rcount < sl->buffsize) { 689 687 sl->rbuff[sl->rcount++] = s; 690 688 return; 691 689 } ··· 699 709 if (!sl || sl->magic != X25_ASY_MAGIC) 700 710 return -EINVAL; 701 711 702 - switch(cmd) { 712 + switch (cmd) { 703 713 case SIOCGIFNAME: 704 714 if (copy_to_user((void __user *)arg, sl->dev->name, 705 715 strlen(sl->dev->name) + 1)) ··· 714 724 715 725 static int x25_asy_open_dev(struct net_device *dev) 716 726 { 717 - struct x25_asy *sl = (struct x25_asy*)(dev->priv); 718 - if(sl->tty==NULL) 727 + struct x25_asy *sl = dev->priv; 728 + if (sl->tty == NULL) 719 729 return -ENODEV; 720 730 return 0; 721 731 } ··· 731 741 set_bit(SLF_INUSE, &sl->flags); 732 742 733 743 /* 734 - * Finish setting up the DEVICE info. 744 + * Finish setting up the DEVICE info. 735 745 */ 736 - 746 + 737 747 dev->mtu = SL_MTU; 738 748 dev->hard_start_xmit = x25_asy_xmit; 739 749 dev->tx_timeout = x25_asy_timeout; ··· 768 778 x25_asy_maxdev = 4; /* Sanity */ 769 779 770 780 printk(KERN_INFO "X.25 async: version 0.00 ALPHA " 771 - "(dynamic channels, max=%d).\n", x25_asy_maxdev ); 781 + "(dynamic channels, max=%d).\n", x25_asy_maxdev); 772 782 773 - x25_asy_devs = kcalloc(x25_asy_maxdev, sizeof(struct net_device*), GFP_KERNEL); 783 + x25_asy_devs = kcalloc(x25_asy_maxdev, sizeof(struct net_device *), 784 + GFP_KERNEL); 774 785 if (!x25_asy_devs) { 775 786 printk(KERN_WARNING "X25 async: Can't allocate x25_asy_ctrls[] " 776 787 "array! Uaargh! (-> No X.25 available)\n"); ··· 793 802 struct x25_asy *sl = dev->priv; 794 803 795 804 spin_lock_bh(&sl->lock); 796 - if (sl->tty) 805 + if (sl->tty) 797 806 tty_hangup(sl->tty); 798 807 799 808 spin_unlock_bh(&sl->lock);
+4 -2
drivers/serial/kgdboc.c
··· 96 96 97 97 static int kgdboc_get_char(void) 98 98 { 99 - return kgdb_tty_driver->poll_get_char(kgdb_tty_driver, kgdb_tty_line); 99 + return kgdb_tty_driver->ops->poll_get_char(kgdb_tty_driver, 100 + kgdb_tty_line); 100 101 } 101 102 102 103 static void kgdboc_put_char(u8 chr) 103 104 { 104 - kgdb_tty_driver->poll_put_char(kgdb_tty_driver, kgdb_tty_line, chr); 105 + kgdb_tty_driver->ops->poll_put_char(kgdb_tty_driver, 106 + kgdb_tty_line, chr); 105 107 } 106 108 107 109 static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
+26 -12
drivers/serial/serial_core.c
··· 532 532 static int uart_write_room(struct tty_struct *tty) 533 533 { 534 534 struct uart_state *state = tty->driver_data; 535 + unsigned long flags; 536 + int ret; 535 537 536 - return uart_circ_chars_free(&state->info->xmit); 538 + spin_lock_irqsave(&state->port->lock, flags); 539 + ret = uart_circ_chars_free(&state->info->xmit); 540 + spin_unlock_irqrestore(&state->port->lock, flags); 541 + return ret; 537 542 } 538 543 539 544 static int uart_chars_in_buffer(struct tty_struct *tty) 540 545 { 541 546 struct uart_state *state = tty->driver_data; 547 + unsigned long flags; 548 + int ret; 542 549 543 - return uart_circ_chars_pending(&state->info->xmit); 550 + spin_lock_irqsave(&state->port->lock, flags); 551 + ret = uart_circ_chars_pending(&state->info->xmit); 552 + spin_unlock_irqrestore(&state->port->lock, flags); 553 + return ret; 544 554 } 545 555 546 556 static void uart_flush_buffer(struct tty_struct *tty) ··· 632 622 struct serial_struct tmp; 633 623 634 624 memset(&tmp, 0, sizeof(tmp)); 625 + 626 + /* Ensure the state we copy is consistent and no hardware changes 627 + occur as we go */ 628 + mutex_lock(&state->mutex); 629 + 635 630 tmp.type = port->type; 636 631 tmp.line = port->line; 637 632 tmp.port = port->iobase; ··· 655 640 tmp.io_type = port->iotype; 656 641 tmp.iomem_reg_shift = port->regshift; 657 642 tmp.iomem_base = (void *)(unsigned long)port->mapbase; 643 + 644 + mutex_unlock(&state->mutex); 658 645 659 646 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 660 647 return -EFAULT; ··· 935 918 struct uart_state *state = tty->driver_data; 936 919 struct uart_port *port = state->port; 937 920 938 - lock_kernel(); 939 921 mutex_lock(&state->mutex); 940 922 941 923 if (port->type != PORT_UNKNOWN) 942 924 port->ops->break_ctl(port, break_state); 943 925 944 926 mutex_unlock(&state->mutex); 945 - unlock_kernel(); 946 927 } 947 928 948 929 static int uart_do_autoconfig(struct uart_state *state) ··· 1089 1074 int ret = -ENOIOCTLCMD; 1090 1075 1091 1076 1092 - lock_kernel(); 1093 1077 /* 1094 1078 * These ioctls don't rely on the hardware to be present. 1095 1079 */ ··· 1158 1144 break; 1159 1145 } 1160 1146 } 1161 - out_up: 1147 + out_up: 1162 1148 mutex_unlock(&state->mutex); 1163 - out: 1164 - unlock_kernel(); 1149 + out: 1165 1150 return ret; 1166 1151 } 1167 1152 ··· 1186 1173 return; 1187 1174 } 1188 1175 1189 - lock_kernel(); 1190 1176 uart_change_speed(state, old_termios); 1191 1177 1192 1178 /* Handle transition to B0 status */ ··· 1218 1206 } 1219 1207 spin_unlock_irqrestore(&state->port->lock, flags); 1220 1208 } 1221 - unlock_kernel(); 1222 1209 #if 0 1223 1210 /* 1224 1211 * No need to wake up processes in open wait, since they ··· 1333 1322 struct uart_port *port = state->port; 1334 1323 unsigned long char_time, expire; 1335 1324 1336 - BUG_ON(!kernel_locked()); 1337 - 1338 1325 if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1339 1326 return; 1327 + 1328 + lock_kernel(); 1340 1329 1341 1330 /* 1342 1331 * Set the check interval to be 1/5 of the estimated time to ··· 1383 1372 break; 1384 1373 } 1385 1374 set_current_state(TASK_RUNNING); /* might not be needed */ 1375 + unlock_kernel(); 1386 1376 } 1387 1377 1388 1378 /* ··· 2097 2085 int ret; 2098 2086 2099 2087 uart_change_pm(state, 0); 2088 + spin_lock_irq(&port->lock); 2100 2089 ops->set_mctrl(port, 0); 2090 + spin_unlock_irq(&port->lock); 2101 2091 ret = ops->startup(port); 2102 2092 if (ret == 0) { 2103 2093 uart_change_speed(state, NULL);
+1 -2
drivers/usb/serial/digi_acceleport.c
··· 1421 1421 tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT); 1422 1422 1423 1423 /* flush driver and line discipline buffers */ 1424 - if (tty->driver->flush_buffer) 1425 - tty->driver->flush_buffer(tty); 1424 + tty_driver_flush_buffer(tty); 1426 1425 tty_ldisc_flush(tty); 1427 1426 1428 1427 if (port->serial->dev) {
+23 -106
drivers/usb/serial/usb-serial.c
··· 296 296 struct usb_serial_port *port = tty->driver_data; 297 297 int retval = -ENODEV; 298 298 299 - if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) 299 + if (port->serial->dev->state == USB_STATE_NOTATTACHED) 300 300 goto exit; 301 301 302 302 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 303 303 304 - if (!port->open_count) { 305 - retval = -EINVAL; 306 - dbg("%s - port not opened", __func__); 307 - goto exit; 308 - } 304 + /* open_count is managed under the mutex lock for the tty so cannot 305 + drop to zero until after the last close completes */ 306 + WARN_ON(!port->open_count); 309 307 310 308 /* pass on to the driver specific version of this function */ 311 309 retval = port->serial->type->write(port, buf, count); ··· 315 317 static int serial_write_room (struct tty_struct *tty) 316 318 { 317 319 struct usb_serial_port *port = tty->driver_data; 318 - int retval = -ENODEV; 319 - 320 - if (!port) 321 - goto exit; 322 - 323 320 dbg("%s - port %d", __func__, port->number); 324 - 325 - if (!port->open_count) { 326 - dbg("%s - port not open", __func__); 327 - goto exit; 328 - } 329 - 321 + WARN_ON(!port->open_count); 330 322 /* pass on to the driver specific version of this function */ 331 - retval = port->serial->type->write_room(port); 332 - 333 - exit: 334 - return retval; 323 + return port->serial->type->write_room(port); 335 324 } 336 325 337 326 static int serial_chars_in_buffer (struct tty_struct *tty) 338 327 { 339 328 struct usb_serial_port *port = tty->driver_data; 340 - int retval = -ENODEV; 341 - 342 - if (!port) 343 - goto exit; 344 - 345 329 dbg("%s = port %d", __func__, port->number); 346 330 347 - if (!port->open_count) { 348 - dbg("%s - port not open", __func__); 349 - goto exit; 350 - } 351 - 331 + WARN_ON(!port->open_count); 352 332 /* pass on to the driver specific version of this function */ 353 - retval = port->serial->type->chars_in_buffer(port); 354 - 355 - exit: 356 - return retval; 333 + return port->serial->type->chars_in_buffer(port); 357 334 } 358 335 359 336 static void serial_throttle (struct tty_struct * tty) 360 337 { 361 338 struct usb_serial_port *port = tty->driver_data; 362 - 363 - if (!port) 364 - return; 365 - 366 339 dbg("%s - port %d", __func__, port->number); 367 340 368 - if (!port->open_count) { 369 - dbg ("%s - port not open", __func__); 370 - return; 371 - } 372 - 341 + WARN_ON(!port->open_count); 373 342 /* pass on to the driver specific version of this function */ 374 343 if (port->serial->type->throttle) 375 344 port->serial->type->throttle(port); ··· 345 380 static void serial_unthrottle (struct tty_struct * tty) 346 381 { 347 382 struct usb_serial_port *port = tty->driver_data; 348 - 349 - if (!port) 350 - return; 351 - 352 383 dbg("%s - port %d", __func__, port->number); 353 384 354 - if (!port->open_count) { 355 - dbg("%s - port not open", __func__); 356 - return; 357 - } 358 - 385 + WARN_ON(!port->open_count); 359 386 /* pass on to the driver specific version of this function */ 360 387 if (port->serial->type->unthrottle) 361 388 port->serial->type->unthrottle(port); ··· 358 401 struct usb_serial_port *port = tty->driver_data; 359 402 int retval = -ENODEV; 360 403 361 - lock_kernel(); 362 - if (!port) 363 - goto exit; 364 - 365 404 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 366 405 367 - /* Caution - port->open_count is BKL protected */ 368 - if (!port->open_count) { 369 - dbg ("%s - port not open", __func__); 370 - goto exit; 371 - } 406 + WARN_ON(!port->open_count); 372 407 373 408 /* pass on to the driver specific version of this function if it is available */ 374 - if (port->serial->type->ioctl) 409 + if (port->serial->type->ioctl) { 410 + lock_kernel(); 375 411 retval = port->serial->type->ioctl(port, file, cmd, arg); 412 + unlock_kernel(); 413 + } 376 414 else 377 415 retval = -ENOIOCTLCMD; 378 - exit: 379 - unlock_kernel(); 380 416 return retval; 381 417 } 382 418 383 419 static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) 384 420 { 385 421 struct usb_serial_port *port = tty->driver_data; 386 - 387 - if (!port) 388 - return; 389 - 390 422 dbg("%s - port %d", __func__, port->number); 391 423 392 - if (!port->open_count) { 393 - dbg("%s - port not open", __func__); 394 - return; 395 - } 396 - 424 + WARN_ON(!port->open_count); 397 425 /* pass on to the driver specific version of this function if it is available */ 398 426 if (port->serial->type->set_termios) 399 427 port->serial->type->set_termios(port, old); ··· 390 448 { 391 449 struct usb_serial_port *port = tty->driver_data; 392 450 393 - lock_kernel(); 394 - if (!port) { 395 - unlock_kernel(); 396 - return; 397 - } 398 - 399 451 dbg("%s - port %d", __func__, port->number); 400 452 401 - if (!port->open_count) { 402 - dbg("%s - port not open", __func__); 403 - unlock_kernel(); 404 - return; 405 - } 406 - 453 + WARN_ON(!port->open_count); 407 454 /* pass on to the driver specific version of this function if it is available */ 408 - if (port->serial->type->break_ctl) 455 + if (port->serial->type->break_ctl) { 456 + lock_kernel(); 409 457 port->serial->type->break_ctl(port, break_state); 410 - unlock_kernel(); 458 + unlock_kernel(); 459 + } 411 460 } 412 461 413 462 static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) ··· 452 519 { 453 520 struct usb_serial_port *port = tty->driver_data; 454 521 455 - if (!port) 456 - return -ENODEV; 457 - 458 522 dbg("%s - port %d", __func__, port->number); 459 523 460 - if (!port->open_count) { 461 - dbg("%s - port not open", __func__); 462 - return -ENODEV; 463 - } 464 - 524 + WARN_ON(!port->open_count); 465 525 if (port->serial->type->tiocmget) 466 526 return port->serial->type->tiocmget(port, file); 467 - 468 527 return -EINVAL; 469 528 } 470 529 ··· 465 540 { 466 541 struct usb_serial_port *port = tty->driver_data; 467 542 468 - if (!port) 469 - return -ENODEV; 470 - 471 543 dbg("%s - port %d", __func__, port->number); 472 544 473 - if (!port->open_count) { 474 - dbg("%s - port not open", __func__); 475 - return -ENODEV; 476 - } 477 - 545 + WARN_ON(!port->open_count); 478 546 if (port->serial->type->tiocmset) 479 547 return port->serial->type->tiocmset(port, file, set, clear); 480 - 481 548 return -EINVAL; 482 549 } 483 550
+1 -3
drivers/usb/serial/whiteheat.c
··· 673 673 } 674 674 */ 675 675 676 - if (port->tty->driver->flush_buffer) 677 - port->tty->driver->flush_buffer(port->tty); 676 + tty_driver_flush_buffer(port->tty); 678 677 tty_ldisc_flush(port->tty); 679 678 680 679 firm_report_tx_done(port); 681 680 682 681 firm_close(port); 683 682 684 - printk(KERN_ERR"Before processing rx_urbs_submitted.\n"); 685 683 /* shutdown our bulk reads and writes */ 686 684 mutex_lock(&info->deathwarrant); 687 685 spin_lock_irq(&info->lock);
+1 -1
fs/compat_ioctl.c
··· 1053 1053 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 1054 1054 return -EINVAL; 1055 1055 1056 - if (tty->driver->ioctl != vt_ioctl) 1056 + if (tty->ops->ioctl != vt_ioctl) 1057 1057 return -EINVAL; 1058 1058 1059 1059 vc = (struct vc_data *)tty->driver_data;
+2 -4
fs/proc/proc_tty.c
··· 192 192 { 193 193 struct proc_dir_entry *ent; 194 194 195 - if ((!driver->read_proc && !driver->write_proc) || 196 - !driver->driver_name || 195 + if (!driver->ops->read_proc || !driver->driver_name || 197 196 driver->proc_entry) 198 197 return; 199 198 200 199 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver); 201 200 if (!ent) 202 201 return; 203 - ent->read_proc = driver->read_proc; 204 - ent->write_proc = driver->write_proc; 202 + ent->read_proc = driver->ops->read_proc; 205 203 ent->owner = driver->owner; 206 204 ent->data = driver; 207 205
+8
include/linux/tty.h
··· 177 177 * size each time the window is created or resized anyway. 178 178 * - TYT, 9/14/92 179 179 */ 180 + 181 + struct tty_operations; 182 + 180 183 struct tty_struct { 181 184 int magic; 182 185 struct tty_driver *driver; 186 + const struct tty_operations *ops; 183 187 int index; 184 188 struct tty_ldisc ldisc; 185 189 struct mutex termios_mutex; ··· 299 295 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, 300 296 int buflen); 301 297 extern void tty_write_message(struct tty_struct *tty, char *msg); 298 + extern int tty_put_char(struct tty_struct *tty, unsigned char c); 299 + extern int tty_chars_in_buffer(struct tty_struct *tty); 300 + extern int tty_write_room(struct tty_struct *tty); 301 + extern void tty_driver_flush_buffer(struct tty_struct *tty); 302 302 303 303 extern int is_current_pgrp_orphaned(void); 304 304 extern struct pid *tty_get_pgrp(struct tty_struct *tty);
+56 -50
include/linux/tty_driver.h
··· 12 12 * This routine is called when a particular tty device is opened. 13 13 * This routine is mandatory; if this routine is not filled in, 14 14 * the attempted open will fail with ENODEV. 15 + * 16 + * Required method. 15 17 * 16 18 * void (*close)(struct tty_struct * tty, struct file * filp); 17 19 * 18 20 * This routine is called when a particular tty device is closed. 21 + * 22 + * Required method. 19 23 * 20 24 * int (*write)(struct tty_struct * tty, 21 25 * const unsigned char *buf, int count); ··· 30 26 * number of characters actually accepted for writing. This 31 27 * routine is mandatory. 32 28 * 33 - * void (*put_char)(struct tty_struct *tty, unsigned char ch); 29 + * Optional: Required for writable devices. 30 + * 31 + * int (*put_char)(struct tty_struct *tty, unsigned char ch); 34 32 * 35 33 * This routine is called by the kernel to write a single 36 34 * character to the tty device. If the kernel uses this routine, ··· 40 34 * done stuffing characters into the driver. If there is no room 41 35 * in the queue, the character is ignored. 42 36 * 37 + * Optional: Kernel will use the write method if not provided. 38 + * 39 + * Note: Do not call this function directly, call tty_put_char 40 + * 43 41 * void (*flush_chars)(struct tty_struct *tty); 44 42 * 45 43 * This routine is called by the kernel after it has written a 46 44 * series of characters to the tty device using put_char(). 45 + * 46 + * Optional: 47 + * 48 + * Note: Do not call this function directly, call tty_driver_flush_chars 47 49 * 48 50 * int (*write_room)(struct tty_struct *tty); 49 51 * ··· 59 45 * will accept for queuing to be written. This number is subject 60 46 * to change as output buffers get emptied, or if the output flow 61 47 * control is acted. 48 + * 49 + * Required if write method is provided else not needed. 50 + * 51 + * Note: Do not call this function directly, call tty_write_room 62 52 * 63 53 * int (*ioctl)(struct tty_struct *tty, struct file * file, 64 54 * unsigned int cmd, unsigned long arg); ··· 71 53 * device-specific ioctl's. If the ioctl number passed in cmd 72 54 * is not recognized by the driver, it should return ENOIOCTLCMD. 73 55 * 56 + * Optional 57 + * 74 58 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file, 75 59 * unsigned int cmd, unsigned long arg); 76 60 * 77 61 * implement ioctl processing for 32 bit process on 64 bit system 62 + * 63 + * Optional 78 64 * 79 65 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); 80 66 * 81 67 * This routine allows the tty driver to be notified when 82 - * device's termios settings have changed. Note that a 83 - * well-designed tty driver should be prepared to accept the case 84 - * where old == NULL, and try to do something rational. 68 + * device's termios settings have changed. 69 + * 70 + * Optional: Called under the termios lock 71 + * 85 72 * 86 73 * void (*set_ldisc)(struct tty_struct *tty); 87 74 * 88 75 * This routine allows the tty driver to be notified when the 89 76 * device's termios settings have changed. 77 + * 78 + * Optional: Called under BKL (currently) 90 79 * 91 80 * void (*throttle)(struct tty_struct * tty); 92 81 * ··· 111 86 * 112 87 * This routine notifies the tty driver that it should stop 113 88 * outputting characters to the tty device. 89 + * 90 + * Optional: 91 + * 92 + * Note: Call stop_tty not this method. 114 93 * 115 94 * void (*start)(struct tty_struct *tty); 116 95 * 117 96 * This routine notifies the tty driver that it resume sending 118 97 * characters to the tty device. 98 + * 99 + * Optional: 100 + * 101 + * Note: Call start_tty not this method. 119 102 * 120 103 * void (*hangup)(struct tty_struct *tty); 121 104 * 122 105 * This routine notifies the tty driver that it should hangup the 123 106 * tty device. 107 + * 108 + * Required: 124 109 * 125 110 * void (*break_ctl)(struct tty_stuct *tty, int state); 126 111 * ··· 141 106 * 142 107 * If this routine is implemented, the high-level tty driver will 143 108 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, 144 - * TIOCCBRK. Otherwise, these ioctls will be passed down to the 145 - * driver to handle. 109 + * TIOCCBRK. 110 + * 111 + * Optional: Required for TCSBRK/BRKP/etc handling. 146 112 * 147 113 * void (*wait_until_sent)(struct tty_struct *tty, int timeout); 148 114 * 149 115 * This routine waits until the device has written out all of the 150 116 * characters in its transmitter FIFO. 151 117 * 118 + * Optional: If not provided the device is assumed to have no FIFO 119 + * 120 + * Note: Usually correct to call tty_wait_until_sent 121 + * 152 122 * void (*send_xchar)(struct tty_struct *tty, char ch); 153 123 * 154 124 * This routine is used to send a high-priority XON/XOFF 155 125 * character to the device. 126 + * 127 + * Optional: If not provided then the write method is called under 128 + * the atomic write lock to keep it serialized with the ldisc. 156 129 */ 157 130 158 131 #include <linux/fs.h> ··· 175 132 void (*close)(struct tty_struct * tty, struct file * filp); 176 133 int (*write)(struct tty_struct * tty, 177 134 const unsigned char *buf, int count); 178 - void (*put_char)(struct tty_struct *tty, unsigned char ch); 135 + int (*put_char)(struct tty_struct *tty, unsigned char ch); 179 136 void (*flush_chars)(struct tty_struct *tty); 180 137 int (*write_room)(struct tty_struct *tty); 181 138 int (*chars_in_buffer)(struct tty_struct *tty); ··· 196 153 void (*send_xchar)(struct tty_struct *tty, char ch); 197 154 int (*read_proc)(char *page, char **start, off_t off, 198 155 int count, int *eof, void *data); 199 - int (*write_proc)(struct file *file, const char __user *buffer, 200 - unsigned long count, void *data); 201 156 int (*tiocmget)(struct tty_struct *tty, struct file *file); 202 157 int (*tiocmset)(struct tty_struct *tty, struct file *file, 203 158 unsigned int set, unsigned int clear); ··· 231 190 struct tty_struct **ttys; 232 191 struct ktermios **termios; 233 192 struct ktermios **termios_locked; 234 - void *driver_state; /* only used for the PTY driver */ 235 - 236 - /* 237 - * Interface routines from the upper tty layer to the tty 238 - * driver. Will be replaced with struct tty_operations. 239 - */ 240 - int (*open)(struct tty_struct * tty, struct file * filp); 241 - void (*close)(struct tty_struct * tty, struct file * filp); 242 - int (*write)(struct tty_struct * tty, 243 - const unsigned char *buf, int count); 244 - void (*put_char)(struct tty_struct *tty, unsigned char ch); 245 - void (*flush_chars)(struct tty_struct *tty); 246 - int (*write_room)(struct tty_struct *tty); 247 - int (*chars_in_buffer)(struct tty_struct *tty); 248 - int (*ioctl)(struct tty_struct *tty, struct file * file, 249 - unsigned int cmd, unsigned long arg); 250 - long (*compat_ioctl)(struct tty_struct *tty, struct file * file, 251 - unsigned int cmd, unsigned long arg); 252 - void (*set_termios)(struct tty_struct *tty, struct ktermios * old); 253 - void (*throttle)(struct tty_struct * tty); 254 - void (*unthrottle)(struct tty_struct * tty); 255 - void (*stop)(struct tty_struct *tty); 256 - void (*start)(struct tty_struct *tty); 257 - void (*hangup)(struct tty_struct *tty); 258 - void (*break_ctl)(struct tty_struct *tty, int state); 259 - void (*flush_buffer)(struct tty_struct *tty); 260 - void (*set_ldisc)(struct tty_struct *tty); 261 - void (*wait_until_sent)(struct tty_struct *tty, int timeout); 262 - void (*send_xchar)(struct tty_struct *tty, char ch); 263 - int (*read_proc)(char *page, char **start, off_t off, 264 - int count, int *eof, void *data); 265 - int (*write_proc)(struct file *file, const char __user *buffer, 266 - unsigned long count, void *data); 267 - int (*tiocmget)(struct tty_struct *tty, struct file *file); 268 - int (*tiocmset)(struct tty_struct *tty, struct file *file, 269 - unsigned int set, unsigned int clear); 270 - #ifdef CONFIG_CONSOLE_POLL 271 - int (*poll_init)(struct tty_driver *driver, int line, char *options); 272 - int (*poll_get_char)(struct tty_driver *driver, int line); 273 - void (*poll_put_char)(struct tty_driver *driver, int line, char ch); 274 - #endif 193 + void *driver_state; 275 194 195 + /* 196 + * Driver methods 197 + */ 198 + 199 + const struct tty_operations *ops; 276 200 struct list_head tty_drivers; 277 201 }; 278 202
+2 -2
kernel/printk.c
··· 1272 1272 */ 1273 1273 void tty_write_message(struct tty_struct *tty, char *msg) 1274 1274 { 1275 - if (tty && tty->driver->write) 1276 - tty->driver->write(tty, msg, strlen(msg)); 1275 + if (tty && tty->ops->write) 1276 + tty->ops->write(tty, msg, strlen(msg)); 1277 1277 return; 1278 1278 } 1279 1279
+2 -4
net/irda/ircomm/ircomm_tty.c
··· 555 555 556 556 ircomm_tty_shutdown(self); 557 557 558 - if (tty->driver->flush_buffer) 559 - tty->driver->flush_buffer(tty); 560 - if (tty->ldisc.flush_buffer) 561 - tty->ldisc.flush_buffer(tty); 558 + tty_driver_flush_buffer(tty); 559 + tty_ldisc_flush(tty); 562 560 563 561 tty->closing = 0; 564 562 self->tty = NULL;