Skip to content

Commit

Permalink
net_sched: convert tcf_proto_ops to use struct list_head
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
WANG Cong authored and David S. Miller committed Dec 18, 2013
1 parent 1f747c2 commit 3627287
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/net/sch_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct tcf_result {
};

struct tcf_proto_ops {
struct tcf_proto_ops *next;
struct list_head head;
char kind[IFNAMSIZ];

int (*classify)(struct sk_buff *,
Expand Down
18 changes: 8 additions & 10 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include <net/pkt_cls.h>

/* The list of all installed classifier types */

static struct tcf_proto_ops *tcf_proto_base __read_mostly;
static LIST_HEAD(tcf_proto_base);

/* Protects list of registered TC modules. It is pure SMP lock. */
static DEFINE_RWLOCK(cls_mod_lock);
Expand All @@ -45,7 +44,7 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)

if (kind) {
read_lock(&cls_mod_lock);
for (t = tcf_proto_base; t; t = t->next) {
list_for_each_entry(t, &tcf_proto_base, head) {
if (nla_strcmp(kind, t->kind) == 0) {
if (!try_module_get(t->owner))
t = NULL;
Expand All @@ -61,16 +60,15 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)

int register_tcf_proto_ops(struct tcf_proto_ops *ops)
{
struct tcf_proto_ops *t, **tp;
struct tcf_proto_ops *t;
int rc = -EEXIST;

write_lock(&cls_mod_lock);
for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next)
list_for_each_entry(t, &tcf_proto_base, head)
if (!strcmp(ops->kind, t->kind))
goto out;

ops->next = NULL;
*tp = ops;
list_add_tail(&ops->head, &tcf_proto_base);
rc = 0;
out:
write_unlock(&cls_mod_lock);
Expand All @@ -80,17 +78,17 @@ EXPORT_SYMBOL(register_tcf_proto_ops);

int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
{
struct tcf_proto_ops *t, **tp;
struct tcf_proto_ops *t;
int rc = -ENOENT;

write_lock(&cls_mod_lock);
for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next)
list_for_each_entry(t, &tcf_proto_base, head)
if (t == ops)
break;

if (!t)
goto out;
*tp = t->next;
list_del(&t->head);
rc = 0;
out:
write_unlock(&cls_mod_lock);
Expand Down

0 comments on commit 3627287

Please sign in to comment.