[v6,06/20] batman-adv: Convert batadv_bla_claim to kref
Commit Message
batman-adv uses a self-written reference implementation which is just based
on atomic_t. This is less obvious when reading the code than kref and
therefore increases the change that the reference counting will be missed.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
v6:
- removed patches which are now applied in the branch next
- rebased remaining patches on the patch
"batman-adv: Avoid recursive call_rcu for batadv_nc_node" which was
modified by Marek while he applied the patches (this unfortunately made
some of the remaining patches "hard" to apply)
v5:
- add hack which allows to compile against stable kernel like 3.2.44 which
also added the kref_get_unless_zero function
v4:
- fix function names in commit messages
- fix double whitespace in batadv_tt_orig_list_entry_release kerneldoc
- add extra patch for batadv_claim_free_ref kerneldoc fix
- change the phrase "free it" in all *_free_ref/*_put functions to "release it"
v3:
- update copyright year
v2:
- split patchset into fixes and kref migration to make it easier when the
decision is made where each patch will be applied
net/batman-adv/bridge_loop_avoidance.c | 16 ++++++++++------
net/batman-adv/types.h | 2 +-
2 files changed, 11 insertions(+), 7 deletions(-)
Comments
On Saturday, January 16, 2016 10:29:44 Sven Eckelmann wrote:
> batman-adv uses a self-written reference implementation which is just based
> on atomic_t. This is less obvious when reading the code than kref and
> therefore increases the change that the reference counting will be missed.
>
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> v6:
> - removed patches which are now applied in the branch next
> - rebased remaining patches on the patch
> "batman-adv: Avoid recursive call_rcu for batadv_nc_node" which was
> modified by Marek while he applied the patches (this unfortunately made
> some of the remaining patches "hard" to apply)
> v5:
> - add hack which allows to compile against stable kernel like 3.2.44 which
> also added the kref_get_unless_zero function
> v4:
> - fix function names in commit messages
> - fix double whitespace in batadv_tt_orig_list_entry_release kerneldoc
> - add extra patch for batadv_claim_free_ref kerneldoc fix
> - change the phrase "free it" in all *_free_ref/*_put functions to "release
> it" v3:
> - update copyright year
> v2:
> - split patchset into fixes and kref migration to make it easier when the
> decision is made where each patch will be applied
>
> net/batman-adv/bridge_loop_avoidance.c | 16 ++++++++++------
> net/batman-adv/types.h | 2 +-
> 2 files changed, 11 insertions(+), 7 deletions(-)
Applied in revision b7a53be.
Thanks,
Marek
@@ -172,10 +172,14 @@ batadv_backbone_gw_free_ref(struct batadv_bla_backbone_gw *backbone_gw)
/**
* batadv_claim_release - release claim from lists and queue for free after rcu
* grace period
- * @claim: claim to be free'd
+ * @ref: kref pointer of the claim
*/
-static void batadv_claim_release(struct batadv_bla_claim *claim)
+static void batadv_claim_release(struct kref *ref)
{
+ struct batadv_bla_claim *claim;
+
+ claim = container_of(ref, struct batadv_bla_claim, refcount);
+
batadv_backbone_gw_free_ref(claim->backbone_gw);
kfree_rcu(claim, rcu);
}
@@ -187,8 +191,7 @@ static void batadv_claim_release(struct batadv_bla_claim *claim)
*/
static void batadv_claim_free_ref(struct batadv_bla_claim *claim)
{
- if (atomic_dec_and_test(&claim->refcount))
- batadv_claim_release(claim);
+ kref_put(&claim->refcount, batadv_claim_release);
}
/**
@@ -219,7 +222,7 @@ static struct batadv_bla_claim
if (!batadv_compare_claim(&claim->hash_entry, data))
continue;
- if (!atomic_inc_not_zero(&claim->refcount))
+ if (!kref_get_unless_zero(&claim->refcount))
continue;
claim_tmp = claim;
@@ -651,7 +654,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
claim->lasttime = jiffies;
claim->backbone_gw = backbone_gw;
- atomic_set(&claim->refcount, 2);
+ kref_init(&claim->refcount);
+ kref_get(&claim->refcount);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
"bla_add_claim(): adding new entry %pM, vid %d to hash ...\n",
mac, BATADV_PRINT_VID(vid));
@@ -951,7 +951,7 @@ struct batadv_bla_claim {
unsigned long lasttime;
struct hlist_node hash_entry;
struct rcu_head rcu;
- atomic_t refcount;
+ struct kref refcount;
};
#endif