Merge branch 'topic/misc' into for-linus
[safe/jmp/linux-2.6] / net / sched / cls_u32.c
index 4d75544..17c5dfc 100644 (file)
@@ -31,6 +31,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -75,7 +76,6 @@ struct tc_u_hnode
 
 struct tc_u_common
 {
-       struct tc_u_common      *next;
        struct tc_u_hnode       *hlist;
        struct Qdisc            *q;
        int                     refcnt;
@@ -87,8 +87,6 @@ static const struct tcf_ext_map u32_ext_map = {
        .police = TCA_U32_POLICE
 };
 
-static struct tc_u_common *u32_list;
-
 static __inline__ unsigned u32_hash_fold(__be32 key, struct tc_u32_sel *sel, u8 fshift)
 {
        unsigned h = ntohl(key & sel->hmask)>>fshift;
@@ -287,9 +285,7 @@ static int u32_init(struct tcf_proto *tp)
        struct tc_u_hnode *root_ht;
        struct tc_u_common *tp_c;
 
-       for (tp_c = u32_list; tp_c; tp_c = tp_c->next)
-               if (tp_c->q == tp->q)
-                       break;
+       tp_c = tp->q->u32_node;
 
        root_ht = kzalloc(sizeof(*root_ht), GFP_KERNEL);
        if (root_ht == NULL)
@@ -307,8 +303,7 @@ static int u32_init(struct tcf_proto *tp)
                        return -ENOBUFS;
                }
                tp_c->q = tp->q;
-               tp_c->next = u32_list;
-               u32_list = tp_c;
+               tp->q->u32_node = tp_c;
        }
 
        tp_c->refcnt++;
@@ -351,7 +346,7 @@ static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key)
                        }
                }
        }
-       BUG_TRAP(0);
+       WARN_ON(1);
        return 0;
 }
 
@@ -374,7 +369,7 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
        struct tc_u_common *tp_c = tp->data;
        struct tc_u_hnode **hn;
 
-       BUG_TRAP(!ht->refcnt);
+       WARN_ON(ht->refcnt);
 
        u32_clear_hnode(tp, ht);
 
@@ -386,30 +381,24 @@ static int u32_destroy_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht)
                }
        }
 
-       BUG_TRAP(0);
+       WARN_ON(1);
        return -ENOENT;
 }
 
 static void u32_destroy(struct tcf_proto *tp)
 {
        struct tc_u_common *tp_c = tp->data;
-       struct tc_u_hnode *root_ht = xchg(&tp->root, NULL);
+       struct tc_u_hnode *root_ht = tp->root;
 
-       BUG_TRAP(root_ht != NULL);
+       WARN_ON(root_ht == NULL);
 
        if (root_ht && --root_ht->refcnt == 0)
                u32_destroy_hnode(tp, root_ht);
 
        if (--tp_c->refcnt == 0) {
                struct tc_u_hnode *ht;
-               struct tc_u_common **tp_cp;
 
-               for (tp_cp = &u32_list; *tp_cp; tp_cp = &(*tp_cp)->next) {
-                       if (*tp_cp == tp_c) {
-                               *tp_cp = tp_c->next;
-                               break;
-                       }
-               }
+               tp->q->u32_node = NULL;
 
                for (ht = tp_c->hlist; ht; ht = ht->next) {
                        ht->refcnt--;
@@ -419,7 +408,7 @@ static void u32_destroy(struct tcf_proto *tp)
                while ((ht = tp_c->hlist) != NULL) {
                        tp_c->hlist = ht->next;
 
-                       BUG_TRAP(ht->refcnt == 0);
+                       WARN_ON(ht->refcnt != 0);
 
                        kfree(ht);
                }
@@ -491,7 +480,7 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
        err = -EINVAL;
        if (tb[TCA_U32_LINK]) {
                u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
-               struct tc_u_hnode *ht_down = NULL;
+               struct tc_u_hnode *ht_down = NULL, *ht_old;
 
                if (TC_U32_KEY(handle))
                        goto errout;
@@ -505,11 +494,12 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base,
                }
 
                tcf_tree_lock(tp);
-               ht_down = xchg(&n->ht_down, ht_down);
+               ht_old = n->ht_down;
+               n->ht_down = ht_down;
                tcf_tree_unlock(tp);
 
-               if (ht_down)
-                       ht_down->refcnt--;
+               if (ht_old)
+                       ht_old->refcnt--;
        }
        if (tb[TCA_U32_CLASSID]) {
                n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
@@ -649,8 +639,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                                break;
 
                n->next = *ins;
-               wmb();
+               tcf_tree_lock(tp);
                *ins = n;
+               tcf_tree_unlock(tp);
 
                *arg = (unsigned long)n;
                return 0;