aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2013-12-15 23:15:10 -0500
committerDavid S. Miller <davem@davemloft.net>2013-12-18 12:52:07 -0500
commit1f747c26c48bb290c79c34e155860c7e2ec3926a (patch)
tree0a821ed2e74aef2a9569656040f805d4c762e3ab
parent89819dc01f4c5920783f561597a48d9d75220e9e (diff)
net_sched: convert tc_action_ops to use struct list_head
We don't need to maintain our own singly linked list code. Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/act_api.h2
-rw-r--r--net/sched/act_api.c20
2 files changed, 10 insertions, 12 deletions
diff --git a/include/net/act_api.h b/include/net/act_api.h
index 22418d1a8396..77d5d8156efc 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -85,7 +85,7 @@ struct tc_action {
85 85
86#define TCA_CAP_NONE 0 86#define TCA_CAP_NONE 0
87struct tc_action_ops { 87struct tc_action_ops {
88 struct tc_action_ops *next; 88 struct list_head head;
89 struct tcf_hashinfo *hinfo; 89 struct tcf_hashinfo *hinfo;
90 char kind[IFNAMSIZ]; 90 char kind[IFNAMSIZ];
91 __u32 type; /* TBD to match kind */ 91 __u32 type; /* TBD to match kind */
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index dc457c957656..8114fef308d9 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -255,12 +255,12 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
255} 255}
256EXPORT_SYMBOL(tcf_hash_insert); 256EXPORT_SYMBOL(tcf_hash_insert);
257 257
258static struct tc_action_ops *act_base = NULL; 258static LIST_HEAD(act_base);
259static DEFINE_RWLOCK(act_mod_lock); 259static DEFINE_RWLOCK(act_mod_lock);
260 260
261int tcf_register_action(struct tc_action_ops *act) 261int tcf_register_action(struct tc_action_ops *act)
262{ 262{
263 struct tc_action_ops *a, **ap; 263 struct tc_action_ops *a;
264 264
265 /* Must supply act, dump, cleanup and init */ 265 /* Must supply act, dump, cleanup and init */
266 if (!act->act || !act->dump || !act->cleanup || !act->init) 266 if (!act->act || !act->dump || !act->cleanup || !act->init)
@@ -273,14 +273,13 @@ int tcf_register_action(struct tc_action_ops *act)
273 act->walk = tcf_generic_walker; 273 act->walk = tcf_generic_walker;
274 274
275 write_lock(&act_mod_lock); 275 write_lock(&act_mod_lock);
276 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) { 276 list_for_each_entry(a, &act_base, head) {
277 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) { 277 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
278 write_unlock(&act_mod_lock); 278 write_unlock(&act_mod_lock);
279 return -EEXIST; 279 return -EEXIST;
280 } 280 }
281 } 281 }
282 act->next = NULL; 282 list_add_tail(&act->head, &act_base);
283 *ap = act;
284 write_unlock(&act_mod_lock); 283 write_unlock(&act_mod_lock);
285 return 0; 284 return 0;
286} 285}
@@ -288,16 +287,15 @@ EXPORT_SYMBOL(tcf_register_action);
288 287
289int tcf_unregister_action(struct tc_action_ops *act) 288int tcf_unregister_action(struct tc_action_ops *act)
290{ 289{
291 struct tc_action_ops *a, **ap; 290 struct tc_action_ops *a;
292 int err = -ENOENT; 291 int err = -ENOENT;
293 292
294 write_lock(&act_mod_lock); 293 write_lock(&act_mod_lock);
295 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) 294 list_for_each_entry(a, &act_base, head)
296 if (a == act) 295 if (a == act)
297 break; 296 break;
298 if (a) { 297 if (a) {
299 *ap = a->next; 298 list_del(&act->head);
300 a->next = NULL;
301 err = 0; 299 err = 0;
302 } 300 }
303 write_unlock(&act_mod_lock); 301 write_unlock(&act_mod_lock);
@@ -312,7 +310,7 @@ static struct tc_action_ops *tc_lookup_action_n(char *kind)
312 310
313 if (kind) { 311 if (kind) {
314 read_lock(&act_mod_lock); 312 read_lock(&act_mod_lock);
315 for (a = act_base; a; a = a->next) { 313 list_for_each_entry(a, &act_base, head) {
316 if (strcmp(kind, a->kind) == 0) { 314 if (strcmp(kind, a->kind) == 0) {
317 if (!try_module_get(a->owner)) { 315 if (!try_module_get(a->owner)) {
318 read_unlock(&act_mod_lock); 316 read_unlock(&act_mod_lock);
@@ -333,7 +331,7 @@ static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
333 331
334 if (kind) { 332 if (kind) {
335 read_lock(&act_mod_lock); 333 read_lock(&act_mod_lock);
336 for (a = act_base; a; a = a->next) { 334 list_for_each_entry(a, &act_base, head) {
337 if (nla_strcmp(kind, a->kind) == 0) { 335 if (nla_strcmp(kind, a->kind) == 0) {
338 if (!try_module_get(a->owner)) { 336 if (!try_module_get(a->owner)) {
339 read_unlock(&act_mod_lock); 337 read_unlock(&act_mod_lock);