aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2016-01-10 00:13:46 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-01-27 17:28:20 -0500
commitc8b710b3e4348119924051551b836c94835331b1 (patch)
tree5315047eaf79a1e2db862ab4502569b42b2b9136 /drivers/tty
parentf4f9edcf9b5289ed96113e79fa65a7bf27ecb096 (diff)
tty: Fix ldisc leak in failed tty_init_dev()
release_tty() leaks the ldisc instance when called directly (rather than when releasing the file descriptor from tty_release()). Since tty_ldisc_release() clears tty->ldisc, releasing the ldisc instance at tty teardown if tty->ldisc is non-null is not in danger of double-releasing the ldisc. Remove deinitialize_tty_struct() now that free_tty_struct() always performs the tty_ldisc_deinit(). Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/pty.c5
-rw-r--r--drivers/tty/tty_io.c20
-rw-r--r--drivers/tty/tty_ldisc.c5
3 files changed, 8 insertions, 22 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index b3110040164a..8cbe802bff1d 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -408,7 +408,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
408 the easy way .. */ 408 the easy way .. */
409 retval = tty_init_termios(tty); 409 retval = tty_init_termios(tty);
410 if (retval) 410 if (retval)
411 goto err_deinit_tty; 411 goto err_free_tty;
412 412
413 retval = tty_init_termios(o_tty); 413 retval = tty_init_termios(o_tty);
414 if (retval) 414 if (retval)
@@ -447,8 +447,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
447err_free_termios: 447err_free_termios:
448 if (legacy) 448 if (legacy)
449 tty_free_termios(tty); 449 tty_free_termios(tty);
450err_deinit_tty: 450err_free_tty:
451 deinitialize_tty_struct(o_tty);
452 free_tty_struct(o_tty); 451 free_tty_struct(o_tty);
453err_put_module: 452err_put_module:
454 module_put(driver->other->owner); 453 module_put(driver->other->owner);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5cec01c75691..c9f2365167df 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -172,6 +172,7 @@ void free_tty_struct(struct tty_struct *tty)
172{ 172{
173 if (!tty) 173 if (!tty)
174 return; 174 return;
175 tty_ldisc_deinit(tty);
175 put_device(tty->dev); 176 put_device(tty->dev);
176 kfree(tty->write_buf); 177 kfree(tty->write_buf);
177 tty->magic = 0xDEADDEAD; 178 tty->magic = 0xDEADDEAD;
@@ -1529,7 +1530,7 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1529 tty_lock(tty); 1530 tty_lock(tty);
1530 retval = tty_driver_install_tty(driver, tty); 1531 retval = tty_driver_install_tty(driver, tty);
1531 if (retval < 0) 1532 if (retval < 0)
1532 goto err_deinit_tty; 1533 goto err_free_tty;
1533 1534
1534 if (!tty->port) 1535 if (!tty->port)
1535 tty->port = driver->ports[idx]; 1536 tty->port = driver->ports[idx];
@@ -1551,9 +1552,8 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1551 /* Return the tty locked so that it cannot vanish under the caller */ 1552 /* Return the tty locked so that it cannot vanish under the caller */
1552 return tty; 1553 return tty;
1553 1554
1554err_deinit_tty: 1555err_free_tty:
1555 tty_unlock(tty); 1556 tty_unlock(tty);
1556 deinitialize_tty_struct(tty);
1557 free_tty_struct(tty); 1557 free_tty_struct(tty);
1558err_module_put: 1558err_module_put:
1559 module_put(driver->owner); 1559 module_put(driver->owner);
@@ -3163,20 +3163,6 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
3163} 3163}
3164 3164
3165/** 3165/**
3166 * deinitialize_tty_struct
3167 * @tty: tty to deinitialize
3168 *
3169 * This subroutine deinitializes a tty structure that has been newly
3170 * allocated but tty_release cannot be called on that yet.
3171 *
3172 * Locking: none - tty in question must not be exposed at this point
3173 */
3174void deinitialize_tty_struct(struct tty_struct *tty)
3175{
3176 tty_ldisc_deinit(tty);
3177}
3178
3179/**
3180 * tty_put_char - write one character to a tty 3166 * tty_put_char - write one character to a tty
3181 * @tty: tty 3167 * @tty: tty
3182 * @ch: character 3168 * @ch: character
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index a054d03c22e7..49f0cea1e538 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -797,7 +797,7 @@ void tty_ldisc_init(struct tty_struct *tty)
797} 797}
798 798
799/** 799/**
800 * tty_ldisc_init - ldisc cleanup for new tty 800 * tty_ldisc_deinit - ldisc cleanup for new tty
801 * @tty: tty that was allocated recently 801 * @tty: tty that was allocated recently
802 * 802 *
803 * The tty structure must not becompletely set up (tty_ldisc_setup) when 803 * The tty structure must not becompletely set up (tty_ldisc_setup) when
@@ -805,7 +805,8 @@ void tty_ldisc_init(struct tty_struct *tty)
805 */ 805 */
806void tty_ldisc_deinit(struct tty_struct *tty) 806void tty_ldisc_deinit(struct tty_struct *tty)
807{ 807{
808 tty_ldisc_put(tty->ldisc); 808 if (tty->ldisc)
809 tty_ldisc_put(tty->ldisc);
809 tty->ldisc = NULL; 810 tty->ldisc = NULL;
810} 811}
811 812