diff options
author | Alan Cox <alan@linux.intel.com> | 2011-02-14 11:27:53 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-17 15:03:52 -0500 |
commit | 8d075b199b9a66ad90296f898f1f15c0ae1511b8 (patch) | |
tree | 2189c77c61210a4d24608f3fb49daf0bd6309f64 /drivers | |
parent | 94c2273d6c1b65eaaf2a6446c7147bdf6e5ae924 (diff) |
tty: add a helper for setting termios data from kernel side
This basically encapsulates the small bit of locking knowledge needed. While
we are at it make sure we blow up on any more abusers and unsafe misuses of
ioctl for this kind of stuff.
We change the function to return an argument as at some point it needs to
honour the POSIX 'I asked for changes but got none of them' error reporting
corner case.
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/tty/tty_ioctl.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c index 0c1889971459..1a1135d580a2 100644 --- a/drivers/tty/tty_ioctl.c +++ b/drivers/tty/tty_ioctl.c | |||
@@ -486,7 +486,7 @@ int tty_termios_hw_change(struct ktermios *a, struct ktermios *b) | |||
486 | EXPORT_SYMBOL(tty_termios_hw_change); | 486 | EXPORT_SYMBOL(tty_termios_hw_change); |
487 | 487 | ||
488 | /** | 488 | /** |
489 | * change_termios - update termios values | 489 | * tty_set_termios - update termios values |
490 | * @tty: tty to update | 490 | * @tty: tty to update |
491 | * @new_termios: desired new value | 491 | * @new_termios: desired new value |
492 | * | 492 | * |
@@ -497,7 +497,7 @@ EXPORT_SYMBOL(tty_termios_hw_change); | |||
497 | * Locking: termios_mutex | 497 | * Locking: termios_mutex |
498 | */ | 498 | */ |
499 | 499 | ||
500 | static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) | 500 | int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) |
501 | { | 501 | { |
502 | struct ktermios old_termios; | 502 | struct ktermios old_termios; |
503 | struct tty_ldisc *ld; | 503 | struct tty_ldisc *ld; |
@@ -553,7 +553,9 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) | |||
553 | tty_ldisc_deref(ld); | 553 | tty_ldisc_deref(ld); |
554 | } | 554 | } |
555 | mutex_unlock(&tty->termios_mutex); | 555 | mutex_unlock(&tty->termios_mutex); |
556 | return 0; | ||
556 | } | 557 | } |
558 | EXPORT_SYMBOL_GPL(tty_set_termios); | ||
557 | 559 | ||
558 | /** | 560 | /** |
559 | * set_termios - set termios values for a tty | 561 | * set_termios - set termios values for a tty |
@@ -562,7 +564,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) | |||
562 | * @opt: option information | 564 | * @opt: option information |
563 | * | 565 | * |
564 | * Helper function to prepare termios data and run necessary other | 566 | * Helper function to prepare termios data and run necessary other |
565 | * functions before using change_termios to do the actual changes. | 567 | * functions before using tty_set_termios to do the actual changes. |
566 | * | 568 | * |
567 | * Locking: | 569 | * Locking: |
568 | * Called functions take ldisc and termios_mutex locks | 570 | * Called functions take ldisc and termios_mutex locks |
@@ -620,7 +622,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt) | |||
620 | return -EINTR; | 622 | return -EINTR; |
621 | } | 623 | } |
622 | 624 | ||
623 | change_termios(tty, &tmp_termios); | 625 | tty_set_termios(tty, &tmp_termios); |
624 | 626 | ||
625 | /* FIXME: Arguably if tmp_termios == tty->termios AND the | 627 | /* FIXME: Arguably if tmp_termios == tty->termios AND the |
626 | actual requested termios was not tmp_termios then we may | 628 | actual requested termios was not tmp_termios then we may |
@@ -797,7 +799,7 @@ static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) | |||
797 | termios.c_ospeed); | 799 | termios.c_ospeed); |
798 | #endif | 800 | #endif |
799 | mutex_unlock(&tty->termios_mutex); | 801 | mutex_unlock(&tty->termios_mutex); |
800 | change_termios(tty, &termios); | 802 | tty_set_termios(tty, &termios); |
801 | return 0; | 803 | return 0; |
802 | } | 804 | } |
803 | #endif | 805 | #endif |
@@ -951,6 +953,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | |||
951 | int ret = 0; | 953 | int ret = 0; |
952 | struct ktermios kterm; | 954 | struct ktermios kterm; |
953 | 955 | ||
956 | BUG_ON(file == NULL); | ||
957 | |||
954 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && | 958 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY && |
955 | tty->driver->subtype == PTY_TYPE_MASTER) | 959 | tty->driver->subtype == PTY_TYPE_MASTER) |
956 | real_tty = tty->link; | 960 | real_tty = tty->link; |