From: <erik.hugne@ericsson.com>
To: <netdev@vger.kernel.org>, <tipc-discussion@lists.sourceforge.net>,
<jon.maloy@ericsson.com>, <maloy@donjonn.com>
Cc: <ying.xue@windriver.com>, <paul.gortmaker@windriver.com>,
<richard.alpe@ericsson.com>, Erik Hugne <erik.hugne@ericsson.com>
Subject: [PATCH net-next v2 5/6] tipc: fix memory leak during module removal
Date: Wed, 5 Mar 2014 08:56:17 +0100 [thread overview]
Message-ID: <1394006178-23966-6-git-send-email-erik.hugne@ericsson.com> (raw)
In-Reply-To: <1394006178-23966-1-git-send-email-erik.hugne@ericsson.com>
From: Erik Hugne <erik.hugne@ericsson.com>
When the TIPC module is removed, the tasklet handler is disabled
before all other subsystems. This will cause lingering publications
in the name table because the node_down tasklets responsible to
clean up publications from an unreachable node will never run.
When the name table is shut down, these publications are detected
and an error message is logged:
tipc: nametbl_stop(): orphaned hash chain detected
This is actually a memory leak, introduced with commit
993b858e37b3120ee76d9957a901cca22312ffaa ("tipc: correct the order
of stopping services at rmmod")
Instead of just logging an error and leaking memory, we free
the orphaned entries during nametable shutdown.
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
net/tipc/name_table.c | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 92a1533..25c32dd 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -941,20 +941,51 @@ int tipc_nametbl_init(void)
return 0;
}
+/**
+ * tipc_purge_publications - remove all publications for a given type
+ *
+ * tipc_nametbl_lock must be held when calling this function
+ */
+static void tipc_purge_publications(struct name_seq *seq)
+{
+ struct publication *publ, *safe;
+ struct sub_seq *sseq;
+ struct name_info *info;
+
+ if (!seq->sseqs) {
+ nameseq_delete_empty(seq);
+ return;
+ }
+ sseq = seq->sseqs;
+ info = sseq->info;
+ list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
+ tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node,
+ publ->ref, publ->key);
+ }
+}
+
void tipc_nametbl_stop(void)
{
u32 i;
+ struct name_seq *seq;
+ struct hlist_head *seq_head;
+ struct hlist_node *safe;
if (!table.types)
return;
- /* Verify name table is empty, then release it */
+ /* Verify name table is empty and purge any lingering
+ * publications, then release the name table
+ */
write_lock_bh(&tipc_nametbl_lock);
for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
if (hlist_empty(&table.types[i]))
continue;
- pr_err("nametbl_stop(): orphaned hash chain detected\n");
- break;
+ seq_head = &table.types[i];
+ hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
+ tipc_purge_publications(seq);
+ }
+ continue;
}
kfree(table.types);
table.types = NULL;
--
1.8.3.2
next prev parent reply other threads:[~2014-03-05 7:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-05 7:56 [PATCH net-next v2 0/6] tipc: refcount and memory leak fixes erik.hugne
2014-03-05 7:56 ` [PATCH net-next v2 1/6] tipc: allow connection shutdown callback to be invoked in advance erik.hugne
2014-03-06 4:56 ` David Miller
2014-03-06 9:06 ` Erik Hugne
2014-03-09 17:48 ` Ben Hutchings
2014-03-05 7:56 ` [PATCH net-next v2 2/6] tipc: fix connection refcount leak erik.hugne
2014-03-05 7:56 ` [PATCH net-next v2 3/6] tipc: avoid to unnecessary process switch under non-block mode erik.hugne
2014-03-05 7:56 ` [PATCH net-next v2 4/6] tipc: drop subscriber connection id invalidation erik.hugne
2014-03-05 7:56 ` erik.hugne [this message]
2014-03-05 7:56 ` [PATCH net-next v2 6/6] tipc: don't log disabled tasklet handler errors erik.hugne
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=1394006178-23966-6-git-send-email-erik.hugne@ericsson.com \
--to=erik.hugne@ericsson.com \
--cc=jon.maloy@ericsson.com \
--cc=maloy@donjonn.com \
--cc=netdev@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=richard.alpe@ericsson.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=ying.xue@windriver.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;
as well as URLs for NNTP newsgroup(s).