diff options
author | Herbert Xu <herbert@lithui.me.apana.org.au> | 2017-12-22 04:00:50 -0500 |
---|---|---|
committer | Herbert Xu <herbert@lithui.me.apana.org.au> | 2017-12-22 04:00:50 -0500 |
commit | 45fa9a324d0f5be9140ba2e0db9b8fb8a0b9b7e8 (patch) | |
tree | a5e7c8428030ec0462b58133d6548ddff3802018 /net/dsa/dsa2.c | |
parent | fc8517bf627c9b834f80274a1bc9ecd39b27231b (diff) | |
parent | 2973633e9f09311e849f975d969737af81a521ff (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Merge the crypto tree to pick up inside-secure fixes.
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r-- | net/dsa/dsa2.c | 25 |
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 | ||
67 | static struct dsa_switch_tree *dsa_tree_touch(int index) | 65 | static 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 | ||
78 | static void dsa_tree_get(struct dsa_switch_tree *dst) | 73 | static 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 | ||
83 | static void dsa_tree_release(struct kref *ref) | 84 | static void dsa_tree_release(struct kref *ref) |
@@ -91,7 +92,8 @@ static void dsa_tree_release(struct kref *ref) | |||
91 | 92 | ||
92 | static void dsa_tree_put(struct dsa_switch_tree *dst) | 93 | static 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 | ||
97 | static bool dsa_port_is_dsa(struct dsa_port *port) | 99 | static 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; |