mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: alan@linux.intel.com, linux-kernel@vger.kernel.org, jirislaby@gmail.com
Subject: [PATCH 3/9] ISDN: capi, use kref from tty_port
Date: Thu, 15 Nov 2012 09:49:50 +0100	[thread overview]
Message-ID: <1352969396-23760-4-git-send-email-jslaby@suse.cz> (raw)
In-Reply-To: <1352969396-23760-1-git-send-email-jslaby@suse.cz>

After commit "TTY: move tty buffers to tty_port", the tty buffers are
not freed in some drivers. This is because tty_port_destructor is not
called whenever a tty_port is freed. This was an assumption I counted
with but was unfortunately untrue. So fix the drivers to fulfil this
assumption.

Here it is enough to switch to refcounting in tty_port.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/isdn/capi/capi.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index c679867..89562a8 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -77,8 +77,6 @@ struct ackqueue_entry {
 };
 
 struct capiminor {
-	struct kref kref;
-
 	unsigned int      minor;
 
 	struct capi20_appl	*ap;
@@ -190,7 +188,20 @@ static void capiminor_del_all_ack(struct capiminor *mp)
 
 /* -------- struct capiminor ---------------------------------------- */
 
-static const struct tty_port_operations capiminor_port_ops; /* we have none */
+static void capiminor_destroy(struct tty_port *port)
+{
+	struct capiminor *mp = container_of(port, struct capiminor, port);
+
+	kfree_skb(mp->outskb);
+	skb_queue_purge(&mp->inqueue);
+	skb_queue_purge(&mp->outqueue);
+	capiminor_del_all_ack(mp);
+	kfree(mp);
+}
+
+static const struct tty_port_operations capiminor_port_ops = {
+	.destruct = capiminor_destroy,
+};
 
 static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
 {
@@ -204,8 +215,6 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
 		return NULL;
 	}
 
-	kref_init(&mp->kref);
-
 	mp->ap = ap;
 	mp->ncci = ncci;
 	INIT_LIST_HEAD(&mp->ackqueue);
@@ -247,21 +256,10 @@ err_out2:
 	spin_unlock(&capiminors_lock);
 
 err_out1:
-	kfree(mp);
+	tty_port_put(&mp->port);
 	return NULL;
 }
 
-static void capiminor_destroy(struct kref *kref)
-{
-	struct capiminor *mp = container_of(kref, struct capiminor, kref);
-
-	kfree_skb(mp->outskb);
-	skb_queue_purge(&mp->inqueue);
-	skb_queue_purge(&mp->outqueue);
-	capiminor_del_all_ack(mp);
-	kfree(mp);
-}
-
 static struct capiminor *capiminor_get(unsigned int minor)
 {
 	struct capiminor *mp;
@@ -269,7 +267,7 @@ static struct capiminor *capiminor_get(unsigned int minor)
 	spin_lock(&capiminors_lock);
 	mp = capiminors[minor];
 	if (mp)
-		kref_get(&mp->kref);
+		tty_port_get(&mp->port);
 	spin_unlock(&capiminors_lock);
 
 	return mp;
@@ -277,7 +275,7 @@ static struct capiminor *capiminor_get(unsigned int minor)
 
 static inline void capiminor_put(struct capiminor *mp)
 {
-	kref_put(&mp->kref, capiminor_destroy);
+	tty_port_put(&mp->port);
 }
 
 static void capiminor_free(struct capiminor *mp)
-- 
1.8.0



  parent reply	other threads:[~2012-11-15  8:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-15  8:49 [PATCH 0/9] TTY: memory leaks patchset Jiri Slaby
2012-11-15  8:49 ` [PATCH 1/9] TTY: isicom, stop using port->tty Jiri Slaby
2012-11-15  8:49 ` [PATCH 2/9] TTY: pty, fix tty buffers leak Jiri Slaby
2012-11-15  8:49 ` Jiri Slaby [this message]
2012-11-15  8:49 ` [PATCH 4/9] MMC: sdio_uart, remove unused member from sdio_uart_port Jiri Slaby
2012-11-15  8:49 ` [PATCH 5/9] MMC: sdio, use kref from tty_port Jiri Slaby
2012-11-15  8:49 ` [PATCH 6/9] TTY: n_gsm, " Jiri Slaby
2012-11-15  8:49 ` [PATCH 7/9] TTY: introduce tty_port_destroy Jiri Slaby
2012-11-15  8:49 ` [PATCH 8/9] TTY: isicom, fix tty buffers memory leak Jiri Slaby
2012-11-15  8:49 ` [PATCH 9/9] TTY: call tty_port_destroy in the rest of drivers Jiri Slaby
2012-11-18 13:39   ` Tilman Schmidt
2012-11-27 16:52   ` Peter Hurley
2012-11-27 17:04     ` Greg Kroah-Hartman
2012-11-27 17:23       ` Peter Hurley
2012-11-28  2:37       ` [PATCH -next 0/3] staging/fwserial: teardown cleanup Peter Hurley
2012-11-28  2:37         ` [PATCH -next 1/3] staging/fwserial: Destruct embedded tty_port on teardown Peter Hurley
2012-11-28  2:37         ` [PATCH -next 2/3] staging/fwserial: Use WARN_ONCE when port table is corrupted Peter Hurley
2012-11-28  2:37         ` [PATCH -next 3/3] staging/fwserial: Remove superfluous free Peter Hurley
2012-11-15 10:42 ` [PATCH 0/9] TTY: memory leaks patchset Alan Cox
2012-11-16  1:21   ` Greg KH

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=1352969396-23760-4-git-send-email-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=alan@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®