Skip to content

Commit

Permalink
net: dsa: get and put tree reference counting
Browse files Browse the repository at this point in the history
Provide convenient dsa_tree_get and dsa_tree_put functions scoping a DSA
tree used to increment and decrement its reference counter, instead of
poking directly its kref structure.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vivien Didelot authored and David S. Miller committed Nov 5, 2017
1 parent 8e5bf97 commit 6525410
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ static struct dsa_switch_tree *dsa_get_dst(unsigned int index)
return NULL;
}

static void dsa_free_dst(struct kref *ref)
{
struct dsa_switch_tree *dst = container_of(ref, struct dsa_switch_tree,
refcount);

list_del(&dst->list);
kfree(dst);
}

static struct dsa_switch_tree *dsa_add_dst(unsigned int index)
{
struct dsa_switch_tree *dst;
Expand All @@ -65,18 +56,43 @@ static struct dsa_switch_tree *dsa_add_dst(unsigned int index)
return dst;
}

static void dsa_tree_free(struct dsa_switch_tree *dst)
{
list_del(&dst->list);
kfree(dst);
}

static void dsa_tree_get(struct dsa_switch_tree *dst)
{
kref_get(&dst->refcount);
}

static void dsa_tree_release(struct kref *ref)
{
struct dsa_switch_tree *dst;

dst = container_of(ref, struct dsa_switch_tree, refcount);

dsa_tree_free(dst);
}

static void dsa_tree_put(struct dsa_switch_tree *dst)
{
kref_put(&dst->refcount, dsa_tree_release);
}

static void dsa_dst_add_ds(struct dsa_switch_tree *dst,
struct dsa_switch *ds, u32 index)
{
kref_get(&dst->refcount);
dsa_tree_get(dst);
dst->ds[index] = ds;
}

static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
struct dsa_switch *ds, u32 index)
{
dst->ds[index] = NULL;
kref_put(&dst->refcount, dsa_free_dst);
dsa_tree_put(dst);
}

/* For platform data configurations, we need to have a valid name argument to
Expand Down

0 comments on commit 6525410

Please sign in to comment.