From patchwork Mon Jun 18 20:39:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 165593 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 27441B7032 for ; Tue, 19 Jun 2012 06:39:27 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753456Ab2FRUjW (ORCPT ); Mon, 18 Jun 2012 16:39:22 -0400 Received: from latitanza.investici.org ([82.94.249.234]:41795 "EHLO latitanza.investici.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753413Ab2FRUjT (ORCPT ); Mon, 18 Jun 2012 16:39:19 -0400 Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 76E2B98218; Mon, 18 Jun 2012 20:39:17 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org 76E2B98218 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1340051958; bh=8YlxdqaEzXpMScEIUnwqDPxA+GaJzG8hsx5H+oS3HPY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=KQvs6OZd2G+hpAJ8o85RgUNZV5XWfK3vrWnzOghv5eYNZP9EFO1M9YalE7eWHgARf hIgSx0WMQkLdHPYmw404Qdtbd6uTwxHsdY8buWbOhuvot/P0wnEJHh911DveftD/T0 gnoNuVOZ+WaWr/+P5KmBKmfoaw0aX+SCDQAJ4gc0= From: Antonio Quartulli To: davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Matthias Schiffer , Sven Eckelmann , Antonio Quartulli Subject: [PATCH 18/19] batman-adv: fix locking in hash_add() Date: Mon, 18 Jun 2012 22:39:22 +0200 Message-Id: <1340051963-14836-19-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.9.4 In-Reply-To: <1340051963-14836-1-git-send-email-ordex@autistici.org> References: <1340051963-14836-1-git-send-email-ordex@autistici.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Matthias Schiffer To ensure an entry isn't added twice all comparisons have to be protected by the hash line write spinlock. This doesn't really hurt as the case that it is tried to add an element already present to the hash shouldn't occur very often, so in most cases the lock would have have to be taken anyways. Signed-off-by: Matthias Schiffer Acked-by: Sven Eckelmann Signed-off-by: Sven Eckelmann Signed-off-by: Antonio Quartulli --- net/batman-adv/hash.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h index 93b3c71..3d67ce4 100644 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@ -110,26 +110,23 @@ static inline int hash_add(struct hashtable_t *hash, head = &hash->table[index]; list_lock = &hash->list_locks[index]; - rcu_read_lock(); - __hlist_for_each_rcu(node, head) { + spin_lock_bh(list_lock); + + hlist_for_each(node, head) { if (!compare(node, data)) continue; ret = 1; - goto err_unlock; + goto unlock; } - rcu_read_unlock(); /* no duplicate found in list, add new element */ - spin_lock_bh(list_lock); hlist_add_head_rcu(data_node, head); - spin_unlock_bh(list_lock); ret = 0; - goto out; -err_unlock: - rcu_read_unlock(); +unlock: + spin_unlock_bh(list_lock); out: return ret; }