From patchwork Tue Dec 15 23:31:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 4772 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dkim=pass reason="1024-bit key; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=MYmcDdGa; dkim-adsp=pass; dkim-atps=neutral Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 4912C8194D for ; Wed, 16 Dec 2015 00:32:26 +0100 (CET) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a02:3100:260c:3afd:2066:82e6:79c1:88d8]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 9970B110111; Wed, 16 Dec 2015 00:32:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=20121; t=1450222345; bh=0u8QbczMqi/hMDDKF+N6BTPNEp80yPQtimCN2Qkklh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MYmcDdGa3jWU9sbEJR3Ux/4teF7TiUVkLpK2P5fW1tFGCfIJbus72FqHA1ENczXbh D2iqRX0v7W74bh3L+QGzTGSA+GZiggXaUbZhpj2SqmWCRG0Md/bHiUU8jLR/TMmodd pzdUCrvJ5wojOlO3psSwSDBcMrRvKH39FA6jAn8c= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 16 Dec 2015 00:31:43 +0100 Message-Id: <1450222316-1764-10-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1450222316-1764-1-git-send-email-sven@narfation.org> References: <1450222316-1764-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 10/23] batman-adv: Convert batadv_nc_node to kref X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list 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: Tue, 15 Dec 2015 23:32:26 -0000 So switch to kref instead of using the self-made, atomic_t-based implementation. Signed-off-by: Sven Eckelmann --- net/batman-adv/network-coding.c | 36 +++++++++++++++++++----------------- net/batman-adv/types.h | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c index 56100c5..246cd90 100644 --- a/net/batman-adv/network-coding.c +++ b/net/batman-adv/network-coding.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -207,28 +208,28 @@ void batadv_nc_init_orig(struct batadv_orig_node *orig_node) } /** - * batadv_nc_node_free_rcu - rcu callback to free an nc node and remove - * its refcount on the orig_node - * @rcu: rcu pointer of the nc node + * batadv_nc_node_release - release nc_node from lists and queue for free after + * rcu grace period + * * @ref: kref pointer of the nc_node */ -static void batadv_nc_node_free_rcu(struct rcu_head *rcu) +static void batadv_nc_node_release(struct kref *ref) { struct batadv_nc_node *nc_node; - nc_node = container_of(rcu, struct batadv_nc_node, rcu); + nc_node = container_of(ref, struct batadv_nc_node, refcount); + batadv_orig_node_free_ref(nc_node->orig_node); - kfree(nc_node); + kfree_rcu(nc_node, rcu); } /** - * batadv_nc_node_free_ref - decrements the nc node refcounter and possibly - * frees it - * @nc_node: the nc node to free + * batadv_nc_node_put - decrement the nc_node refcounter and possibly + * release it + * @nc_node: nc_node to be free'd */ -static void batadv_nc_node_free_ref(struct batadv_nc_node *nc_node) +static void batadv_nc_node_put(struct batadv_nc_node *nc_node) { - if (atomic_dec_and_test(&nc_node->refcount)) - call_rcu(&nc_node->rcu, batadv_nc_node_free_rcu); + kref_put(&nc_node->refcount, batadv_nc_node_release); } /** @@ -342,7 +343,7 @@ batadv_nc_purge_orig_nc_nodes(struct batadv_priv *bat_priv, "Removing nc_node %pM -> %pM\n", nc_node->addr, nc_node->orig_node->orig); list_del_rcu(&nc_node->list); - batadv_nc_node_free_ref(nc_node); + batadv_nc_node_put(nc_node); } spin_unlock_bh(lock); } @@ -800,7 +801,7 @@ static struct batadv_nc_node if (!batadv_compare_eth(nc_node->addr, orig_node->orig)) continue; - if (!atomic_inc_not_zero(&nc_node->refcount)) + if (!kref_get_unless_zero(&nc_node->refcount)) continue; /* Found a match */ @@ -851,7 +852,8 @@ static struct batadv_nc_node INIT_LIST_HEAD(&nc_node->list); ether_addr_copy(nc_node->addr, orig_node->orig); nc_node->orig_node = orig_neigh_node; - atomic_set(&nc_node->refcount, 2); + kref_init(&nc_node->refcount); + kref_get(&nc_node->refcount); /* Select ingoing or outgoing coding node */ if (in_coding) { @@ -927,9 +929,9 @@ void batadv_nc_update_nc_node(struct batadv_priv *bat_priv, out: if (in_nc_node) - batadv_nc_node_free_ref(in_nc_node); + batadv_nc_node_put(in_nc_node); if (out_nc_node) - batadv_nc_node_free_ref(out_nc_node); + batadv_nc_node_put(out_nc_node); } /** diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index c56b99c..9a2371a 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1067,7 +1067,7 @@ struct batadv_tt_roam_node { struct batadv_nc_node { struct list_head list; u8 addr[ETH_ALEN]; - atomic_t refcount; + struct kref refcount; struct rcu_head rcu; struct batadv_orig_node *orig_node; unsigned long last_seen;