Skip to content

Commit 6525410

Browse files
viviendavem330
authored andcommitted
net: dsa: get and put tree reference counting
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>
1 parent 8e5bf97 commit 6525410

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

net/dsa/dsa2.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ static struct dsa_switch_tree *dsa_get_dst(unsigned int index)
3838
return NULL;
3939
}
4040

41-
static void dsa_free_dst(struct kref *ref)
42-
{
43-
struct dsa_switch_tree *dst = container_of(ref, struct dsa_switch_tree,
44-
refcount);
45-
46-
list_del(&dst->list);
47-
kfree(dst);
48-
}
49-
5041
static struct dsa_switch_tree *dsa_add_dst(unsigned int index)
5142
{
5243
struct dsa_switch_tree *dst;
@@ -65,18 +56,43 @@ static struct dsa_switch_tree *dsa_add_dst(unsigned int index)
6556
return dst;
6657
}
6758

59+
static void dsa_tree_free(struct dsa_switch_tree *dst)
60+
{
61+
list_del(&dst->list);
62+
kfree(dst);
63+
}
64+
65+
static void dsa_tree_get(struct dsa_switch_tree *dst)
66+
{
67+
kref_get(&dst->refcount);
68+
}
69+
70+
static void dsa_tree_release(struct kref *ref)
71+
{
72+
struct dsa_switch_tree *dst;
73+
74+
dst = container_of(ref, struct dsa_switch_tree, refcount);
75+
76+
dsa_tree_free(dst);
77+
}
78+
79+
static void dsa_tree_put(struct dsa_switch_tree *dst)
80+
{
81+
kref_put(&dst->refcount, dsa_tree_release);
82+
}
83+
6884
static void dsa_dst_add_ds(struct dsa_switch_tree *dst,
6985
struct dsa_switch *ds, u32 index)
7086
{
71-
kref_get(&dst->refcount);
87+
dsa_tree_get(dst);
7288
dst->ds[index] = ds;
7389
}
7490

7591
static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
7692
struct dsa_switch *ds, u32 index)
7793
{
7894
dst->ds[index] = NULL;
79-
kref_put(&dst->refcount, dsa_free_dst);
95+
dsa_tree_put(dst);
8096
}
8197

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

0 commit comments

Comments
 (0)