aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2008-02-08 07:18:47 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:25 -0500
commit37bdfb074ec035880ed140f6281badf92b655a72 (patch)
tree9226be1a944ad3f87f2095675ba8a7f07b979817 /drivers/char
parent66c6ceae39534c029c3434489c036f5ae2c6a593 (diff)
tty_io: drag screaming into coding style compliance
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/tty_io.c561
1 files changed, 283 insertions, 278 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 79c86c47947f..613ec816ce60 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -19,7 +19,7 @@
19 * Also restructured routines so that there is more of a separation 19 * Also restructured routines so that there is more of a separation
20 * between the high-level tty routines (tty_io.c and tty_ioctl.c) and 20 * between the high-level tty routines (tty_io.c and tty_ioctl.c) and
21 * the low-level tty routines (serial.c, pty.c, console.c). This 21 * the low-level tty routines (serial.c, pty.c, console.c). This
22 * makes for cleaner and more compact code. -TYT, 9/17/92 22 * makes for cleaner and more compact code. -TYT, 9/17/92
23 * 23 *
24 * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines 24 * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines
25 * which can be dynamically activated and de-activated by the line 25 * which can be dynamically activated and de-activated by the line
@@ -41,7 +41,7 @@
41 * 41 *
42 * New TIOCLINUX variants added. 42 * New TIOCLINUX variants added.
43 * -- mj@k332.feld.cvut.cz, 19-Nov-95 43 * -- mj@k332.feld.cvut.cz, 19-Nov-95
44 * 44 *
45 * Restrict vt switching via ioctl() 45 * Restrict vt switching via ioctl()
46 * -- grif@cs.ucr.edu, 5-Dec-95 46 * -- grif@cs.ucr.edu, 5-Dec-95
47 * 47 *
@@ -62,7 +62,8 @@
62 * -- Russell King <rmk@arm.linux.org.uk> 62 * -- Russell King <rmk@arm.linux.org.uk>
63 * 63 *
64 * Move do_SAK() into process context. Less stack use in devfs functions. 64 * Move do_SAK() into process context. Less stack use in devfs functions.
65 * alloc_tty_struct() always uses kmalloc() -- Andrew Morton <andrewm@uow.edu.eu> 17Mar01 65 * alloc_tty_struct() always uses kmalloc()
66 * -- Andrew Morton <andrewm@uow.edu.eu> 17Mar01
66 */ 67 */
67 68
68#include <linux/types.h> 69#include <linux/types.h>
@@ -126,7 +127,7 @@ EXPORT_SYMBOL(tty_std_termios);
126/* This list gets poked at by procfs and various bits of boot up code. This 127/* This list gets poked at by procfs and various bits of boot up code. This
127 could do with some rationalisation such as pulling the tty proc function 128 could do with some rationalisation such as pulling the tty proc function
128 into this file */ 129 into this file */
129 130
130LIST_HEAD(tty_drivers); /* linked list of tty drivers */ 131LIST_HEAD(tty_drivers); /* linked list of tty drivers */
131 132
132/* Mutex to protect creating and releasing a tty. This is shared with 133/* Mutex to protect creating and releasing a tty. This is shared with
@@ -136,7 +137,7 @@ EXPORT_SYMBOL(tty_mutex);
136 137
137#ifdef CONFIG_UNIX98_PTYS 138#ifdef CONFIG_UNIX98_PTYS
138extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ 139extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
139extern int pty_limit; /* Config limit on Unix98 ptys */ 140extern int pty_limit; /* Config limit on Unix98 ptys */
140static DEFINE_IDR(allocated_ptys); 141static DEFINE_IDR(allocated_ptys);
141static DEFINE_MUTEX(allocated_ptys_lock); 142static DEFINE_MUTEX(allocated_ptys_lock);
142static int ptmx_open(struct inode *, struct file *); 143static int ptmx_open(struct inode *, struct file *);
@@ -146,19 +147,20 @@ static void initialize_tty_struct(struct tty_struct *tty);
146 147
147static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *); 148static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
148static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *); 149static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
149ssize_t redirected_tty_write(struct file *, const char __user *, size_t, loff_t *); 150ssize_t redirected_tty_write(struct file *, const char __user *,
151 size_t, loff_t *);
150static unsigned int tty_poll(struct file *, poll_table *); 152static unsigned int tty_poll(struct file *, poll_table *);
151static int tty_open(struct inode *, struct file *); 153static int tty_open(struct inode *, struct file *);
152static int tty_release(struct inode *, struct file *); 154static int tty_release(struct inode *, struct file *);
153int tty_ioctl(struct inode * inode, struct file * file, 155int tty_ioctl(struct inode *inode, struct file *file,
154 unsigned int cmd, unsigned long arg); 156 unsigned int cmd, unsigned long arg);
155#ifdef CONFIG_COMPAT 157#ifdef CONFIG_COMPAT
156static long tty_compat_ioctl(struct file * file, unsigned int cmd, 158static long tty_compat_ioctl(struct file *file, unsigned int cmd,
157 unsigned long arg); 159 unsigned long arg);
158#else 160#else
159#define tty_compat_ioctl NULL 161#define tty_compat_ioctl NULL
160#endif 162#endif
161static int tty_fasync(int fd, struct file * filp, int on); 163static int tty_fasync(int fd, struct file *filp, int on);
162static void release_tty(struct tty_struct *tty, int idx); 164static void release_tty(struct tty_struct *tty, int idx);
163static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 165static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
164static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 166static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
@@ -244,7 +246,7 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
244#ifdef CHECK_TTY_COUNT 246#ifdef CHECK_TTY_COUNT
245 struct list_head *p; 247 struct list_head *p;
246 int count = 0; 248 int count = 0;
247 249
248 file_list_lock(); 250 file_list_lock();
249 list_for_each(p, &tty->tty_files) { 251 list_for_each(p, &tty->tty_files) {
250 count++; 252 count++;
@@ -281,11 +283,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
281static void tty_buffer_free_all(struct tty_struct *tty) 283static void tty_buffer_free_all(struct tty_struct *tty)
282{ 284{
283 struct tty_buffer *thead; 285 struct tty_buffer *thead;
284 while((thead = tty->buf.head) != NULL) { 286 while ((thead = tty->buf.head) != NULL) {
285 tty->buf.head = thead->next; 287 tty->buf.head = thead->next;
286 kfree(thead); 288 kfree(thead);
287 } 289 }
288 while((thead = tty->buf.free) != NULL) { 290 while ((thead = tty->buf.free) != NULL) {
289 tty->buf.free = thead->next; 291 tty->buf.free = thead->next;
290 kfree(thead); 292 kfree(thead);
291 } 293 }
@@ -331,7 +333,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
331 if (tty->buf.memory_used + size > 65536) 333 if (tty->buf.memory_used + size > 65536)
332 return NULL; 334 return NULL;
333 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); 335 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
334 if(p == NULL) 336 if (p == NULL)
335 return NULL; 337 return NULL;
336 p->used = 0; 338 p->used = 0;
337 p->size = size; 339 p->size = size;
@@ -361,7 +363,7 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
361 tty->buf.memory_used -= b->size; 363 tty->buf.memory_used -= b->size;
362 WARN_ON(tty->buf.memory_used < 0); 364 WARN_ON(tty->buf.memory_used < 0);
363 365
364 if(b->size >= 512) 366 if (b->size >= 512)
365 kfree(b); 367 kfree(b);
366 else { 368 else {
367 b->next = tty->buf.free; 369 b->next = tty->buf.free;
@@ -384,7 +386,7 @@ static void __tty_buffer_flush(struct tty_struct *tty)
384{ 386{
385 struct tty_buffer *thead; 387 struct tty_buffer *thead;
386 388
387 while((thead = tty->buf.head) != NULL) { 389 while ((thead = tty->buf.head) != NULL) {
388 tty->buf.head = thead->next; 390 tty->buf.head = thead->next;
389 tty_buffer_free(tty, thead); 391 tty_buffer_free(tty, thead);
390 } 392 }
@@ -436,9 +438,9 @@ static void tty_buffer_flush(struct tty_struct *tty)
436static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size) 438static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
437{ 439{
438 struct tty_buffer **tbh = &tty->buf.free; 440 struct tty_buffer **tbh = &tty->buf.free;
439 while((*tbh) != NULL) { 441 while ((*tbh) != NULL) {
440 struct tty_buffer *t = *tbh; 442 struct tty_buffer *t = *tbh;
441 if(t->size >= size) { 443 if (t->size >= size) {
442 *tbh = t->next; 444 *tbh = t->next;
443 t->next = NULL; 445 t->next = NULL;
444 t->used = 0; 446 t->used = 0;
@@ -450,7 +452,7 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
450 tbh = &((*tbh)->next); 452 tbh = &((*tbh)->next);
451 } 453 }
452 /* Round the buffer size out */ 454 /* Round the buffer size out */
453 size = (size + 0xFF) & ~ 0xFF; 455 size = (size + 0xFF) & ~0xFF;
454 return tty_buffer_alloc(tty, size); 456 return tty_buffer_alloc(tty, size);
455 /* Should possibly check if this fails for the largest buffer we 457 /* Should possibly check if this fails for the largest buffer we
456 have queued and recycle that ? */ 458 have queued and recycle that ? */
@@ -520,7 +522,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
520 int space = tty_buffer_request_room(tty, size - copied); 522 int space = tty_buffer_request_room(tty, size - copied);
521 struct tty_buffer *tb = tty->buf.tail; 523 struct tty_buffer *tb = tty->buf.tail;
522 /* If there is no space then tb may be NULL */ 524 /* If there is no space then tb may be NULL */
523 if(unlikely(space == 0)) 525 if (unlikely(space == 0))
524 break; 526 break;
525 memcpy(tb->char_buf_ptr + tb->used, chars, space); 527 memcpy(tb->char_buf_ptr + tb->used, chars, space);
526 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 528 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
@@ -556,7 +558,7 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
556 int space = tty_buffer_request_room(tty, size - copied); 558 int space = tty_buffer_request_room(tty, size - copied);
557 struct tty_buffer *tb = tty->buf.tail; 559 struct tty_buffer *tb = tty->buf.tail;
558 /* If there is no space then tb may be NULL */ 560 /* If there is no space then tb may be NULL */
559 if(unlikely(space == 0)) 561 if (unlikely(space == 0))
560 break; 562 break;
561 memcpy(tb->char_buf_ptr + tb->used, chars, space); 563 memcpy(tb->char_buf_ptr + tb->used, chars, space);
562 memcpy(tb->flag_buf_ptr + tb->used, flags, space); 564 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
@@ -608,7 +610,8 @@ EXPORT_SYMBOL(tty_schedule_flip);
608 * Locking: May call functions taking tty->buf.lock 610 * Locking: May call functions taking tty->buf.lock
609 */ 611 */
610 612
611int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size) 613int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
614 size_t size)
612{ 615{
613 int space = tty_buffer_request_room(tty, size); 616 int space = tty_buffer_request_room(tty, size);
614 if (likely(space)) { 617 if (likely(space)) {
@@ -638,7 +641,8 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
638 * Locking: May call functions taking tty->buf.lock 641 * Locking: May call functions taking tty->buf.lock
639 */ 642 */
640 643
641int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size) 644int tty_prepare_flip_string_flags(struct tty_struct *tty,
645 unsigned char **chars, char **flags, size_t size)
642{ 646{
643 int space = tty_buffer_request_room(tty, size); 647 int space = tty_buffer_request_room(tty, size);
644 if (likely(space)) { 648 if (likely(space)) {
@@ -660,12 +664,12 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
660 * @num: line discipline number 664 * @num: line discipline number
661 * 665 *
662 * This is probably overkill for real world processors but 666 * This is probably overkill for real world processors but
663 * they are not on hot paths so a little discipline won't do 667 * they are not on hot paths so a little discipline won't do
664 * any harm. 668 * any harm.
665 * 669 *
666 * Locking: takes termios_mutex 670 * Locking: takes termios_mutex
667 */ 671 */
668 672
669static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 673static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
670{ 674{
671 mutex_lock(&tty->termios_mutex); 675 mutex_lock(&tty->termios_mutex);
@@ -678,10 +682,11 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
678 * must be taken with irqs off because there are hangup path 682 * must be taken with irqs off because there are hangup path
679 * callers who will do ldisc lookups and cannot sleep. 683 * callers who will do ldisc lookups and cannot sleep.
680 */ 684 */
681 685
682static DEFINE_SPINLOCK(tty_ldisc_lock); 686static DEFINE_SPINLOCK(tty_ldisc_lock);
683static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); 687static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
684static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch table */ 688/* Line disc dispatch table */
689static struct tty_ldisc tty_ldiscs[NR_LDISCS];
685 690
686/** 691/**
687 * tty_register_ldisc - install a line discipline 692 * tty_register_ldisc - install a line discipline
@@ -700,17 +705,17 @@ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
700{ 705{
701 unsigned long flags; 706 unsigned long flags;
702 int ret = 0; 707 int ret = 0;
703 708
704 if (disc < N_TTY || disc >= NR_LDISCS) 709 if (disc < N_TTY || disc >= NR_LDISCS)
705 return -EINVAL; 710 return -EINVAL;
706 711
707 spin_lock_irqsave(&tty_ldisc_lock, flags); 712 spin_lock_irqsave(&tty_ldisc_lock, flags);
708 tty_ldiscs[disc] = *new_ldisc; 713 tty_ldiscs[disc] = *new_ldisc;
709 tty_ldiscs[disc].num = disc; 714 tty_ldiscs[disc].num = disc;
710 tty_ldiscs[disc].flags |= LDISC_FLAG_DEFINED; 715 tty_ldiscs[disc].flags |= LDISC_FLAG_DEFINED;
711 tty_ldiscs[disc].refcount = 0; 716 tty_ldiscs[disc].refcount = 0;
712 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 717 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
713 718
714 return ret; 719 return ret;
715} 720}
716EXPORT_SYMBOL(tty_register_ldisc); 721EXPORT_SYMBOL(tty_register_ldisc);
@@ -766,20 +771,18 @@ struct tty_ldisc *tty_ldisc_get(int disc)
766 771
767 if (disc < N_TTY || disc >= NR_LDISCS) 772 if (disc < N_TTY || disc >= NR_LDISCS)
768 return NULL; 773 return NULL;
769 774
770 spin_lock_irqsave(&tty_ldisc_lock, flags); 775 spin_lock_irqsave(&tty_ldisc_lock, flags);
771 776
772 ld = &tty_ldiscs[disc]; 777 ld = &tty_ldiscs[disc];
773 /* Check the entry is defined */ 778 /* Check the entry is defined */
774 if(ld->flags & LDISC_FLAG_DEFINED) 779 if (ld->flags & LDISC_FLAG_DEFINED) {
775 {
776 /* If the module is being unloaded we can't use it */ 780 /* If the module is being unloaded we can't use it */
777 if (!try_module_get(ld->owner)) 781 if (!try_module_get(ld->owner))
778 ld = NULL; 782 ld = NULL;
779 else /* lock it */ 783 else /* lock it */
780 ld->refcount++; 784 ld->refcount++;
781 } 785 } else
782 else
783 ld = NULL; 786 ld = NULL;
784 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 787 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
785 return ld; 788 return ld;
@@ -802,9 +805,9 @@ void tty_ldisc_put(int disc)
802{ 805{
803 struct tty_ldisc *ld; 806 struct tty_ldisc *ld;
804 unsigned long flags; 807 unsigned long flags;
805 808
806 BUG_ON(disc < N_TTY || disc >= NR_LDISCS); 809 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
807 810
808 spin_lock_irqsave(&tty_ldisc_lock, flags); 811 spin_lock_irqsave(&tty_ldisc_lock, flags);
809 ld = &tty_ldiscs[disc]; 812 ld = &tty_ldiscs[disc];
810 BUG_ON(ld->refcount == 0); 813 BUG_ON(ld->refcount == 0);
@@ -812,7 +815,7 @@ void tty_ldisc_put(int disc)
812 module_put(ld->owner); 815 module_put(ld->owner);
813 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 816 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
814} 817}
815 818
816EXPORT_SYMBOL_GPL(tty_ldisc_put); 819EXPORT_SYMBOL_GPL(tty_ldisc_put);
817 820
818/** 821/**
@@ -851,11 +854,10 @@ static int tty_ldisc_try(struct tty_struct *tty)
851 unsigned long flags; 854 unsigned long flags;
852 struct tty_ldisc *ld; 855 struct tty_ldisc *ld;
853 int ret = 0; 856 int ret = 0;
854 857
855 spin_lock_irqsave(&tty_ldisc_lock, flags); 858 spin_lock_irqsave(&tty_ldisc_lock, flags);
856 ld = &tty->ldisc; 859 ld = &tty->ldisc;
857 if(test_bit(TTY_LDISC, &tty->flags)) 860 if (test_bit(TTY_LDISC, &tty->flags)) {
858 {
859 ld->refcount++; 861 ld->refcount++;
860 ret = 1; 862 ret = 1;
861 } 863 }
@@ -867,8 +869,8 @@ static int tty_ldisc_try(struct tty_struct *tty)
867 * tty_ldisc_ref_wait - wait for the tty ldisc 869 * tty_ldisc_ref_wait - wait for the tty ldisc
868 * @tty: tty device 870 * @tty: tty device
869 * 871 *
870 * Dereference the line discipline for the terminal and take a 872 * Dereference the line discipline for the terminal and take a
871 * reference to it. If the line discipline is in flux then 873 * reference to it. If the line discipline is in flux then
872 * wait patiently until it changes. 874 * wait patiently until it changes.
873 * 875 *
874 * Note: Must not be called from an IRQ/timer context. The caller 876 * Note: Must not be called from an IRQ/timer context. The caller
@@ -878,12 +880,12 @@ static int tty_ldisc_try(struct tty_struct *tty)
878 * 880 *
879 * Locking: call functions take tty_ldisc_lock 881 * Locking: call functions take tty_ldisc_lock
880 */ 882 */
881 883
882struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) 884struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
883{ 885{
884 /* wait_event is a macro */ 886 /* wait_event is a macro */
885 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); 887 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
886 if(tty->ldisc.refcount == 0) 888 if (tty->ldisc.refcount == 0)
887 printk(KERN_ERR "tty_ldisc_ref_wait\n"); 889 printk(KERN_ERR "tty_ldisc_ref_wait\n");
888 return &tty->ldisc; 890 return &tty->ldisc;
889} 891}
@@ -894,16 +896,16 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
894 * tty_ldisc_ref - get the tty ldisc 896 * tty_ldisc_ref - get the tty ldisc
895 * @tty: tty device 897 * @tty: tty device
896 * 898 *
897 * Dereference the line discipline for the terminal and take a 899 * Dereference the line discipline for the terminal and take a
898 * reference to it. If the line discipline is in flux then 900 * reference to it. If the line discipline is in flux then
899 * return NULL. Can be called from IRQ and timer functions. 901 * return NULL. Can be called from IRQ and timer functions.
900 * 902 *
901 * Locking: called functions take tty_ldisc_lock 903 * Locking: called functions take tty_ldisc_lock
902 */ 904 */
903 905
904struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) 906struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
905{ 907{
906 if(tty_ldisc_try(tty)) 908 if (tty_ldisc_try(tty))
907 return &tty->ldisc; 909 return &tty->ldisc;
908 return NULL; 910 return NULL;
909} 911}
@@ -919,19 +921,19 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref);
919 * 921 *
920 * Locking: takes tty_ldisc_lock 922 * Locking: takes tty_ldisc_lock
921 */ 923 */
922 924
923void tty_ldisc_deref(struct tty_ldisc *ld) 925void tty_ldisc_deref(struct tty_ldisc *ld)
924{ 926{
925 unsigned long flags; 927 unsigned long flags;
926 928
927 BUG_ON(ld == NULL); 929 BUG_ON(ld == NULL);
928 930
929 spin_lock_irqsave(&tty_ldisc_lock, flags); 931 spin_lock_irqsave(&tty_ldisc_lock, flags);
930 if(ld->refcount == 0) 932 if (ld->refcount == 0)
931 printk(KERN_ERR "tty_ldisc_deref: no references.\n"); 933 printk(KERN_ERR "tty_ldisc_deref: no references.\n");
932 else 934 else
933 ld->refcount--; 935 ld->refcount--;
934 if(ld->refcount == 0) 936 if (ld->refcount == 0)
935 wake_up(&tty_ldisc_wait); 937 wake_up(&tty_ldisc_wait);
936 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 938 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
937} 939}
@@ -954,7 +956,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
954 set_bit(TTY_LDISC, &tty->flags); 956 set_bit(TTY_LDISC, &tty->flags);
955 wake_up(&tty_ldisc_wait); 957 wake_up(&tty_ldisc_wait);
956} 958}
957 959
958/** 960/**
959 * tty_set_ldisc - set line discipline 961 * tty_set_ldisc - set line discipline
960 * @tty: the terminal to set 962 * @tty: the terminal to set
@@ -966,7 +968,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
966 * Locking: takes tty_ldisc_lock. 968 * Locking: takes tty_ldisc_lock.
967 * called functions take termios_mutex 969 * called functions take termios_mutex
968 */ 970 */
969 971
970static int tty_set_ldisc(struct tty_struct *tty, int ldisc) 972static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
971{ 973{
972 int retval = 0; 974 int retval = 0;
@@ -1022,7 +1024,7 @@ restart:
1022 1024
1023 spin_lock_irqsave(&tty_ldisc_lock, flags); 1025 spin_lock_irqsave(&tty_ldisc_lock, flags);
1024 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { 1026 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
1025 if(tty->ldisc.refcount) { 1027 if (tty->ldisc.refcount) {
1026 /* Free the new ldisc we grabbed. Must drop the lock 1028 /* Free the new ldisc we grabbed. Must drop the lock
1027 first. */ 1029 first. */
1028 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 1030 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
@@ -1031,14 +1033,14 @@ restart:
1031 * There are several reasons we may be busy, including 1033 * There are several reasons we may be busy, including
1032 * random momentary I/O traffic. We must therefore 1034 * random momentary I/O traffic. We must therefore
1033 * retry. We could distinguish between blocking ops 1035 * retry. We could distinguish between blocking ops
1034 * and retries if we made tty_ldisc_wait() smarter. That 1036 * and retries if we made tty_ldisc_wait() smarter.
1035 * is up for discussion. 1037 * That is up for discussion.
1036 */ 1038 */
1037 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) 1039 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
1038 return -ERESTARTSYS; 1040 return -ERESTARTSYS;
1039 goto restart; 1041 goto restart;
1040 } 1042 }
1041 if(o_tty && o_tty->ldisc.refcount) { 1043 if (o_tty && o_tty->ldisc.refcount) {
1042 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 1044 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1043 tty_ldisc_put(ldisc); 1045 tty_ldisc_put(ldisc);
1044 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0) 1046 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
@@ -1046,9 +1048,10 @@ restart:
1046 goto restart; 1048 goto restart;
1047 } 1049 }
1048 } 1050 }
1049 1051 /*
1050 /* if the TTY_LDISC bit is set, then we are racing against another ldisc change */ 1052 * If the TTY_LDISC bit is set, then we are racing against
1051 1053 * another ldisc change
1054 */
1052 if (!test_bit(TTY_LDISC, &tty->flags)) { 1055 if (!test_bit(TTY_LDISC, &tty->flags)) {
1053 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 1056 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
1054 tty_ldisc_put(ldisc); 1057 tty_ldisc_put(ldisc);
@@ -1072,7 +1075,6 @@ restart:
1072 /* 1075 /*
1073 * Wait for ->hangup_work and ->buf.work handlers to terminate 1076 * Wait for ->hangup_work and ->buf.work handlers to terminate
1074 */ 1077 */
1075
1076 flush_scheduled_work(); 1078 flush_scheduled_work();
1077 /* Shutdown the current discipline. */ 1079 /* Shutdown the current discipline. */
1078 if (tty->ldisc.close) 1080 if (tty->ldisc.close)
@@ -1106,21 +1108,21 @@ restart:
1106 /* At this point we hold a reference to the new ldisc and a 1108 /* At this point we hold a reference to the new ldisc and a
1107 a reference to the old ldisc. If we ended up flipping back 1109 a reference to the old ldisc. If we ended up flipping back
1108 to the existing ldisc we have two references to it */ 1110 to the existing ldisc we have two references to it */
1109 1111
1110 if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) 1112 if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc)
1111 tty->driver->set_ldisc(tty); 1113 tty->driver->set_ldisc(tty);
1112 1114
1113 tty_ldisc_put(o_ldisc.num); 1115 tty_ldisc_put(o_ldisc.num);
1114 1116
1115 /* 1117 /*
1116 * Allow ldisc referencing to occur as soon as the driver 1118 * Allow ldisc referencing to occur as soon as the driver
1117 * ldisc callback completes. 1119 * ldisc callback completes.
1118 */ 1120 */
1119 1121
1120 tty_ldisc_enable(tty); 1122 tty_ldisc_enable(tty);
1121 if (o_tty) 1123 if (o_tty)
1122 tty_ldisc_enable(o_tty); 1124 tty_ldisc_enable(o_tty);
1123 1125
1124 /* Restart it in case no characters kick it off. Safe if 1126 /* Restart it in case no characters kick it off. Safe if
1125 already running */ 1127 already running */
1126 if (work) 1128 if (work)
@@ -1164,7 +1166,7 @@ static struct tty_driver *get_tty_driver(dev_t device, int *index)
1164 * Locking: none 1166 * Locking: none
1165 */ 1167 */
1166 1168
1167int tty_check_change(struct tty_struct * tty) 1169int tty_check_change(struct tty_struct *tty)
1168{ 1170{
1169 if (current->signal->tty != tty) 1171 if (current->signal->tty != tty)
1170 return 0; 1172 return 0;
@@ -1185,31 +1187,31 @@ int tty_check_change(struct tty_struct * tty)
1185 1187
1186EXPORT_SYMBOL(tty_check_change); 1188EXPORT_SYMBOL(tty_check_change);
1187 1189
1188static ssize_t hung_up_tty_read(struct file * file, char __user * buf, 1190static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
1189 size_t count, loff_t *ppos) 1191 size_t count, loff_t *ppos)
1190{ 1192{
1191 return 0; 1193 return 0;
1192} 1194}
1193 1195
1194static ssize_t hung_up_tty_write(struct file * file, const char __user * buf, 1196static ssize_t hung_up_tty_write(struct file *file, const char __user *buf,
1195 size_t count, loff_t *ppos) 1197 size_t count, loff_t *ppos)
1196{ 1198{
1197 return -EIO; 1199 return -EIO;
1198} 1200}
1199 1201
1200/* No kernel lock held - none needed ;) */ 1202/* No kernel lock held - none needed ;) */
1201static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait) 1203static unsigned int hung_up_tty_poll(struct file *filp, poll_table *wait)
1202{ 1204{
1203 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; 1205 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
1204} 1206}
1205 1207
1206static int hung_up_tty_ioctl(struct inode * inode, struct file * file, 1208static int hung_up_tty_ioctl(struct inode *inode, struct file *file,
1207 unsigned int cmd, unsigned long arg) 1209 unsigned int cmd, unsigned long arg)
1208{ 1210{
1209 return cmd == TIOCSPGRP ? -ENOTTY : -EIO; 1211 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
1210} 1212}
1211 1213
1212static long hung_up_tty_compat_ioctl(struct file * file, 1214static long hung_up_tty_compat_ioctl(struct file *file,
1213 unsigned int cmd, unsigned long arg) 1215 unsigned int cmd, unsigned long arg)
1214{ 1216{
1215 return cmd == TIOCSPGRP ? -ENOTTY : -EIO; 1217 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
@@ -1274,15 +1276,15 @@ static struct file *redirect;
1274 * informs the line discipline if present that the driver is ready 1276 * informs the line discipline if present that the driver is ready
1275 * to receive more output data. 1277 * to receive more output data.
1276 */ 1278 */
1277 1279
1278void tty_wakeup(struct tty_struct *tty) 1280void tty_wakeup(struct tty_struct *tty)
1279{ 1281{
1280 struct tty_ldisc *ld; 1282 struct tty_ldisc *ld;
1281 1283
1282 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { 1284 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) {
1283 ld = tty_ldisc_ref(tty); 1285 ld = tty_ldisc_ref(tty);
1284 if(ld) { 1286 if (ld) {
1285 if(ld->write_wakeup) 1287 if (ld->write_wakeup)
1286 ld->write_wakeup(tty); 1288 ld->write_wakeup(tty);
1287 tty_ldisc_deref(ld); 1289 tty_ldisc_deref(ld);
1288 } 1290 }
@@ -1299,12 +1301,12 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
1299 * Flush the line discipline queue (if any) for this tty. If there 1301 * Flush the line discipline queue (if any) for this tty. If there
1300 * is no line discipline active this is a no-op. 1302 * is no line discipline active this is a no-op.
1301 */ 1303 */
1302 1304
1303void tty_ldisc_flush(struct tty_struct *tty) 1305void tty_ldisc_flush(struct tty_struct *tty)
1304{ 1306{
1305 struct tty_ldisc *ld = tty_ldisc_ref(tty); 1307 struct tty_ldisc *ld = tty_ldisc_ref(tty);
1306 if(ld) { 1308 if (ld) {
1307 if(ld->flush_buffer) 1309 if (ld->flush_buffer)
1308 ld->flush_buffer(tty); 1310 ld->flush_buffer(tty);
1309 tty_ldisc_deref(ld); 1311 tty_ldisc_deref(ld);
1310 } 1312 }
@@ -1328,7 +1330,7 @@ static void tty_reset_termios(struct tty_struct *tty)
1328 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); 1330 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1329 mutex_unlock(&tty->termios_mutex); 1331 mutex_unlock(&tty->termios_mutex);
1330} 1332}
1331 1333
1332/** 1334/**
1333 * do_tty_hangup - actual handler for hangup events 1335 * do_tty_hangup - actual handler for hangup events
1334 * @work: tty device 1336 * @work: tty device
@@ -1355,7 +1357,7 @@ static void do_tty_hangup(struct work_struct *work)
1355{ 1357{
1356 struct tty_struct *tty = 1358 struct tty_struct *tty =
1357 container_of(work, struct tty_struct, hangup_work); 1359 container_of(work, struct tty_struct, hangup_work);
1358 struct file * cons_filp = NULL; 1360 struct file *cons_filp = NULL;
1359 struct file *filp, *f = NULL; 1361 struct file *filp, *f = NULL;
1360 struct task_struct *p; 1362 struct task_struct *p;
1361 struct tty_ldisc *ld; 1363 struct tty_ldisc *ld;
@@ -1373,7 +1375,7 @@ static void do_tty_hangup(struct work_struct *work)
1373 redirect = NULL; 1375 redirect = NULL;
1374 } 1376 }
1375 spin_unlock(&redirect_lock); 1377 spin_unlock(&redirect_lock);
1376 1378
1377 check_tty_count(tty, "do_tty_hangup"); 1379 check_tty_count(tty, "do_tty_hangup");
1378 file_list_lock(); 1380 file_list_lock();
1379 /* This breaks for file handles being sent over AF_UNIX sockets ? */ 1381 /* This breaks for file handles being sent over AF_UNIX sockets ? */
@@ -1387,13 +1389,14 @@ static void do_tty_hangup(struct work_struct *work)
1387 filp->f_op = &hung_up_tty_fops; 1389 filp->f_op = &hung_up_tty_fops;
1388 } 1390 }
1389 file_list_unlock(); 1391 file_list_unlock();
1390 1392 /*
1391 /* FIXME! What are the locking issues here? This may me overdoing things.. 1393 * FIXME! What are the locking issues here? This may me overdoing
1392 * this question is especially important now that we've removed the irqlock. */ 1394 * things... This question is especially important now that we've
1393 1395 * removed the irqlock.
1396 */
1394 ld = tty_ldisc_ref(tty); 1397 ld = tty_ldisc_ref(tty);
1395 if(ld != NULL) /* We may have no line discipline at this point */ 1398 if (ld != NULL) {
1396 { 1399 /* We may have no line discipline at this point */
1397 if (ld->flush_buffer) 1400 if (ld->flush_buffer)
1398 ld->flush_buffer(tty); 1401 ld->flush_buffer(tty);
1399 if (tty->driver->flush_buffer) 1402 if (tty->driver->flush_buffer)
@@ -1404,26 +1407,24 @@ static void do_tty_hangup(struct work_struct *work)
1404 if (ld->hangup) 1407 if (ld->hangup)
1405 ld->hangup(tty); 1408 ld->hangup(tty);
1406 } 1409 }
1407 1410 /*
1408 /* FIXME: Once we trust the LDISC code better we can wait here for 1411 * FIXME: Once we trust the LDISC code better we can wait here for
1409 ldisc completion and fix the driver call race */ 1412 * ldisc completion and fix the driver call race
1410 1413 */
1411 wake_up_interruptible(&tty->write_wait); 1414 wake_up_interruptible(&tty->write_wait);
1412 wake_up_interruptible(&tty->read_wait); 1415 wake_up_interruptible(&tty->read_wait);
1413
1414 /* 1416 /*
1415 * Shutdown the current line discipline, and reset it to 1417 * Shutdown the current line discipline, and reset it to
1416 * N_TTY. 1418 * N_TTY.
1417 */ 1419 */
1418 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1420 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
1419 tty_reset_termios(tty); 1421 tty_reset_termios(tty);
1420
1421 /* Defer ldisc switch */ 1422 /* Defer ldisc switch */
1422 /* tty_deferred_ldisc_switch(N_TTY); 1423 /* tty_deferred_ldisc_switch(N_TTY);
1423 1424
1424 This should get done automatically when the port closes and 1425 This should get done automatically when the port closes and
1425 tty_release is called */ 1426 tty_release is called */
1426 1427
1427 read_lock(&tasklist_lock); 1428 read_lock(&tasklist_lock);
1428 if (tty->session) { 1429 if (tty->session) {
1429 do_each_pid_task(tty->session, PIDTYPE_SID, p) { 1430 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
@@ -1451,10 +1452,10 @@ static void do_tty_hangup(struct work_struct *work)
1451 tty->pgrp = NULL; 1452 tty->pgrp = NULL;
1452 tty->ctrl_status = 0; 1453 tty->ctrl_status = 0;
1453 /* 1454 /*
1454 * If one of the devices matches a console pointer, we 1455 * If one of the devices matches a console pointer, we
1455 * cannot just call hangup() because that will cause 1456 * cannot just call hangup() because that will cause
1456 * tty->count and state->count to go out of sync. 1457 * tty->count and state->count to go out of sync.
1457 * So we just call close() the right number of times. 1458 * So we just call close() the right number of times.
1458 */ 1459 */
1459 if (cons_filp) { 1460 if (cons_filp) {
1460 if (tty->driver->close) 1461 if (tty->driver->close)
@@ -1462,12 +1463,12 @@ static void do_tty_hangup(struct work_struct *work)
1462 tty->driver->close(tty, cons_filp); 1463 tty->driver->close(tty, cons_filp);
1463 } else if (tty->driver->hangup) 1464 } else if (tty->driver->hangup)
1464 (tty->driver->hangup)(tty); 1465 (tty->driver->hangup)(tty);
1465 1466 /*
1466 /* We don't want to have driver/ldisc interactions beyond 1467 * We don't want to have driver/ldisc interactions beyond
1467 the ones we did here. The driver layer expects no 1468 * the ones we did here. The driver layer expects no
1468 calls after ->hangup() from the ldisc side. However we 1469 * calls after ->hangup() from the ldisc side. However we
1469 can't yet guarantee all that */ 1470 * can't yet guarantee all that.
1470 1471 */
1471 set_bit(TTY_HUPPED, &tty->flags); 1472 set_bit(TTY_HUPPED, &tty->flags);
1472 if (ld) { 1473 if (ld) {
1473 tty_ldisc_enable(tty); 1474 tty_ldisc_enable(tty);
@@ -1486,11 +1487,10 @@ static void do_tty_hangup(struct work_struct *work)
1486 * schedule a hangup sequence to run after this event. 1487 * schedule a hangup sequence to run after this event.
1487 */ 1488 */
1488 1489
1489void tty_hangup(struct tty_struct * tty) 1490void tty_hangup(struct tty_struct *tty)
1490{ 1491{
1491#ifdef TTY_DEBUG_HANGUP 1492#ifdef TTY_DEBUG_HANGUP
1492 char buf[64]; 1493 char buf[64];
1493
1494 printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf)); 1494 printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf));
1495#endif 1495#endif
1496 schedule_work(&tty->hangup_work); 1496 schedule_work(&tty->hangup_work);
@@ -1507,7 +1507,7 @@ EXPORT_SYMBOL(tty_hangup);
1507 * is complete. That guarantee is necessary for security reasons. 1507 * is complete. That guarantee is necessary for security reasons.
1508 */ 1508 */
1509 1509
1510void tty_vhangup(struct tty_struct * tty) 1510void tty_vhangup(struct tty_struct *tty)
1511{ 1511{
1512#ifdef TTY_DEBUG_HANGUP 1512#ifdef TTY_DEBUG_HANGUP
1513 char buf[64]; 1513 char buf[64];
@@ -1516,6 +1516,7 @@ void tty_vhangup(struct tty_struct * tty)
1516#endif 1516#endif
1517 do_tty_hangup(&tty->hangup_work); 1517 do_tty_hangup(&tty->hangup_work);
1518} 1518}
1519
1519EXPORT_SYMBOL(tty_vhangup); 1520EXPORT_SYMBOL(tty_vhangup);
1520 1521
1521/** 1522/**
@@ -1526,7 +1527,7 @@ EXPORT_SYMBOL(tty_vhangup);
1526 * loss 1527 * loss
1527 */ 1528 */
1528 1529
1529int tty_hung_up_p(struct file * filp) 1530int tty_hung_up_p(struct file *filp)
1530{ 1531{
1531 return (filp->f_op == &hung_up_tty_fops); 1532 return (filp->f_op == &hung_up_tty_fops);
1532} 1533}
@@ -1534,8 +1535,12 @@ int tty_hung_up_p(struct file * filp)
1534EXPORT_SYMBOL(tty_hung_up_p); 1535EXPORT_SYMBOL(tty_hung_up_p);
1535 1536
1536/** 1537/**
1537 * is_tty - checker whether file is a TTY 1538 * is_tty - checker whether file is a TTY
1539 * @filp: file handle that may be a tty
1540 *
1541 * Check if the file handle is a tty handle.
1538 */ 1542 */
1543
1539int is_tty(struct file *filp) 1544int is_tty(struct file *filp)
1540{ 1545{
1541 return filp->f_op->read == tty_read 1546 return filp->f_op->read == tty_read
@@ -1601,7 +1606,7 @@ void disassociate_ctty(int on_exit)
1601 put_pid(old_pgrp); 1606 put_pid(old_pgrp);
1602 } 1607 }
1603 mutex_unlock(&tty_mutex); 1608 mutex_unlock(&tty_mutex);
1604 unlock_kernel(); 1609 unlock_kernel();
1605 return; 1610 return;
1606 } 1611 }
1607 if (tty_pgrp) { 1612 if (tty_pgrp) {
@@ -1711,7 +1716,6 @@ void start_tty(struct tty_struct *tty)
1711 } 1716 }
1712 if (tty->driver->start) 1717 if (tty->driver->start)
1713 (tty->driver->start)(tty); 1718 (tty->driver->start)(tty);
1714
1715 /* If we have a running line discipline it may need kicking */ 1719 /* If we have a running line discipline it may need kicking */
1716 tty_wakeup(tty); 1720 tty_wakeup(tty);
1717} 1721}
@@ -1735,11 +1739,11 @@ EXPORT_SYMBOL(start_tty);
1735 * in new code. Multiple read calls may be outstanding in parallel. 1739 * in new code. Multiple read calls may be outstanding in parallel.
1736 */ 1740 */
1737 1741
1738static ssize_t tty_read(struct file * file, char __user * buf, size_t count, 1742static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
1739 loff_t *ppos) 1743 loff_t *ppos)
1740{ 1744{
1741 int i; 1745 int i;
1742 struct tty_struct * tty; 1746 struct tty_struct *tty;
1743 struct inode *inode; 1747 struct inode *inode;
1744 struct tty_ldisc *ld; 1748 struct tty_ldisc *ld;
1745 1749
@@ -1755,7 +1759,7 @@ static ssize_t tty_read(struct file * file, char __user * buf, size_t count,
1755 ld = tty_ldisc_ref_wait(tty); 1759 ld = tty_ldisc_ref_wait(tty);
1756 lock_kernel(); 1760 lock_kernel();
1757 if (ld->read) 1761 if (ld->read)
1758 i = (ld->read)(tty,file,buf,count); 1762 i = (ld->read)(tty, file, buf, count);
1759 else 1763 else
1760 i = -EIO; 1764 i = -EIO;
1761 tty_ldisc_deref(ld); 1765 tty_ldisc_deref(ld);
@@ -1795,7 +1799,7 @@ static inline ssize_t do_tty_write(
1795{ 1799{
1796 ssize_t ret, written = 0; 1800 ssize_t ret, written = 0;
1797 unsigned int chunk; 1801 unsigned int chunk;
1798 1802
1799 ret = tty_write_lock(tty, file->f_flags & O_NDELAY); 1803 ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
1800 if (ret < 0) 1804 if (ret < 0)
1801 return ret; 1805 return ret;
@@ -1891,21 +1895,22 @@ out:
1891 * kernel lock for historical reasons. New code should not rely on this. 1895 * kernel lock for historical reasons. New code should not rely on this.
1892 */ 1896 */
1893 1897
1894static ssize_t tty_write(struct file * file, const char __user * buf, size_t count, 1898static ssize_t tty_write(struct file *file, const char __user *buf,
1895 loff_t *ppos) 1899 size_t count, loff_t *ppos)
1896{ 1900{
1897 struct tty_struct * tty; 1901 struct tty_struct *tty;
1898 struct inode *inode = file->f_path.dentry->d_inode; 1902 struct inode *inode = file->f_path.dentry->d_inode;
1899 ssize_t ret; 1903 ssize_t ret;
1900 struct tty_ldisc *ld; 1904 struct tty_ldisc *ld;
1901 1905
1902 tty = (struct tty_struct *)file->private_data; 1906 tty = (struct tty_struct *)file->private_data;
1903 if (tty_paranoia_check(tty, inode, "tty_write")) 1907 if (tty_paranoia_check(tty, inode, "tty_write"))
1904 return -EIO; 1908 return -EIO;
1905 if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags))) 1909 if (!tty || !tty->driver->write ||
1906 return -EIO; 1910 (test_bit(TTY_IO_ERROR, &tty->flags)))
1911 return -EIO;
1907 1912
1908 ld = tty_ldisc_ref_wait(tty); 1913 ld = tty_ldisc_ref_wait(tty);
1909 if (!ld->write) 1914 if (!ld->write)
1910 ret = -EIO; 1915 ret = -EIO;
1911 else 1916 else
@@ -1914,8 +1919,8 @@ static ssize_t tty_write(struct file * file, const char __user * buf, size_t cou
1914 return ret; 1919 return ret;
1915} 1920}
1916 1921
1917ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t count, 1922ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1918 loff_t *ppos) 1923 size_t count, loff_t *ppos)
1919{ 1924{
1920 struct file *p = NULL; 1925 struct file *p = NULL;
1921 1926
@@ -1932,7 +1937,6 @@ ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t
1932 fput(p); 1937 fput(p);
1933 return res; 1938 return res;
1934 } 1939 }
1935
1936 return tty_write(file, buf, count, ppos); 1940 return tty_write(file, buf, count, ppos);
1937} 1941}
1938 1942
@@ -1954,8 +1958,8 @@ static void pty_line_name(struct tty_driver *driver, int index, char *p)
1954 int i = index + driver->name_base; 1958 int i = index + driver->name_base;
1955 /* ->name is initialized to "ttyp", but "tty" is expected */ 1959 /* ->name is initialized to "ttyp", but "tty" is expected */
1956 sprintf(p, "%s%c%x", 1960 sprintf(p, "%s%c%x",
1957 driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name, 1961 driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name,
1958 ptychar[i >> 4 & 0xf], i & 0xf); 1962 ptychar[i >> 4 & 0xf], i & 0xf);
1959} 1963}
1960 1964
1961/** 1965/**
@@ -2034,7 +2038,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2034 * First time open is complex, especially for PTY devices. 2038 * First time open is complex, especially for PTY devices.
2035 * This code guarantees that either everything succeeds and the 2039 * This code guarantees that either everything succeeds and the
2036 * TTY is ready for operation, or else the table slots are vacated 2040 * TTY is ready for operation, or else the table slots are vacated
2037 * and the allocated memory released. (Except that the termios 2041 * and the allocated memory released. (Except that the termios
2038 * and locked termios may be retained.) 2042 * and locked termios may be retained.)
2039 */ 2043 */
2040 2044
@@ -2048,7 +2052,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2048 ltp = o_ltp = NULL; 2052 ltp = o_ltp = NULL;
2049 2053
2050 tty = alloc_tty_struct(); 2054 tty = alloc_tty_struct();
2051 if(!tty) 2055 if (!tty)
2052 goto fail_no_mem; 2056 goto fail_no_mem;
2053 initialize_tty_struct(tty); 2057 initialize_tty_struct(tty);
2054 tty->driver = driver; 2058 tty->driver = driver;
@@ -2109,9 +2113,8 @@ static int init_dev(struct tty_driver *driver, int idx,
2109 /* 2113 /*
2110 * Everything allocated ... set up the o_tty structure. 2114 * Everything allocated ... set up the o_tty structure.
2111 */ 2115 */
2112 if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM)) { 2116 if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM))
2113 driver->other->ttys[idx] = o_tty; 2117 driver->other->ttys[idx] = o_tty;
2114 }
2115 if (!*o_tp_loc) 2118 if (!*o_tp_loc)
2116 *o_tp_loc = o_tp; 2119 *o_tp_loc = o_tp;
2117 if (!*o_ltp_loc) 2120 if (!*o_ltp_loc)
@@ -2127,15 +2130,14 @@ static int init_dev(struct tty_driver *driver, int idx,
2127 o_tty->link = tty; 2130 o_tty->link = tty;
2128 } 2131 }
2129 2132
2130 /* 2133 /*
2131 * All structures have been allocated, so now we install them. 2134 * All structures have been allocated, so now we install them.
2132 * Failures after this point use release_tty to clean up, so 2135 * Failures after this point use release_tty to clean up, so
2133 * there's no need to null out the local pointers. 2136 * there's no need to null out the local pointers.
2134 */ 2137 */
2135 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 2138 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM))
2136 driver->ttys[idx] = tty; 2139 driver->ttys[idx] = tty;
2137 } 2140
2138
2139 if (!*tp_loc) 2141 if (!*tp_loc)
2140 *tp_loc = tp; 2142 *tp_loc = tp;
2141 if (!*ltp_loc) 2143 if (!*ltp_loc)
@@ -2148,7 +2150,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2148 driver->refcount++; 2150 driver->refcount++;
2149 tty->count++; 2151 tty->count++;
2150 2152
2151 /* 2153 /*
2152 * Structures all installed ... call the ldisc open routines. 2154 * Structures all installed ... call the ldisc open routines.
2153 * If we fail here just call release_tty to clean up. No need 2155 * If we fail here just call release_tty to clean up. No need
2154 * to decrement the use counts, as release_tty doesn't care. 2156 * to decrement the use counts, as release_tty doesn't care.
@@ -2185,7 +2187,7 @@ fast_track:
2185 if (driver->type == TTY_DRIVER_TYPE_PTY && 2187 if (driver->type == TTY_DRIVER_TYPE_PTY &&
2186 driver->subtype == PTY_TYPE_MASTER) { 2188 driver->subtype == PTY_TYPE_MASTER) {
2187 /* 2189 /*
2188 * special case for PTY masters: only one open permitted, 2190 * special case for PTY masters: only one open permitted,
2189 * and the slave side open count is incremented as well. 2191 * and the slave side open count is incremented as well.
2190 */ 2192 */
2191 if (tty->count) { 2193 if (tty->count) {
@@ -2198,11 +2200,11 @@ fast_track:
2198 tty->driver = driver; /* N.B. why do this every time?? */ 2200 tty->driver = driver; /* N.B. why do this every time?? */
2199 2201
2200 /* FIXME */ 2202 /* FIXME */
2201 if(!test_bit(TTY_LDISC, &tty->flags)) 2203 if (!test_bit(TTY_LDISC, &tty->flags))
2202 printk(KERN_ERR "init_dev but no ldisc\n"); 2204 printk(KERN_ERR "init_dev but no ldisc\n");
2203success: 2205success:
2204 *ret_tty = tty; 2206 *ret_tty = tty;
2205 2207
2206 /* All paths come through here to release the mutex */ 2208 /* All paths come through here to release the mutex */
2207end_init: 2209end_init:
2208 return retval; 2210 return retval;
@@ -2304,7 +2306,7 @@ static void release_tty(struct tty_struct *tty, int idx)
2304 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could 2306 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could
2305 * lead to double frees or releasing memory still in use. 2307 * lead to double frees or releasing memory still in use.
2306 */ 2308 */
2307static void release_dev(struct file * filp) 2309static void release_dev(struct file *filp)
2308{ 2310{
2309 struct tty_struct *tty, *o_tty; 2311 struct tty_struct *tty, *o_tty;
2310 int pty_master, tty_closing, o_tty_closing, do_sleep; 2312 int pty_master, tty_closing, o_tty_closing, do_sleep;
@@ -2312,9 +2314,10 @@ static void release_dev(struct file * filp)
2312 int idx; 2314 int idx;
2313 char buf[64]; 2315 char buf[64];
2314 unsigned long flags; 2316 unsigned long flags;
2315 2317
2316 tty = (struct tty_struct *)filp->private_data; 2318 tty = (struct tty_struct *)filp->private_data;
2317 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "release_dev")) 2319 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode,
2320 "release_dev"))
2318 return; 2321 return;
2319 2322
2320 check_tty_count(tty, "release_dev"); 2323 check_tty_count(tty, "release_dev");
@@ -2374,7 +2377,7 @@ static void release_dev(struct file * filp)
2374 idx, tty->name); 2377 idx, tty->name);
2375 return; 2378 return;
2376 } 2379 }
2377 if (o_tty->termios_locked != 2380 if (o_tty->termios_locked !=
2378 tty->driver->other->termios_locked[idx]) { 2381 tty->driver->other->termios_locked[idx]) {
2379 printk(KERN_DEBUG "release_dev: other->termios_locked[" 2382 printk(KERN_DEBUG "release_dev: other->termios_locked["
2380 "%d] not o_termios_locked for (%s)\n", 2383 "%d] not o_termios_locked for (%s)\n",
@@ -2410,7 +2413,7 @@ static void release_dev(struct file * filp)
2410 while (1) { 2413 while (1) {
2411 /* Guard against races with tty->count changes elsewhere and 2414 /* Guard against races with tty->count changes elsewhere and
2412 opens on /dev/tty */ 2415 opens on /dev/tty */
2413 2416
2414 mutex_lock(&tty_mutex); 2417 mutex_lock(&tty_mutex);
2415 tty_closing = tty->count <= 1; 2418 tty_closing = tty->count <= 1;
2416 o_tty_closing = o_tty && 2419 o_tty_closing = o_tty &&
@@ -2444,11 +2447,11 @@ static void release_dev(struct file * filp)
2444 "active!\n", tty_name(tty, buf)); 2447 "active!\n", tty_name(tty, buf));
2445 mutex_unlock(&tty_mutex); 2448 mutex_unlock(&tty_mutex);
2446 schedule(); 2449 schedule();
2447 } 2450 }
2448 2451
2449 /* 2452 /*
2450 * The closing flags are now consistent with the open counts on 2453 * The closing flags are now consistent with the open counts on
2451 * both sides, and we've completed the last operation that could 2454 * both sides, and we've completed the last operation that could
2452 * block, so it's safe to proceed with closing. 2455 * block, so it's safe to proceed with closing.
2453 */ 2456 */
2454 if (pty_master) { 2457 if (pty_master) {
@@ -2464,7 +2467,7 @@ static void release_dev(struct file * filp)
2464 tty->count, tty_name(tty, buf)); 2467 tty->count, tty_name(tty, buf));
2465 tty->count = 0; 2468 tty->count = 0;
2466 } 2469 }
2467 2470
2468 /* 2471 /*
2469 * We've decremented tty->count, so we need to remove this file 2472 * We've decremented tty->count, so we need to remove this file
2470 * descriptor off the tty->tty_files list; this serves two 2473 * descriptor off the tty->tty_files list; this serves two
@@ -2484,9 +2487,9 @@ static void release_dev(struct file * filp)
2484 * case of a pty we may have to wait around for the other side 2487 * case of a pty we may have to wait around for the other side
2485 * to close, and TTY_CLOSING makes sure we can't be reopened. 2488 * to close, and TTY_CLOSING makes sure we can't be reopened.
2486 */ 2489 */
2487 if(tty_closing) 2490 if (tty_closing)
2488 set_bit(TTY_CLOSING, &tty->flags); 2491 set_bit(TTY_CLOSING, &tty->flags);
2489 if(o_tty_closing) 2492 if (o_tty_closing)
2490 set_bit(TTY_CLOSING, &o_tty->flags); 2493 set_bit(TTY_CLOSING, &o_tty->flags);
2491 2494
2492 /* 2495 /*
@@ -2507,7 +2510,7 @@ static void release_dev(struct file * filp)
2507 /* check whether both sides are closing ... */ 2510 /* check whether both sides are closing ... */
2508 if (!tty_closing || (o_tty && !o_tty_closing)) 2511 if (!tty_closing || (o_tty && !o_tty_closing))
2509 return; 2512 return;
2510 2513
2511#ifdef TTY_DEBUG_HANGUP 2514#ifdef TTY_DEBUG_HANGUP
2512 printk(KERN_DEBUG "freeing tty structure..."); 2515 printk(KERN_DEBUG "freeing tty structure...");
2513#endif 2516#endif
@@ -2522,17 +2525,16 @@ static void release_dev(struct file * filp)
2522 /* 2525 /*
2523 * Wait for ->hangup_work and ->buf.work handlers to terminate 2526 * Wait for ->hangup_work and ->buf.work handlers to terminate
2524 */ 2527 */
2525 2528
2526 flush_scheduled_work(); 2529 flush_scheduled_work();
2527 2530
2528 /* 2531 /*
2529 * Wait for any short term users (we know they are just driver 2532 * Wait for any short term users (we know they are just driver
2530 * side waiters as the file is closing so user count on the file 2533 * side waiters as the file is closing so user count on the file
2531 * side is zero. 2534 * side is zero.
2532 */ 2535 */
2533 spin_lock_irqsave(&tty_ldisc_lock, flags); 2536 spin_lock_irqsave(&tty_ldisc_lock, flags);
2534 while(tty->ldisc.refcount) 2537 while (tty->ldisc.refcount) {
2535 {
2536 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 2538 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
2537 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); 2539 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
2538 spin_lock_irqsave(&tty_ldisc_lock, flags); 2540 spin_lock_irqsave(&tty_ldisc_lock, flags);
@@ -2547,12 +2549,12 @@ static void release_dev(struct file * filp)
2547 if (tty->ldisc.close) 2549 if (tty->ldisc.close)
2548 (tty->ldisc.close)(tty); 2550 (tty->ldisc.close)(tty);
2549 tty_ldisc_put(tty->ldisc.num); 2551 tty_ldisc_put(tty->ldisc.num);
2550 2552
2551 /* 2553 /*
2552 * Switch the line discipline back 2554 * Switch the line discipline back
2553 */ 2555 */
2554 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); 2556 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY));
2555 tty_set_termios_ldisc(tty,N_TTY); 2557 tty_set_termios_ldisc(tty, N_TTY);
2556 if (o_tty) { 2558 if (o_tty) {
2557 /* FIXME: could o_tty be in setldisc here ? */ 2559 /* FIXME: could o_tty be in setldisc here ? */
2558 clear_bit(TTY_LDISC, &o_tty->flags); 2560 clear_bit(TTY_LDISC, &o_tty->flags);
@@ -2560,7 +2562,7 @@ static void release_dev(struct file * filp)
2560 (o_tty->ldisc.close)(o_tty); 2562 (o_tty->ldisc.close)(o_tty);
2561 tty_ldisc_put(o_tty->ldisc.num); 2563 tty_ldisc_put(o_tty->ldisc.num);
2562 tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY)); 2564 tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY));
2563 tty_set_termios_ldisc(o_tty,N_TTY); 2565 tty_set_termios_ldisc(o_tty, N_TTY);
2564 } 2566 }
2565 /* 2567 /*
2566 * The release_tty function takes care of the details of clearing 2568 * The release_tty function takes care of the details of clearing
@@ -2600,7 +2602,7 @@ static void release_dev(struct file * filp)
2600 * ->siglock protects ->signal/->sighand 2602 * ->siglock protects ->signal/->sighand
2601 */ 2603 */
2602 2604
2603static int tty_open(struct inode * inode, struct file * filp) 2605static int tty_open(struct inode *inode, struct file *filp)
2604{ 2606{
2605 struct tty_struct *tty; 2607 struct tty_struct *tty;
2606 int noctty, retval; 2608 int noctty, retval;
@@ -2610,15 +2612,15 @@ static int tty_open(struct inode * inode, struct file * filp)
2610 unsigned short saved_flags = filp->f_flags; 2612 unsigned short saved_flags = filp->f_flags;
2611 2613
2612 nonseekable_open(inode, filp); 2614 nonseekable_open(inode, filp);
2613 2615
2614retry_open: 2616retry_open:
2615 noctty = filp->f_flags & O_NOCTTY; 2617 noctty = filp->f_flags & O_NOCTTY;
2616 index = -1; 2618 index = -1;
2617 retval = 0; 2619 retval = 0;
2618 2620
2619 mutex_lock(&tty_mutex); 2621 mutex_lock(&tty_mutex);
2620 2622
2621 if (device == MKDEV(TTYAUX_MAJOR,0)) { 2623 if (device == MKDEV(TTYAUX_MAJOR, 0)) {
2622 tty = get_current_tty(); 2624 tty = get_current_tty();
2623 if (!tty) { 2625 if (!tty) {
2624 mutex_unlock(&tty_mutex); 2626 mutex_unlock(&tty_mutex);
@@ -2631,7 +2633,7 @@ retry_open:
2631 goto got_driver; 2633 goto got_driver;
2632 } 2634 }
2633#ifdef CONFIG_VT 2635#ifdef CONFIG_VT
2634 if (device == MKDEV(TTY_MAJOR,0)) { 2636 if (device == MKDEV(TTY_MAJOR, 0)) {
2635 extern struct tty_driver *console_driver; 2637 extern struct tty_driver *console_driver;
2636 driver = console_driver; 2638 driver = console_driver;
2637 index = fg_console; 2639 index = fg_console;
@@ -2639,7 +2641,7 @@ retry_open:
2639 goto got_driver; 2641 goto got_driver;
2640 } 2642 }
2641#endif 2643#endif
2642 if (device == MKDEV(TTYAUX_MAJOR,1)) { 2644 if (device == MKDEV(TTYAUX_MAJOR, 1)) {
2643 driver = console_device(&index); 2645 driver = console_device(&index);
2644 if (driver) { 2646 if (driver) {
2645 /* Don't let /dev/console block */ 2647 /* Don't let /dev/console block */
@@ -2679,7 +2681,8 @@ got_driver:
2679 } 2681 }
2680 filp->f_flags = saved_flags; 2682 filp->f_flags = saved_flags;
2681 2683
2682 if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) 2684 if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
2685 !capable(CAP_SYS_ADMIN))
2683 retval = -EBUSY; 2686 retval = -EBUSY;
2684 2687
2685 if (retval) { 2688 if (retval) {
@@ -2723,11 +2726,11 @@ got_driver:
2723 * Allocate a unix98 pty master device from the ptmx driver. 2726 * Allocate a unix98 pty master device from the ptmx driver.
2724 * 2727 *
2725 * Locking: tty_mutex protects theinit_dev work. tty->count should 2728 * Locking: tty_mutex protects theinit_dev work. tty->count should
2726 protect the rest. 2729 * protect the rest.
2727 * allocated_ptys_lock handles the list of free pty numbers 2730 * allocated_ptys_lock handles the list of free pty numbers
2728 */ 2731 */
2729 2732
2730static int ptmx_open(struct inode * inode, struct file * filp) 2733static int ptmx_open(struct inode *inode, struct file *filp)
2731{ 2734{
2732 struct tty_struct *tty; 2735 struct tty_struct *tty;
2733 int retval; 2736 int retval;
@@ -2759,7 +2762,7 @@ static int ptmx_open(struct inode * inode, struct file * filp)
2759 mutex_lock(&tty_mutex); 2762 mutex_lock(&tty_mutex);
2760 retval = init_dev(ptm_driver, index, &tty); 2763 retval = init_dev(ptm_driver, index, &tty);
2761 mutex_unlock(&tty_mutex); 2764 mutex_unlock(&tty_mutex);
2762 2765
2763 if (retval) 2766 if (retval)
2764 goto out; 2767 goto out;
2765 2768
@@ -2800,7 +2803,7 @@ out:
2800 * Takes bkl. See release_dev 2803 * Takes bkl. See release_dev
2801 */ 2804 */
2802 2805
2803static int tty_release(struct inode * inode, struct file * filp) 2806static int tty_release(struct inode *inode, struct file *filp)
2804{ 2807{
2805 lock_kernel(); 2808 lock_kernel();
2806 release_dev(filp); 2809 release_dev(filp);
@@ -2820,16 +2823,16 @@ static int tty_release(struct inode * inode, struct file * filp)
2820 * may be re-entered freely by other callers. 2823 * may be re-entered freely by other callers.
2821 */ 2824 */
2822 2825
2823static unsigned int tty_poll(struct file * filp, poll_table * wait) 2826static unsigned int tty_poll(struct file *filp, poll_table *wait)
2824{ 2827{
2825 struct tty_struct * tty; 2828 struct tty_struct *tty;
2826 struct tty_ldisc *ld; 2829 struct tty_ldisc *ld;
2827 int ret = 0; 2830 int ret = 0;
2828 2831
2829 tty = (struct tty_struct *)filp->private_data; 2832 tty = (struct tty_struct *)filp->private_data;
2830 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll")) 2833 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
2831 return 0; 2834 return 0;
2832 2835
2833 ld = tty_ldisc_ref_wait(tty); 2836 ld = tty_ldisc_ref_wait(tty);
2834 if (ld->poll) 2837 if (ld->poll)
2835 ret = (ld->poll)(tty, filp, wait); 2838 ret = (ld->poll)(tty, filp, wait);
@@ -2837,15 +2840,15 @@ static unsigned int tty_poll(struct file * filp, poll_table * wait)
2837 return ret; 2840 return ret;
2838} 2841}
2839 2842
2840static int tty_fasync(int fd, struct file * filp, int on) 2843static int tty_fasync(int fd, struct file *filp, int on)
2841{ 2844{
2842 struct tty_struct * tty; 2845 struct tty_struct *tty;
2843 int retval; 2846 int retval;
2844 2847
2845 tty = (struct tty_struct *)filp->private_data; 2848 tty = (struct tty_struct *)filp->private_data;
2846 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync")) 2849 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
2847 return 0; 2850 return 0;
2848 2851
2849 retval = fasync_helper(fd, filp, on, &tty->fasync); 2852 retval = fasync_helper(fd, filp, on, &tty->fasync);
2850 if (retval <= 0) 2853 if (retval <= 0)
2851 return retval; 2854 return retval;
@@ -2893,7 +2896,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2893{ 2896{
2894 char ch, mbz = 0; 2897 char ch, mbz = 0;
2895 struct tty_ldisc *ld; 2898 struct tty_ldisc *ld;
2896 2899
2897 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) 2900 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2898 return -EPERM; 2901 return -EPERM;
2899 if (get_user(ch, p)) 2902 if (get_user(ch, p))
@@ -2915,7 +2918,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2915 * is consistent. 2918 * is consistent.
2916 */ 2919 */
2917 2920
2918static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg) 2921static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
2919{ 2922{
2920 int err; 2923 int err;
2921 2924
@@ -2944,7 +2947,7 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2944 */ 2947 */
2945 2948
2946static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, 2949static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2947 struct winsize __user * arg) 2950 struct winsize __user *arg)
2948{ 2951{
2949 struct winsize tmp_ws; 2952 struct winsize tmp_ws;
2950 2953
@@ -2960,7 +2963,7 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2960 if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col, 2963 if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col,
2961 tmp_ws.ws_row)) { 2964 tmp_ws.ws_row)) {
2962 mutex_unlock(&tty->termios_mutex); 2965 mutex_unlock(&tty->termios_mutex);
2963 return -ENXIO; 2966 return -ENXIO;
2964 } 2967 }
2965 } 2968 }
2966#endif 2969#endif
@@ -3070,7 +3073,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
3070 * This tty is already the controlling 3073 * This tty is already the controlling
3071 * tty for another session group! 3074 * tty for another session group!
3072 */ 3075 */
3073 if ((arg == 1) && capable(CAP_SYS_ADMIN)) { 3076 if (arg == 1 && capable(CAP_SYS_ADMIN)) {
3074 /* 3077 /*
3075 * Steal it away 3078 * Steal it away
3076 */ 3079 */
@@ -3303,14 +3306,14 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
3303/* 3306/*
3304 * Split this up, as gcc can choke on it otherwise.. 3307 * Split this up, as gcc can choke on it otherwise..
3305 */ 3308 */
3306int tty_ioctl(struct inode * inode, struct file * file, 3309int tty_ioctl(struct inode *inode, struct file *file,
3307 unsigned int cmd, unsigned long arg) 3310 unsigned int cmd, unsigned long arg)
3308{ 3311{
3309 struct tty_struct *tty, *real_tty; 3312 struct tty_struct *tty, *real_tty;
3310 void __user *p = (void __user *)arg; 3313 void __user *p = (void __user *)arg;
3311 int retval; 3314 int retval;
3312 struct tty_ldisc *ld; 3315 struct tty_ldisc *ld;
3313 3316
3314 tty = (struct tty_struct *)file->private_data; 3317 tty = (struct tty_struct *)file->private_data;
3315 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3318 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3316 return -EINVAL; 3319 return -EINVAL;
@@ -3326,13 +3329,13 @@ int tty_ioctl(struct inode * inode, struct file * file,
3326 * Break handling by driver 3329 * Break handling by driver
3327 */ 3330 */
3328 if (!tty->driver->break_ctl) { 3331 if (!tty->driver->break_ctl) {
3329 switch(cmd) { 3332 switch (cmd) {
3330 case TIOCSBRK: 3333 case TIOCSBRK:
3331 case TIOCCBRK: 3334 case TIOCCBRK:
3332 if (tty->driver->ioctl) 3335 if (tty->driver->ioctl)
3333 return tty->driver->ioctl(tty, file, cmd, arg); 3336 return tty->driver->ioctl(tty, file, cmd, arg);
3334 return -EINVAL; 3337 return -EINVAL;
3335 3338
3336 /* These two ioctl's always return success; even if */ 3339 /* These two ioctl's always return success; even if */
3337 /* the driver doesn't support them. */ 3340 /* the driver doesn't support them. */
3338 case TCSBRK: 3341 case TCSBRK:
@@ -3354,7 +3357,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
3354 case TIOCSBRK: 3357 case TIOCSBRK:
3355 case TIOCCBRK: 3358 case TIOCCBRK:
3356 case TCSBRK: 3359 case TCSBRK:
3357 case TCSBRKP: 3360 case TCSBRKP:
3358 retval = tty_check_change(tty); 3361 retval = tty_check_change(tty);
3359 if (retval) 3362 if (retval)
3360 return retval; 3363 return retval;
@@ -3367,81 +3370,80 @@ int tty_ioctl(struct inode * inode, struct file * file,
3367 } 3370 }
3368 3371
3369 switch (cmd) { 3372 switch (cmd) {
3370 case TIOCSTI: 3373 case TIOCSTI:
3371 return tiocsti(tty, p); 3374 return tiocsti(tty, p);
3372 case TIOCGWINSZ: 3375 case TIOCGWINSZ:
3373 return tiocgwinsz(tty, p); 3376 return tiocgwinsz(tty, p);
3374 case TIOCSWINSZ: 3377 case TIOCSWINSZ:
3375 return tiocswinsz(tty, real_tty, p); 3378 return tiocswinsz(tty, real_tty, p);
3376 case TIOCCONS: 3379 case TIOCCONS:
3377 return real_tty!=tty ? -EINVAL : tioccons(file); 3380 return real_tty != tty ? -EINVAL : tioccons(file);
3378 case FIONBIO: 3381 case FIONBIO:
3379 return fionbio(file, p); 3382 return fionbio(file, p);
3380 case TIOCEXCL: 3383 case TIOCEXCL:
3381 set_bit(TTY_EXCLUSIVE, &tty->flags); 3384 set_bit(TTY_EXCLUSIVE, &tty->flags);
3382 return 0; 3385 return 0;
3383 case TIOCNXCL: 3386 case TIOCNXCL:
3384 clear_bit(TTY_EXCLUSIVE, &tty->flags); 3387 clear_bit(TTY_EXCLUSIVE, &tty->flags);
3385 return 0; 3388 return 0;
3386 case TIOCNOTTY: 3389 case TIOCNOTTY:
3387 if (current->signal->tty != tty) 3390 if (current->signal->tty != tty)
3388 return -ENOTTY; 3391 return -ENOTTY;
3389 no_tty(); 3392 no_tty();
3390 return 0; 3393 return 0;
3391 case TIOCSCTTY: 3394 case TIOCSCTTY:
3392 return tiocsctty(tty, arg); 3395 return tiocsctty(tty, arg);
3393 case TIOCGPGRP: 3396 case TIOCGPGRP:
3394 return tiocgpgrp(tty, real_tty, p); 3397 return tiocgpgrp(tty, real_tty, p);
3395 case TIOCSPGRP: 3398 case TIOCSPGRP:
3396 return tiocspgrp(tty, real_tty, p); 3399 return tiocspgrp(tty, real_tty, p);
3397 case TIOCGSID: 3400 case TIOCGSID:
3398 return tiocgsid(tty, real_tty, p); 3401 return tiocgsid(tty, real_tty, p);
3399 case TIOCGETD: 3402 case TIOCGETD:
3400 /* FIXME: check this is ok */ 3403 /* FIXME: check this is ok */
3401 return put_user(tty->ldisc.num, (int __user *)p); 3404 return put_user(tty->ldisc.num, (int __user *)p);
3402 case TIOCSETD: 3405 case TIOCSETD:
3403 return tiocsetd(tty, p); 3406 return tiocsetd(tty, p);
3404#ifdef CONFIG_VT 3407#ifdef CONFIG_VT
3405 case TIOCLINUX: 3408 case TIOCLINUX:
3406 return tioclinux(tty, arg); 3409 return tioclinux(tty, arg);
3407#endif 3410#endif
3408 /* 3411 /*
3409 * Break handling 3412 * Break handling
3410 */ 3413 */
3411 case TIOCSBRK: /* Turn break on, unconditionally */ 3414 case TIOCSBRK: /* Turn break on, unconditionally */
3412 tty->driver->break_ctl(tty, -1); 3415 tty->driver->break_ctl(tty, -1);
3413 return 0; 3416 return 0;
3414
3415 case TIOCCBRK: /* Turn break off, unconditionally */
3416 tty->driver->break_ctl(tty, 0);
3417 return 0;
3418 case TCSBRK: /* SVID version: non-zero arg --> no break */
3419 /* non-zero arg means wait for all output data
3420 * to be sent (performed above) but don't send break.
3421 * This is used by the tcdrain() termios function.
3422 */
3423 if (!arg)
3424 return send_break(tty, 250);
3425 return 0;
3426 case TCSBRKP: /* support for POSIX tcsendbreak() */
3427 return send_break(tty, arg ? arg*100 : 250);
3428
3429 case TIOCMGET:
3430 return tty_tiocmget(tty, file, p);
3431 3417
3432 case TIOCMSET: 3418 case TIOCCBRK: /* Turn break off, unconditionally */
3433 case TIOCMBIC: 3419 tty->driver->break_ctl(tty, 0);
3434 case TIOCMBIS: 3420 return 0;
3435 return tty_tiocmset(tty, file, cmd, p); 3421 case TCSBRK: /* SVID version: non-zero arg --> no break */
3436 case TCFLSH: 3422 /* non-zero arg means wait for all output data
3437 switch (arg) { 3423 * to be sent (performed above) but don't send break.
3438 case TCIFLUSH: 3424 * This is used by the tcdrain() termios function.
3439 case TCIOFLUSH: 3425 */
3440 /* flush tty buffer and allow ldisc to process ioctl */ 3426 if (!arg)
3441 tty_buffer_flush(tty); 3427 return send_break(tty, 250);
3442 break; 3428 return 0;
3443 } 3429 case TCSBRKP: /* support for POSIX tcsendbreak() */
3430 return send_break(tty, arg ? arg*100 : 250);
3431
3432 case TIOCMGET:
3433 return tty_tiocmget(tty, file, p);
3434 case TIOCMSET:
3435 case TIOCMBIC:
3436 case TIOCMBIS:
3437 return tty_tiocmset(tty, file, cmd, p);
3438 case TCFLSH:
3439 switch (arg) {
3440 case TCIFLUSH:
3441 case TCIOFLUSH:
3442 /* flush tty buffer and allow ldisc to process ioctl */
3443 tty_buffer_flush(tty);
3444 break; 3444 break;
3445 }
3446 break;
3445 } 3447 }
3446 if (tty->driver->ioctl) { 3448 if (tty->driver->ioctl) {
3447 retval = (tty->driver->ioctl)(tty, file, cmd, arg); 3449 retval = (tty->driver->ioctl)(tty, file, cmd, arg);
@@ -3460,7 +3462,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
3460} 3462}
3461 3463
3462#ifdef CONFIG_COMPAT 3464#ifdef CONFIG_COMPAT
3463static long tty_compat_ioctl(struct file * file, unsigned int cmd, 3465static long tty_compat_ioctl(struct file *file, unsigned int cmd,
3464 unsigned long arg) 3466 unsigned long arg)
3465{ 3467{
3466 struct inode *inode = file->f_dentry->d_inode; 3468 struct inode *inode = file->f_dentry->d_inode;
@@ -3491,7 +3493,7 @@ static long tty_compat_ioctl(struct file * file, unsigned int cmd,
3491 * prevent trojan horses by killing all processes associated with this 3493 * prevent trojan horses by killing all processes associated with this
3492 * tty when the user hits the "Secure Attention Key". Required for 3494 * tty when the user hits the "Secure Attention Key". Required for
3493 * super-paranoid applications --- see the Orange Book for more details. 3495 * super-paranoid applications --- see the Orange Book for more details.
3494 * 3496 *
3495 * This code could be nicer; ideally it should send a HUP, wait a few 3497 * This code could be nicer; ideally it should send a HUP, wait a few
3496 * seconds, then send a INT, and then a KILL signal. But you then 3498 * seconds, then send a INT, and then a KILL signal. But you then
3497 * have to coordinate with the init process, since all processes associated 3499 * have to coordinate with the init process, since all processes associated
@@ -3515,16 +3517,16 @@ void __do_SAK(struct tty_struct *tty)
3515 int i; 3517 int i;
3516 struct file *filp; 3518 struct file *filp;
3517 struct fdtable *fdt; 3519 struct fdtable *fdt;
3518 3520
3519 if (!tty) 3521 if (!tty)
3520 return; 3522 return;
3521 session = tty->session; 3523 session = tty->session;
3522 3524
3523 tty_ldisc_flush(tty); 3525 tty_ldisc_flush(tty);
3524 3526
3525 if (tty->driver->flush_buffer) 3527 if (tty->driver->flush_buffer)
3526 tty->driver->flush_buffer(tty); 3528 tty->driver->flush_buffer(tty);
3527 3529
3528 read_lock(&tasklist_lock); 3530 read_lock(&tasklist_lock);
3529 /* Kill the entire session */ 3531 /* Kill the entire session */
3530 do_each_pid_task(session, PIDTYPE_SID, p) { 3532 do_each_pid_task(session, PIDTYPE_SID, p) {
@@ -3552,7 +3554,7 @@ void __do_SAK(struct tty_struct *tty)
3552 */ 3554 */
3553 spin_lock(&p->files->file_lock); 3555 spin_lock(&p->files->file_lock);
3554 fdt = files_fdtable(p->files); 3556 fdt = files_fdtable(p->files);
3555 for (i=0; i < fdt->max_fds; i++) { 3557 for (i = 0; i < fdt->max_fds; i++) {
3556 filp = fcheck_files(p->files, i); 3558 filp = fcheck_files(p->files, i);
3557 if (!filp) 3559 if (!filp)
3558 continue; 3560 continue;
@@ -3606,7 +3608,7 @@ EXPORT_SYMBOL(do_SAK);
3606 * while invoking the line discipline receive_buf method. The 3608 * while invoking the line discipline receive_buf method. The
3607 * receive_buf method is single threaded for each tty instance. 3609 * receive_buf method is single threaded for each tty instance.
3608 */ 3610 */
3609 3611
3610static void flush_to_ldisc(struct work_struct *work) 3612static void flush_to_ldisc(struct work_struct *work)
3611{ 3613{
3612 struct tty_struct *tty = 3614 struct tty_struct *tty =
@@ -3622,7 +3624,8 @@ static void flush_to_ldisc(struct work_struct *work)
3622 return; 3624 return;
3623 3625
3624 spin_lock_irqsave(&tty->buf.lock, flags); 3626 spin_lock_irqsave(&tty->buf.lock, flags);
3625 set_bit(TTY_FLUSHING, &tty->flags); /* So we know a flush is running */ 3627 /* So we know a flush is running */
3628 set_bit(TTY_FLUSHING, &tty->flags);
3626 head = tty->buf.head; 3629 head = tty->buf.head;
3627 if (head != NULL) { 3630 if (head != NULL) {
3628 tty->buf.head = NULL; 3631 tty->buf.head = NULL;
@@ -3795,7 +3798,8 @@ struct device *tty_register_device(struct tty_driver *driver, unsigned index,
3795 3798
3796void tty_unregister_device(struct tty_driver *driver, unsigned index) 3799void tty_unregister_device(struct tty_driver *driver, unsigned index)
3797{ 3800{
3798 device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index); 3801 device_destroy(tty_class,
3802 MKDEV(driver->major, driver->minor_start) + index);
3799} 3803}
3800 3804
3801EXPORT_SYMBOL(tty_register_device); 3805EXPORT_SYMBOL(tty_register_device);
@@ -3859,7 +3863,7 @@ EXPORT_SYMBOL(tty_set_operations);
3859int tty_register_driver(struct tty_driver *driver) 3863int tty_register_driver(struct tty_driver *driver)
3860{ 3864{
3861 int error; 3865 int error;
3862 int i; 3866 int i;
3863 dev_t dev; 3867 dev_t dev;
3864 void **p = NULL; 3868 void **p = NULL;
3865 3869
@@ -3873,8 +3877,8 @@ int tty_register_driver(struct tty_driver *driver)
3873 } 3877 }
3874 3878
3875 if (!driver->major) { 3879 if (!driver->major) {
3876 error = alloc_chrdev_region(&dev, driver->minor_start, driver->num, 3880 error = alloc_chrdev_region(&dev, driver->minor_start,
3877 driver->name); 3881 driver->num, driver->name);
3878 if (!error) { 3882 if (!error) {
3879 driver->major = MAJOR(dev); 3883 driver->major = MAJOR(dev);
3880 driver->minor_start = MINOR(dev); 3884 driver->minor_start = MINOR(dev);
@@ -3891,7 +3895,8 @@ int tty_register_driver(struct tty_driver *driver)
3891 if (p) { 3895 if (p) {
3892 driver->ttys = (struct tty_struct **)p; 3896 driver->ttys = (struct tty_struct **)p;
3893 driver->termios = (struct ktermios **)(p + driver->num); 3897 driver->termios = (struct ktermios **)(p + driver->num);
3894 driver->termios_locked = (struct ktermios **)(p + driver->num * 2); 3898 driver->termios_locked = (struct ktermios **)
3899 (p + driver->num * 2);
3895 } else { 3900 } else {
3896 driver->ttys = NULL; 3901 driver->ttys = NULL;
3897 driver->termios = NULL; 3902 driver->termios = NULL;
@@ -3911,13 +3916,13 @@ int tty_register_driver(struct tty_driver *driver)
3911 3916
3912 if (!driver->put_char) 3917 if (!driver->put_char)
3913 driver->put_char = tty_default_put_char; 3918 driver->put_char = tty_default_put_char;
3914 3919
3915 mutex_lock(&tty_mutex); 3920 mutex_lock(&tty_mutex);
3916 list_add(&driver->tty_drivers, &tty_drivers); 3921 list_add(&driver->tty_drivers, &tty_drivers);
3917 mutex_unlock(&tty_mutex); 3922 mutex_unlock(&tty_mutex);
3918 3923
3919 if ( !(driver->flags & TTY_DRIVER_DYNAMIC_DEV) ) { 3924 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) {
3920 for(i = 0; i < driver->num; i++) 3925 for (i = 0; i < driver->num; i++)
3921 tty_register_device(driver, i, NULL); 3926 tty_register_device(driver, i, NULL);
3922 } 3927 }
3923 proc_tty_register_driver(driver); 3928 proc_tty_register_driver(driver);
@@ -4037,7 +4042,7 @@ void __init console_init(void)
4037 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); 4042 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
4038 4043
4039 /* 4044 /*
4040 * set up the console device so that later boot sequences can 4045 * set up the console device so that later boot sequences can
4041 * inform about problems etc.. 4046 * inform about problems etc..
4042 */ 4047 */
4043 call = __con_initcall_start; 4048 call = __con_initcall_start;