From: Pan Xinhui Date: Sat, 28 Mar 2015 02:42:56 +0000 (+0800) Subject: tty/n_gsm.c: fix a memory leak when gsmtty is removed X-Git-Tag: omap-for-v4.2/wakeirq-drivers~2^2~8^2~1 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f9cfeed3eae86c70d3b04445a6f2036b27b6304;p=pandora-kernel.git 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. Signed-off-by: Pan Xinhui Fixes: dfabf7ffa30585 Cc: stable # 3.14+ Acked-by: Jiri Slaby Signed-off-by: Greg Kroah-Hartman --- Reading git-diff-tree failed