tty: Fix the leak in tty_ldisc_release

Currently we reinit the ldisc on final tty close which is what the old code
did to ensure that if the device retained its termios settings then it had the
right ldisc. tty_ldisc_reinit does that but also leaves us with the reset
ldisc reference which is then leaked.

At this point we know the port will be recycled so we can kill the ldisc
off completely rather than try and add another ldisc free up when the kref
count hits zero.

At this point it is safe to keep the ldisc closed as tty_ldisc waiting
methods are only used from the user side, and as the final close we are
the last such reference. Interrupt/driver side methods will always use the
non wait version and get back a NULL.

Found with kmemleak and investigated/identified by Catalin Marinas.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alan Cox 2009-06-29 15:21:47 +01:00 коммит произвёл Linus Torvalds
Родитель 5298976562
Коммит aef29bc260
1 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -867,15 +867,22 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
tty_ldisc_wait_idle(tty); tty_ldisc_wait_idle(tty);
/* /*
* Shutdown the current line discipline, and reset it to N_TTY. * Now kill off the ldisc
*
* FIXME: this MUST get fixed for the new reflocking
*/ */
tty_ldisc_close(tty, tty->ldisc);
tty_ldisc_put(tty->ldisc);
/* Force an oops if we mess this up */
tty->ldisc = NULL;
/* Ensure the next open requests the N_TTY ldisc */
tty_set_termios_ldisc(tty, N_TTY);
tty_ldisc_reinit(tty);
/* This will need doing differently if we need to lock */ /* This will need doing differently if we need to lock */
if (o_tty) if (o_tty)
tty_ldisc_release(o_tty, NULL); tty_ldisc_release(o_tty, NULL);
/* And the memory resources remaining (buffers, termios) will be
disposed of when the kref hits zero */
} }
/** /**