From: Jiri Slaby <jslaby@suse.cz>
To: Pan Xinhui <xinhuix.pan@intel.com>,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Cc: mnipxh@gmail.com, yanmin_zhang@linux.intel.com
Subject: Re: [PATCH] tty/n_gsm.c: fix a memory leak when gsmtty is removed
Date: Mon, 23 Mar 2015 16:23:01 +0100 [thread overview]
Message-ID: <55102FD5.5050605@suse.cz> (raw)
In-Reply-To: <551110AC.9000306@intel.com>
On 03/24/2015, 08:22 AM, Pan Xinhui wrote:
> 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)
I am afraid you cannot guarantee it is "late enough" by this approach.
The work can be already running before itty is set to NULL.
If I am looking correctly the work can be moved from ->remove to
->cleanup, right?
And it would be worth to add a Fixes line to the commit log.
dfabf7ffa30585 introduced this.
And could you describe the scenario when it happens to the commit log
too? Like closing the other end first, before the tty.
thanks,
--
js
suse labs
next prev parent reply other threads:[~2015-03-23 15:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-24 7:22 [PATCH] tty/n_gsm.c: fix a memory leak when gsmtty is removed Pan Xinhui
2015-03-23 15:23 ` Jiri Slaby [this message]
2015-03-25 2:43 ` Pan Xinhui
-- strict thread matches above, loose matches on Subject: below --
2015-03-24 7:26 Pan Xinhui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55102FD5.5050605@suse.cz \
--to=jslaby@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mnipxh@gmail.com \
--cc=xinhuix.pan@intel.com \
--cc=yanmin_zhang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox