patch "tty/n_gsm.c: fix a memory leak when gsmtty is removed" added to tty-linus
Subsystems (2)
This is a note to let you know that I've just added the patch titled
tty/n_gsm.c: fix a memory leak when gsmtty is removed
to my tty git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
Quoted 1 line
From
8f9cfeed3eae86c70d3b04445a6f2036b27b6304Mon Sep 17 00:00:00 2001
From: Pan Xinhui <[email protected]>
Date: Sat, 28 Mar 2015 10:42:56 +0800
Subject: tty/n_gsm.c: fix a memory leak when gsmtty is removed
when gsmtty_remove put dlci, it will cause memory leak if dlci->port's refcount is zero. So we do the cleanup work in .cleanup callback instead.
dlci will be last put in two call chains.
1) gsmld_close -> gsm_cleanup_mux -> gsm_dlci_release -> dlci_put
2) gsmld_remove -> dlci_put
so there is a race. the memory leak depends on the race.
In call chain 2. we hit the memory leak. below comment tells.
release_tty -> tty_driver_remove_tty -> gsmtty_remove -> dlci_put -> tty_port_destructor (WARN_ON(port->itty) and return directly)
|
tty->port->itty = NULL;
|
tty_kref_put ---> release_one_tty -> gsmtty_cleanup (added by our patch)So our patch fix the memory leak by doing the cleanup work after tty core did.
--- drivers/tty/n_gsm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tty/n_gsm.c +2 -3
@@ -3170,7 +3170,7 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)return gsmtty_modem_update (dlci, encode); } -static void gsmtty_remove (struct tty_driver *driver,struct tty_struct *tty) +static void gsmtty_cleanup (struct tty_struct *tty) {struct gsm_dlci *dlci = tty->driver_data;struct gsm_mux *gsm = dlci->gsm;
@@ -3178,7 +3178,6 @@ static void gsmtty_remove(struct tty_driver *driver, struct tty_struct *tty)dlci_put (dlci);dlci_put (gsm->dlci[0 ]);mux_put (gsm); - driver->ttys[tty->index] =NULL ; }/* Virtual ttys for the demux */
@@ -3199,7 +3198,7 @@ static const struct tty_operations gsmtty_ops = { .tiocmget = gsmtty_tiocmget, .tiocmset = gsmtty_tiocmset, .break_ctl = gsmtty_break_ctl, - .remove = gsmtty_remove, + .cleanup = gsmtty_cleanup, };
Signature · 1 line
2.4.0