diff options
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/n_gsm.c | 5 | ||||
-rw-r--r-- | drivers/tty/tty_buffer.c | 14 | ||||
-rw-r--r-- | drivers/tty/tty_ldisc.c | 49 | ||||
-rw-r--r-- | drivers/tty/vt/vc_screen.c | 6 |
4 files changed, 60 insertions, 14 deletions
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 04ef3ef0a422..81b46585edf7 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c | |||
@@ -716,8 +716,8 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg) | |||
716 | if (msg->len < 128) | 716 | if (msg->len < 128) |
717 | *--dp = (msg->len << 1) | EA; | 717 | *--dp = (msg->len << 1) | EA; |
718 | else { | 718 | else { |
719 | *--dp = (msg->len >> 6) | EA; | 719 | *--dp = ((msg->len & 127) << 1) | EA; |
720 | *--dp = (msg->len & 127) << 1; | 720 | *--dp = (msg->len >> 6) & 0xfe; |
721 | } | 721 | } |
722 | } | 722 | } |
723 | 723 | ||
@@ -2375,6 +2375,7 @@ static int gsmld_config(struct tty_struct *tty, struct gsm_mux *gsm, | |||
2375 | gsm->mru = c->mru; | 2375 | gsm->mru = c->mru; |
2376 | gsm->encoding = c->encapsulation; | 2376 | gsm->encoding = c->encapsulation; |
2377 | gsm->adaption = c->adaption; | 2377 | gsm->adaption = c->adaption; |
2378 | gsm->n2 = c->n2; | ||
2378 | 2379 | ||
2379 | if (c->i == 1) | 2380 | if (c->i == 1) |
2380 | gsm->ftype = UIH; | 2381 | gsm->ftype = UIH; |
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index cc1e9850d655..d8210ca00720 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c | |||
@@ -413,7 +413,8 @@ static void flush_to_ldisc(struct work_struct *work) | |||
413 | spin_lock_irqsave(&tty->buf.lock, flags); | 413 | spin_lock_irqsave(&tty->buf.lock, flags); |
414 | 414 | ||
415 | if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) { | 415 | if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) { |
416 | struct tty_buffer *head; | 416 | struct tty_buffer *head, *tail = tty->buf.tail; |
417 | int seen_tail = 0; | ||
417 | while ((head = tty->buf.head) != NULL) { | 418 | while ((head = tty->buf.head) != NULL) { |
418 | int count; | 419 | int count; |
419 | char *char_buf; | 420 | char *char_buf; |
@@ -423,6 +424,15 @@ static void flush_to_ldisc(struct work_struct *work) | |||
423 | if (!count) { | 424 | if (!count) { |
424 | if (head->next == NULL) | 425 | if (head->next == NULL) |
425 | break; | 426 | break; |
427 | /* | ||
428 | There's a possibility tty might get new buffer | ||
429 | added during the unlock window below. We could | ||
430 | end up spinning in here forever hogging the CPU | ||
431 | completely. To avoid this let's have a rest each | ||
432 | time we processed the tail buffer. | ||
433 | */ | ||
434 | if (tail == head) | ||
435 | seen_tail = 1; | ||
426 | tty->buf.head = head->next; | 436 | tty->buf.head = head->next; |
427 | tty_buffer_free(tty, head); | 437 | tty_buffer_free(tty, head); |
428 | continue; | 438 | continue; |
@@ -432,7 +442,7 @@ static void flush_to_ldisc(struct work_struct *work) | |||
432 | line discipline as we want to empty the queue */ | 442 | line discipline as we want to empty the queue */ |
433 | if (test_bit(TTY_FLUSHPENDING, &tty->flags)) | 443 | if (test_bit(TTY_FLUSHPENDING, &tty->flags)) |
434 | break; | 444 | break; |
435 | if (!tty->receive_room) { | 445 | if (!tty->receive_room || seen_tail) { |
436 | schedule_delayed_work(&tty->buf.work, 1); | 446 | schedule_delayed_work(&tty->buf.work, 1); |
437 | break; | 447 | break; |
438 | } | 448 | } |
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index 412f9775d19c..d8e96b005023 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c | |||
@@ -47,6 +47,7 @@ | |||
47 | 47 | ||
48 | static DEFINE_SPINLOCK(tty_ldisc_lock); | 48 | static DEFINE_SPINLOCK(tty_ldisc_lock); |
49 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); | 49 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); |
50 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle); | ||
50 | /* Line disc dispatch table */ | 51 | /* Line disc dispatch table */ |
51 | static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; | 52 | static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; |
52 | 53 | ||
@@ -83,6 +84,7 @@ static void put_ldisc(struct tty_ldisc *ld) | |||
83 | return; | 84 | return; |
84 | } | 85 | } |
85 | local_irq_restore(flags); | 86 | local_irq_restore(flags); |
87 | wake_up(&tty_ldisc_idle); | ||
86 | } | 88 | } |
87 | 89 | ||
88 | /** | 90 | /** |
@@ -531,6 +533,23 @@ static int tty_ldisc_halt(struct tty_struct *tty) | |||
531 | } | 533 | } |
532 | 534 | ||
533 | /** | 535 | /** |
536 | * tty_ldisc_wait_idle - wait for the ldisc to become idle | ||
537 | * @tty: tty to wait for | ||
538 | * | ||
539 | * Wait for the line discipline to become idle. The discipline must | ||
540 | * have been halted for this to guarantee it remains idle. | ||
541 | */ | ||
542 | static int tty_ldisc_wait_idle(struct tty_struct *tty) | ||
543 | { | ||
544 | int ret; | ||
545 | ret = wait_event_interruptible_timeout(tty_ldisc_idle, | ||
546 | atomic_read(&tty->ldisc->users) == 1, 5 * HZ); | ||
547 | if (ret < 0) | ||
548 | return ret; | ||
549 | return ret > 0 ? 0 : -EBUSY; | ||
550 | } | ||
551 | |||
552 | /** | ||
534 | * tty_set_ldisc - set line discipline | 553 | * tty_set_ldisc - set line discipline |
535 | * @tty: the terminal to set | 554 | * @tty: the terminal to set |
536 | * @ldisc: the line discipline | 555 | * @ldisc: the line discipline |
@@ -634,8 +653,17 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
634 | 653 | ||
635 | flush_scheduled_work(); | 654 | flush_scheduled_work(); |
636 | 655 | ||
656 | retval = tty_ldisc_wait_idle(tty); | ||
657 | |||
637 | tty_lock(); | 658 | tty_lock(); |
638 | mutex_lock(&tty->ldisc_mutex); | 659 | mutex_lock(&tty->ldisc_mutex); |
660 | |||
661 | /* handle wait idle failure locked */ | ||
662 | if (retval) { | ||
663 | tty_ldisc_put(new_ldisc); | ||
664 | goto enable; | ||
665 | } | ||
666 | |||
639 | if (test_bit(TTY_HUPPED, &tty->flags)) { | 667 | if (test_bit(TTY_HUPPED, &tty->flags)) { |
640 | /* We were raced by the hangup method. It will have stomped | 668 | /* We were raced by the hangup method. It will have stomped |
641 | the ldisc data and closed the ldisc down */ | 669 | the ldisc data and closed the ldisc down */ |
@@ -669,6 +697,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
669 | 697 | ||
670 | tty_ldisc_put(o_ldisc); | 698 | tty_ldisc_put(o_ldisc); |
671 | 699 | ||
700 | enable: | ||
672 | /* | 701 | /* |
673 | * Allow ldisc referencing to occur again | 702 | * Allow ldisc referencing to occur again |
674 | */ | 703 | */ |
@@ -714,9 +743,12 @@ static void tty_reset_termios(struct tty_struct *tty) | |||
714 | * state closed | 743 | * state closed |
715 | */ | 744 | */ |
716 | 745 | ||
717 | static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc) | 746 | static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc) |
718 | { | 747 | { |
719 | struct tty_ldisc *ld; | 748 | struct tty_ldisc *ld = tty_ldisc_get(ldisc); |
749 | |||
750 | if (IS_ERR(ld)) | ||
751 | return -1; | ||
720 | 752 | ||
721 | tty_ldisc_close(tty, tty->ldisc); | 753 | tty_ldisc_close(tty, tty->ldisc); |
722 | tty_ldisc_put(tty->ldisc); | 754 | tty_ldisc_put(tty->ldisc); |
@@ -724,10 +756,10 @@ static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc) | |||
724 | /* | 756 | /* |
725 | * Switch the line discipline back | 757 | * Switch the line discipline back |
726 | */ | 758 | */ |
727 | ld = tty_ldisc_get(ldisc); | ||
728 | BUG_ON(IS_ERR(ld)); | ||
729 | tty_ldisc_assign(tty, ld); | 759 | tty_ldisc_assign(tty, ld); |
730 | tty_set_termios_ldisc(tty, ldisc); | 760 | tty_set_termios_ldisc(tty, ldisc); |
761 | |||
762 | return 0; | ||
731 | } | 763 | } |
732 | 764 | ||
733 | /** | 765 | /** |
@@ -802,13 +834,16 @@ void tty_ldisc_hangup(struct tty_struct *tty) | |||
802 | a FIXME */ | 834 | a FIXME */ |
803 | if (tty->ldisc) { /* Not yet closed */ | 835 | if (tty->ldisc) { /* Not yet closed */ |
804 | if (reset == 0) { | 836 | if (reset == 0) { |
805 | tty_ldisc_reinit(tty, tty->termios->c_line); | 837 | |
806 | err = tty_ldisc_open(tty, tty->ldisc); | 838 | if (!tty_ldisc_reinit(tty, tty->termios->c_line)) |
839 | err = tty_ldisc_open(tty, tty->ldisc); | ||
840 | else | ||
841 | err = 1; | ||
807 | } | 842 | } |
808 | /* If the re-open fails or we reset then go to N_TTY. The | 843 | /* If the re-open fails or we reset then go to N_TTY. The |
809 | N_TTY open cannot fail */ | 844 | N_TTY open cannot fail */ |
810 | if (reset || err) { | 845 | if (reset || err) { |
811 | tty_ldisc_reinit(tty, N_TTY); | 846 | BUG_ON(tty_ldisc_reinit(tty, N_TTY)); |
812 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); | 847 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); |
813 | } | 848 | } |
814 | tty_ldisc_enable(tty); | 849 | tty_ldisc_enable(tty); |
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c index 273ab44cc91d..eab3a1ff99e4 100644 --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c | |||
@@ -553,12 +553,12 @@ static unsigned int | |||
553 | vcs_poll(struct file *file, poll_table *wait) | 553 | vcs_poll(struct file *file, poll_table *wait) |
554 | { | 554 | { |
555 | struct vcs_poll_data *poll = vcs_poll_data_get(file); | 555 | struct vcs_poll_data *poll = vcs_poll_data_get(file); |
556 | int ret = 0; | 556 | int ret = DEFAULT_POLLMASK|POLLERR|POLLPRI; |
557 | 557 | ||
558 | if (poll) { | 558 | if (poll) { |
559 | poll_wait(file, &poll->waitq, wait); | 559 | poll_wait(file, &poll->waitq, wait); |
560 | if (!poll->seen_last_update) | 560 | if (poll->seen_last_update) |
561 | ret = POLLIN | POLLRDNORM; | 561 | ret = DEFAULT_POLLMASK; |
562 | } | 562 | } |
563 | return ret; | 563 | return ret; |
564 | } | 564 | } |