All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty/n_gsm.c: fix a memory leak when gsmtty is removed
@ 2015-03-24  7:26 Pan Xinhui
  2015-03-25  7:05 ` [PATCH v2] " Pan Xinhui
  0 siblings, 1 reply; 5+ messages in thread
From: Pan Xinhui @ 2015-03-24  7:26 UTC (permalink / raw)
  To: gregkh, jslaby, linux-kernel; +Cc: yanmin_zhang, mnipxh

In gsmtty_remove, we will put dlci. when dlci's ref-count is zero,
tty_port_destructor will be called, and it will check if port->itty is NULL.
However port->itty will be set to NULL in release_tty after gsmtty_remove.
that may cause memory leak. so we use queue_work to put the dlci later.

Signed-off-by: xinhui.pan <xinhuix.pan@intel.com>
---
  drivers/tty/n_gsm.c | 16 ++++++++++++++--
  1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index c434376..50f4660 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -135,6 +135,7 @@ struct gsm_dlci {
  #define DLCI_OPEN		2	/* SABM/UA complete */
  #define DLCI_CLOSING		3	/* Sending DISC not seen UA/DM */
  	struct mutex mutex;
+	struct work_struct putself_work;
  
  	/* Link layer */
  	spinlock_t lock;	/* Protects the internal state */
@@ -3170,14 +3171,25 @@ 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 put_gsm_dlci(struct work_struct *work)
  {
-	struct gsm_dlci *dlci = tty->driver_data;
+	struct gsm_dlci *dlci =
+		container_of(work, struct gsm_dlci, putself_work);
  	struct gsm_mux *gsm = dlci->gsm;
  
+	mutex_lock(&gsm->mutex);
  	dlci_put(dlci);
  	dlci_put(gsm->dlci[0]);
+	mutex_unlock(&gsm->mutex);
  	mux_put(gsm);
+}
+
+static void gsmtty_remove(struct tty_driver *driver, struct tty_struct *tty)
+{
+	struct gsm_dlci *dlci = tty->driver_data;
+
+	INIT_WORK(&dlci->putself_work, put_gsm_dlci);
+	schedule_work(&dlci->putself_work);
  	driver->ttys[tty->index] = NULL;
  }
  
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-27  8:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-24  7:26 [PATCH] tty/n_gsm.c: fix a memory leak when gsmtty is removed Pan Xinhui
2015-03-25  7:05 ` [PATCH v2] " Pan Xinhui
2015-03-26 21:36   ` Greg KH
2015-03-28  2:42   ` [PATCH v2 RESEND] " Pan Xinhui
2015-03-27  8:51     ` Jiri Slaby

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.