From patchwork Thu Sep 30 12:08:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 506 Return-Path: Received: from smtp129.mail.ukl.yahoo.com (smtp129.mail.ukl.yahoo.com [77.238.184.60]) by open-mesh.org (Postfix) with SMTP id 6FD9915448A for ; Thu, 30 Sep 2010 14:10:22 +0200 (CEST) Received: (qmail 4563 invoked from network); 30 Sep 2010 12:10:21 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=Vzxg1olSVyvzaSNW0tcX001yz4CpX7rMk+KAq+mz4/530op/RUbvLawt/eQ2USnlce5iBurFl78sFFkIGSJZJIfg+Ka3J9vy6L9iYjO3OFkeCopqAYmSYXSk7Fzr++cTR9Ivz/ca0LN8sLrC/nUt+5zc+SlTzPsrVo6pELAgdBE= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1285848621; bh=/D5kqULH5Bu35g81ax1RyQV991VNeGfZb5VLn2MC9K0=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=kcg48J4iP330jb8or3tjaLg5KGtttYsxIaDnz+0u7XQOF1lCcWp1Ib+2q0aAXBeu9slsG47cCXTTH1I+0DkNnLyQuFga8axvxA/220YjDeCLXmIqybtkz5ZvrzUNUgIimodCMlF1XdRWdqNZaLZ/Lp4V8q6dIQd2bVesJAXfvnA= Received: from localhost (lindner_marek@78.225.40.81 with plain) by smtp129.mail.ukl.yahoo.com with SMTP; 30 Sep 2010 12:10:20 +0000 GMT X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- X-YMail-OSG: ARjn7OAVM1lgOvKFq.50D7cOSFHHe_PNJdys5.Wdf9Q46lv EWdsN0oTgSXjzXR6K_rCPj7Di0pDI1vJyW1rmTrRyBz5bhFcSjI1WxSEjbHJ JBp.3AMYRk7P_A8bo40CMPNwXFjJyvWGOk.cjyHFdSdoc6tx4qKAd_jfOqh9 KcOyfpNErvTYlmGmyqz7mUkGPfBuAl5p9vWMAJe3.z4tuih9XpIgTtyNHiMg KOSTlPVl7I1gA12vCEMs1uzPKNZI2iMEQ7u5jep_r X-Yahoo-Newman-Property: ymail-3 From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 30 Sep 2010 14:08:41 +0200 Message-Id: <1285848524-13469-2-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1285848524-13469-1-git-send-email-lindner_marek@yahoo.de> References: <1285848524-13469-1-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 1/4] batman-adv: convert gw_node custom refcounting to kref functions X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 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: Thu, 30 Sep 2010 12:10:23 -0000 Signed-off-by: Marek Lindner --- batman-adv/gateway_client.c | 24 ++++++++++-------------- batman-adv/types.h | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/batman-adv/gateway_client.c b/batman-adv/gateway_client.c index e1264ba..d275560 100644 --- a/batman-adv/gateway_client.c +++ b/batman-adv/gateway_client.c @@ -28,15 +28,12 @@ #include #include -static void gw_node_hold(struct gw_node *gw_node) +static void gw_node_free_ref(struct kref *refcount) { - atomic_inc(&gw_node->refcnt); -} + struct gw_node *gw_node; -static void gw_node_put(struct gw_node *gw_node) -{ - if (atomic_dec_and_test(&gw_node->refcnt)) - kfree(gw_node); + gw_node = container_of(refcount, struct gw_node, refcount); + kfree(gw_node); } void *gw_get_selected(struct bat_priv *bat_priv) @@ -56,7 +53,7 @@ void gw_deselect(struct bat_priv *bat_priv) bat_priv->curr_gw = NULL; if (gw_node) - gw_node_put(gw_node); + kref_put(&gw_node->refcount, gw_node_free_ref); } static struct gw_node *gw_select(struct bat_priv *bat_priv, @@ -65,7 +62,7 @@ static struct gw_node *gw_select(struct bat_priv *bat_priv, struct gw_node *curr_gw_node = bat_priv->curr_gw; if (new_gw_node) - gw_node_hold(new_gw_node); + kref_get(&new_gw_node->refcount); bat_priv->curr_gw = new_gw_node; return curr_gw_node; @@ -176,7 +173,7 @@ void gw_election(struct bat_priv *bat_priv) /* the kfree() has to be outside of the rcu lock */ if (old_gw_node) - gw_node_put(old_gw_node); + kref_put(&old_gw_node->refcount, gw_node_free_ref); } void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node) @@ -238,8 +235,7 @@ static void gw_node_add(struct bat_priv *bat_priv, memset(gw_node, 0, sizeof(struct gw_node)); INIT_HLIST_NODE(&gw_node->list); gw_node->orig_node = orig_node; - atomic_set(&gw_node->refcnt, 0); - gw_node_hold(gw_node); + kref_init(&gw_node->refcount); spin_lock_irqsave(&bat_priv->gw_list_lock, flags); hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list); @@ -319,7 +315,7 @@ void gw_node_purge_deleted(struct bat_priv *bat_priv) hlist_del_rcu(&gw_node->list); synchronize_rcu(); - gw_node_put(gw_node); + kref_put(&gw_node->refcount, gw_node_free_ref); } } @@ -338,7 +334,7 @@ void gw_node_list_free(struct bat_priv *bat_priv) &bat_priv->gw_list, list) { hlist_del_rcu(&gw_node->list); synchronize_rcu(); - gw_node_put(gw_node); + kref_put(&gw_node->refcount, gw_node_free_ref); } gw_deselect(bat_priv); diff --git a/batman-adv/types.h b/batman-adv/types.h index a609100..f5d29e6 100644 --- a/batman-adv/types.h +++ b/batman-adv/types.h @@ -96,7 +96,7 @@ struct gw_node { struct hlist_node list; struct orig_node *orig_node; unsigned long deleted; - atomic_t refcnt; + struct kref refcount; }; /**