aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tty_ldisc.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-06-01 16:53:01 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-10 16:47:43 -0400
commitec79d6056de58511d8e46d9ae59d3878f958dc3e (patch)
tree8e73cf399c4cb3c31dbf3caced385cfc018a706a /drivers/char/tty_ldisc.c
parent3f582b8c11014e4ce310d9839fb335164195333f (diff)
tty: replace BKL with a new tty_lock
As a preparation for replacing the big kernel lock in the TTY layer, wrap all the callers in new macros tty_lock, tty_lock_nested and tty_unlock. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/char/tty_ldisc.c')
-rw-r--r--drivers/char/tty_ldisc.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index 500e740ec5e4..97681ffd6cbd 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -440,6 +440,8 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
440 * 440 *
441 * A helper opening method. Also a convenient debugging and check 441 * A helper opening method. Also a convenient debugging and check
442 * point. 442 * point.
443 *
444 * Locking: always called with BTM already held.
443 */ 445 */
444 446
445static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) 447static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
@@ -447,10 +449,10 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
447 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); 449 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
448 if (ld->ops->open) { 450 if (ld->ops->open) {
449 int ret; 451 int ret;
450 /* BKL here locks verus a hangup event */ 452 /* BTM here locks versus a hangup event */
451 lock_kernel(); 453 tty_lock_nested(); /* always held here already */
452 ret = ld->ops->open(tty); 454 ret = ld->ops->open(tty);
453 unlock_kernel(); 455 tty_unlock();
454 return ret; 456 return ret;
455 } 457 }
456 return 0; 458 return 0;
@@ -553,7 +555,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
553 if (IS_ERR(new_ldisc)) 555 if (IS_ERR(new_ldisc))
554 return PTR_ERR(new_ldisc); 556 return PTR_ERR(new_ldisc);
555 557
556 lock_kernel(); 558 tty_lock();
557 /* 559 /*
558 * We need to look at the tty locking here for pty/tty pairs 560 * We need to look at the tty locking here for pty/tty pairs
559 * when both sides try to change in parallel. 561 * when both sides try to change in parallel.
@@ -567,12 +569,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
567 */ 569 */
568 570
569 if (tty->ldisc->ops->num == ldisc) { 571 if (tty->ldisc->ops->num == ldisc) {
570 unlock_kernel(); 572 tty_unlock();
571 tty_ldisc_put(new_ldisc); 573 tty_ldisc_put(new_ldisc);
572 return 0; 574 return 0;
573 } 575 }
574 576
575 unlock_kernel(); 577 tty_unlock();
576 /* 578 /*
577 * Problem: What do we do if this blocks ? 579 * Problem: What do we do if this blocks ?
578 * We could deadlock here 580 * We could deadlock here
@@ -594,7 +596,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
594 mutex_lock(&tty->ldisc_mutex); 596 mutex_lock(&tty->ldisc_mutex);
595 } 597 }
596 598
597 lock_kernel(); 599 tty_lock();
598 600
599 set_bit(TTY_LDISC_CHANGING, &tty->flags); 601 set_bit(TTY_LDISC_CHANGING, &tty->flags);
600 602
@@ -607,7 +609,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
607 609
608 o_ldisc = tty->ldisc; 610 o_ldisc = tty->ldisc;
609 611
610 unlock_kernel(); 612 tty_unlock();
611 /* 613 /*
612 * Make sure we don't change while someone holds a 614 * Make sure we don't change while someone holds a
613 * reference to the line discipline. The TTY_LDISC bit 615 * reference to the line discipline. The TTY_LDISC bit
@@ -633,14 +635,14 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
633 flush_scheduled_work(); 635 flush_scheduled_work();
634 636
635 mutex_lock(&tty->ldisc_mutex); 637 mutex_lock(&tty->ldisc_mutex);
636 lock_kernel(); 638 tty_lock();
637 if (test_bit(TTY_HUPPED, &tty->flags)) { 639 if (test_bit(TTY_HUPPED, &tty->flags)) {
638 /* We were raced by the hangup method. It will have stomped 640 /* We were raced by the hangup method. It will have stomped
639 the ldisc data and closed the ldisc down */ 641 the ldisc data and closed the ldisc down */
640 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 642 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
641 mutex_unlock(&tty->ldisc_mutex); 643 mutex_unlock(&tty->ldisc_mutex);
642 tty_ldisc_put(new_ldisc); 644 tty_ldisc_put(new_ldisc);
643 unlock_kernel(); 645 tty_unlock();
644 return -EIO; 646 return -EIO;
645 } 647 }
646 648
@@ -682,7 +684,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
682 if (o_work) 684 if (o_work)
683 schedule_delayed_work(&o_tty->buf.work, 1); 685 schedule_delayed_work(&o_tty->buf.work, 1);
684 mutex_unlock(&tty->ldisc_mutex); 686 mutex_unlock(&tty->ldisc_mutex);
685 unlock_kernel(); 687 tty_unlock();
686 return retval; 688 return retval;
687} 689}
688 690