aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2013-12-15 23:15:11 -0500
committerDavid S. Miller <davem@davemloft.net>2013-12-18 12:52:08 -0500
commit3627287463b4acddb83d24fabb1e0a304e39565c (patch)
treee21fb125479524e1e2f765603283f2070cef80bc
parent1f747c26c48bb290c79c34e155860c7e2ec3926a (diff)
net_sched: convert tcf_proto_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/sch_generic.h2
-rw-r--r--net/sched/cls_api.c18
2 files changed, 9 insertions, 11 deletions
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index d0a6321c302e..013d96dc6918 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -185,7 +185,7 @@ struct tcf_result {
185}; 185};
186 186
187struct tcf_proto_ops { 187struct tcf_proto_ops {
188 struct tcf_proto_ops *next; 188 struct list_head head;
189 char kind[IFNAMSIZ]; 189 char kind[IFNAMSIZ];
190 190
191 int (*classify)(struct sk_buff *, 191 int (*classify)(struct sk_buff *,
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 028c980ef87d..6b085cf27a65 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -31,8 +31,7 @@
31#include <net/pkt_cls.h> 31#include <net/pkt_cls.h>
32 32
33/* The list of all installed classifier types */ 33/* The list of all installed classifier types */
34 34static LIST_HEAD(tcf_proto_base);
35static struct tcf_proto_ops *tcf_proto_base __read_mostly;
36 35
37/* Protects list of registered TC modules. It is pure SMP lock. */ 36/* Protects list of registered TC modules. It is pure SMP lock. */
38static DEFINE_RWLOCK(cls_mod_lock); 37static DEFINE_RWLOCK(cls_mod_lock);
@@ -45,7 +44,7 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)
45 44
46 if (kind) { 45 if (kind) {
47 read_lock(&cls_mod_lock); 46 read_lock(&cls_mod_lock);
48 for (t = tcf_proto_base; t; t = t->next) { 47 list_for_each_entry(t, &tcf_proto_base, head) {
49 if (nla_strcmp(kind, t->kind) == 0) { 48 if (nla_strcmp(kind, t->kind) == 0) {
50 if (!try_module_get(t->owner)) 49 if (!try_module_get(t->owner))
51 t = NULL; 50 t = NULL;
@@ -61,16 +60,15 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)
61 60
62int register_tcf_proto_ops(struct tcf_proto_ops *ops) 61int register_tcf_proto_ops(struct tcf_proto_ops *ops)
63{ 62{
64 struct tcf_proto_ops *t, **tp; 63 struct tcf_proto_ops *t;
65 int rc = -EEXIST; 64 int rc = -EEXIST;
66 65
67 write_lock(&cls_mod_lock); 66 write_lock(&cls_mod_lock);
68 for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next) 67 list_for_each_entry(t, &tcf_proto_base, head)
69 if (!strcmp(ops->kind, t->kind)) 68 if (!strcmp(ops->kind, t->kind))
70 goto out; 69 goto out;
71 70
72 ops->next = NULL; 71 list_add_tail(&ops->head, &tcf_proto_base);
73 *tp = ops;
74 rc = 0; 72 rc = 0;
75out: 73out:
76 write_unlock(&cls_mod_lock); 74 write_unlock(&cls_mod_lock);
@@ -80,17 +78,17 @@ EXPORT_SYMBOL(register_tcf_proto_ops);
80 78
81int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) 79int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
82{ 80{
83 struct tcf_proto_ops *t, **tp; 81 struct tcf_proto_ops *t;
84 int rc = -ENOENT; 82 int rc = -ENOENT;
85 83
86 write_lock(&cls_mod_lock); 84 write_lock(&cls_mod_lock);
87 for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next) 85 list_for_each_entry(t, &tcf_proto_base, head)
88 if (t == ops) 86 if (t == ops)
89 break; 87 break;
90 88
91 if (!t) 89 if (!t)
92 goto out; 90 goto out;
93 *tp = t->next; 91 list_del(&t->head);
94 rc = 0; 92 rc = 0;
95out: 93out:
96 write_unlock(&cls_mod_lock); 94 write_unlock(&cls_mod_lock);