From patchwork Mon Dec 12 11:31:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1447 Return-Path: Received: from nm25-vm6.bullet.mail.ukl.yahoo.com (nm25-vm6.bullet.mail.ukl.yahoo.com [217.146.177.150]) by open-mesh.org (Postfix) with SMTP id 250096007D6 for ; Mon, 12 Dec 2011 12:32:33 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.211] by nm25.bullet.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:32 -0000 Received: from [77.238.184.52] by tm4.bullet.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:32 -0000 Received: from [127.0.0.1] by smtp121.mail.ukl.yahoo.com with NNFMP; 12 Dec 2011 11:32:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1323689552; bh=LxccwybkADyW+lcSxO00QWHIDoe5rrxj4GU9gm80yUA=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=SVIT/APHSfm+AU17ZqhM4yEdVTY1ZqZBa4Ks9KTNfwdmMXAgRaxNKXuoJmavXumym25APTJKmyxNzwJ4KncRcEnt+JyHWuZNIVRkUmApQ6qD7zFoAvxbHsyr8H1BXP8rx8VzOcVBJc+zH4VSBS1wXDeFq5L41+JED49RyN0NSxA= X-Yahoo-Newman-Id: 594432.86644.bm@smtp121.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: XD1KrsUVM1ntXv67ctscF3XSuukzD2L71F9sRrJCeKA7m0f LhmEl4DeIh33RjjKuw2PVKK5omAowErQKI2ZYB09C5dEPqxusI.PBXk5wZIA dd4sCFKba8P30yb2qRY4yvA5IFaRYjQo1cN_gRCufdtacTAYqHRkdibR9zFK koTEC_zOuq3Nd3LpICXMFEWzzIWV.98wxZel1jmqKvoCEP4wVZza315xdMNw qlexphbI20JD2d75rUAqkUq5NSZndPi36HxstubDnfhBlkpluO9dncSGZkhN HqevbeZpBP7_C5_ZXsMa9hZ3HTD0lwoqgYvaGStSAGpoaF_uS.96ex.WEiD8 NJq4RWaIKChBEuCveJ4NfJP75CPUfP3yE1xOD8zsEkbMxoEFo3AwPkw-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp121.mail.ukl.yahoo.com with SMTP; 12 Dec 2011 11:32:31 +0000 GMT From: Marek Lindner To: davem@davemloft.net Date: Mon, 12 Dec 2011 19:31:48 +0800 Message-Id: <1323689516-24427-5-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323689516-24427-1-git-send-email-lindner_marek@yahoo.de> References: <1323689516-24427-1-git-send-email-lindner_marek@yahoo.de> Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Simon Wunderlich , Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 04/11] batman-adv: check return value for hash_add() X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Dec 2011 11:32:33 -0000 From: Simon Wunderlich if hash_add() fails, we should remove the structure to avoid memory leaks. Signed-off-by: Simon Wunderlich Acked-by: Antonio Quartulli Signed-off-by: Sven Eckelmann Signed-off-by: Marek Lindner --- net/batman-adv/translation-table.c | 28 ++++++++++++++++++++++------ 1 files changed, 22 insertions(+), 6 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index f6bbd64..cc87acf 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -190,6 +190,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, struct bat_priv *bat_priv = netdev_priv(soft_iface); struct tt_local_entry *tt_local_entry = NULL; struct tt_global_entry *tt_global_entry = NULL; + int hash_added; tt_local_entry = tt_local_hash_find(bat_priv, addr); @@ -217,6 +218,16 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, if (compare_eth(addr, soft_iface->dev_addr)) tt_local_entry->common.flags |= TT_CLIENT_NOPURGE; + hash_added = hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, + &tt_local_entry->common, + &tt_local_entry->common.hash_entry); + + if (unlikely(hash_added != 0)) { + /* remove the reference for the hash */ + tt_local_entry_free_ref(tt_local_entry); + goto out; + } + tt_local_event(bat_priv, addr, tt_local_entry->common.flags); /* The local entry has to be marked as NEW to avoid to send it in @@ -224,9 +235,6 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, * (consistency check) */ tt_local_entry->common.flags |= TT_CLIENT_NEW; - hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, - &tt_local_entry->common, &tt_local_entry->common.hash_entry); - /* remove address from global hash if present */ tt_global_entry = tt_global_hash_find(bat_priv, addr); @@ -499,6 +507,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, struct tt_global_entry *tt_global_entry; struct orig_node *orig_node_tmp; int ret = 0; + int hash_added; tt_global_entry = tt_global_hash_find(bat_priv, tt_addr); @@ -518,9 +527,15 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, tt_global_entry->ttvn = ttvn; tt_global_entry->roam_at = 0; - hash_add(bat_priv->tt_global_hash, compare_tt, - choose_orig, &tt_global_entry->common, - &tt_global_entry->common.hash_entry); + hash_added = hash_add(bat_priv->tt_global_hash, compare_tt, + choose_orig, &tt_global_entry->common, + &tt_global_entry->common.hash_entry); + + if (unlikely(hash_added != 0)) { + /* remove the reference for the hash */ + tt_global_entry_free_ref(tt_global_entry); + goto out_remove; + } atomic_inc(&orig_node->tt_size); } else { if (tt_global_entry->orig_node != orig_node) { @@ -543,6 +558,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, "Creating new global tt entry: %pM (via %pM)\n", tt_global_entry->common.addr, orig_node->orig); +out_remove: /* remove address from local hash if present */ tt_local_remove(bat_priv, tt_global_entry->common.addr, "global tt received", roaming);