summaryrefslogtreecommitdiffstats
path: root/net/dsa/dsa2.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r--net/dsa/dsa2.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 44e3fb7dec8c..1e287420ff49 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -51,9 +51,7 @@ static struct dsa_switch_tree *dsa_tree_alloc(int index)
51 INIT_LIST_HEAD(&dst->list); 51 INIT_LIST_HEAD(&dst->list);
52 list_add_tail(&dsa_tree_list, &dst->list); 52 list_add_tail(&dsa_tree_list, &dst->list);
53 53
54 /* Initialize the reference counter to the number of switches, not 1 */
55 kref_init(&dst->refcount); 54 kref_init(&dst->refcount);
56 refcount_set(&dst->refcount.refcount, 0);
57 55
58 return dst; 56 return dst;
59} 57}
@@ -64,20 +62,23 @@ static void dsa_tree_free(struct dsa_switch_tree *dst)
64 kfree(dst); 62 kfree(dst);
65} 63}
66 64
67static struct dsa_switch_tree *dsa_tree_touch(int index) 65static struct dsa_switch_tree *dsa_tree_get(struct dsa_switch_tree *dst)
68{ 66{
69 struct dsa_switch_tree *dst; 67 if (dst)
70 68 kref_get(&dst->refcount);
71 dst = dsa_tree_find(index);
72 if (!dst)
73 dst = dsa_tree_alloc(index);
74 69
75 return dst; 70 return dst;
76} 71}
77 72
78static void dsa_tree_get(struct dsa_switch_tree *dst) 73static struct dsa_switch_tree *dsa_tree_touch(int index)
79{ 74{
80 kref_get(&dst->refcount); 75 struct dsa_switch_tree *dst;
76
77 dst = dsa_tree_find(index);
78 if (dst)
79 return dsa_tree_get(dst);
80 else
81 return dsa_tree_alloc(index);
81} 82}
82 83
83static void dsa_tree_release(struct kref *ref) 84static void dsa_tree_release(struct kref *ref)
@@ -91,7 +92,8 @@ static void dsa_tree_release(struct kref *ref)
91 92
92static void dsa_tree_put(struct dsa_switch_tree *dst) 93static void dsa_tree_put(struct dsa_switch_tree *dst)
93{ 94{
94 kref_put(&dst->refcount, dsa_tree_release); 95 if (dst)
96 kref_put(&dst->refcount, dsa_tree_release);
95} 97}
96 98
97static bool dsa_port_is_dsa(struct dsa_port *port) 99static bool dsa_port_is_dsa(struct dsa_port *port)
@@ -765,6 +767,7 @@ int dsa_register_switch(struct dsa_switch *ds)
765 767
766 mutex_lock(&dsa2_mutex); 768 mutex_lock(&dsa2_mutex);
767 err = dsa_switch_probe(ds); 769 err = dsa_switch_probe(ds);
770 dsa_tree_put(ds->dst);
768 mutex_unlock(&dsa2_mutex); 771 mutex_unlock(&dsa2_mutex);
769 772
770 return err; 773 return err;