[JFFS2] Prevent oops after 'node added in wrong place' debug check
[safe/jmp/linux-2.6] / net / sched / cls_u32.c
index 2b67047..8dbe369 100644 (file)
  *     nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
  */
 
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <linux/bitops.h>
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/socket.h>
-#include <linux/sockios.h>
-#include <linux/in.h>
 #include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/if_ether.h>
-#include <linux/inet.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/notifier.h>
 #include <linux/rtnetlink.h>
-#include <net/ip.h>
-#include <net/route.h>
 #include <linux/skbuff.h>
-#include <net/sock.h>
+#include <net/netlink.h>
 #include <net/act_api.h>
 #include <net/pkt_cls.h>
 
@@ -121,7 +104,7 @@ static int u32_classify(struct sk_buff *skb, struct tcf_proto *tp, struct tcf_re
        } stack[TC_U32_MAXDEPTH];
 
        struct tc_u_hnode *ht = (struct tc_u_hnode*)tp->root;
-       u8 *ptr = skb->nh.raw;
+       u8 *ptr = skb_network_header(skb);
        struct tc_u_knode *n;
        int sdepth = 0;
        int off2 = 0;
@@ -144,7 +127,7 @@ next_knode:
 #endif
 
 #ifdef CONFIG_CLS_U32_MARK
-               if ((skb->nfmark & n->mark.mask) != n->mark.val) {
+               if ((skb->mark & n->mark.mask) != n->mark.val) {
                        n = n->next;
                        goto next_knode;
                } else {
@@ -215,7 +198,7 @@ check_terminal:
                        off2 = 0;
                }
 
-               if (ptr < skb->tail)
+               if (ptr < skb_tail_pointer(skb))
                        goto next_ht;
        }
 
@@ -308,23 +291,21 @@ static int u32_init(struct tcf_proto *tp)
                if (tp_c->q == tp->q)
                        break;
 
-       root_ht = kmalloc(sizeof(*root_ht), GFP_KERNEL);
+       root_ht = kzalloc(sizeof(*root_ht), GFP_KERNEL);
        if (root_ht == NULL)
                return -ENOBUFS;
 
-       memset(root_ht, 0, sizeof(*root_ht));
        root_ht->divisor = 0;
        root_ht->refcnt++;
        root_ht->handle = tp_c ? gen_new_htid(tp_c) : 0x80000000;
        root_ht->prio = tp->prio;
 
        if (tp_c == NULL) {
-               tp_c = kmalloc(sizeof(*tp_c), GFP_KERNEL);
+               tp_c = kzalloc(sizeof(*tp_c), GFP_KERNEL);
                if (tp_c == NULL) {
                        kfree(root_ht);
                        return -ENOBUFS;
                }
-               memset(tp_c, 0, sizeof(*tp_c));
                tp_c->q = tp->q;
                tp_c->next = u32_list;
                u32_list = tp_c;
@@ -347,8 +328,7 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
        if (n->ht_down)
                n->ht_down->refcnt--;
 #ifdef CONFIG_CLS_U32_PERF
-       if (n)
-               kfree(n->pf);
+       kfree(n->pf);
 #endif
        kfree(n);
        return 0;
@@ -440,7 +420,7 @@ static void u32_destroy(struct tcf_proto *tp)
                        BUG_TRAP(ht->refcnt == 0);
 
                        kfree(ht);
-               };
+               }
 
                kfree(tp_c);
        }
@@ -573,10 +553,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                        if (handle == 0)
                                return -ENOMEM;
                }
-               ht = kmalloc(sizeof(*ht) + divisor*sizeof(void*), GFP_KERNEL);
+               ht = kzalloc(sizeof(*ht) + divisor*sizeof(void*), GFP_KERNEL);
                if (ht == NULL)
                        return -ENOBUFS;
-               memset(ht, 0, sizeof(*ht) + divisor*sizeof(void*));
                ht->tp_c = tp_c;
                ht->refcnt = 0;
                ht->divisor = divisor;
@@ -619,18 +598,16 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
 
        s = RTA_DATA(tb[TCA_U32_SEL-1]);
 
-       n = kmalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL);
+       n = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL);
        if (n == NULL)
                return -ENOBUFS;
 
-       memset(n, 0, sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key));
 #ifdef CONFIG_CLS_U32_PERF
-       n->pf = kmalloc(sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64), GFP_KERNEL);
+       n->pf = kzalloc(sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64), GFP_KERNEL);
        if (n->pf == NULL) {
                kfree(n);
                return -ENOBUFS;
        }
-       memset(n->pf, 0, sizeof(struct tc_u32_pcnt) + s->nkeys*sizeof(u64));
 #endif
 
        memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
@@ -680,8 +657,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
                return 0;
        }
 #ifdef CONFIG_CLS_U32_PERF
-       if (n)
-               kfree(n->pf);
+       kfree(n->pf);
 #endif
        kfree(n);
        return err;
@@ -727,7 +703,7 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
                     struct sk_buff *skb, struct tcmsg *t)
 {
        struct tc_u_knode *n = (struct tc_u_knode*)fh;
-       unsigned char    *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
        struct rtattr *rta;
 
        if (n == NULL)
@@ -768,20 +744,20 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
                        RTA_PUT(skb, TCA_U32_INDEV, IFNAMSIZ, n->indev);
 #endif
 #ifdef CONFIG_CLS_U32_PERF
-               RTA_PUT(skb, TCA_U32_PCNT, 
+               RTA_PUT(skb, TCA_U32_PCNT,
                sizeof(struct tc_u32_pcnt) + n->sel.nkeys*sizeof(u64),
                        n->pf);
 #endif
        }
 
-       rta->rta_len = skb->tail - b;
+       rta->rta_len = skb_tail_pointer(skb) - b;
        if (TC_U32_KEY(n->handle))
                if (tcf_exts_dump_stats(skb, &n->exts, &u32_ext_map) < 0)
                        goto rtattr_failure;
        return skb->len;
 
 rtattr_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -804,10 +780,7 @@ static int __init init_u32(void)
 {
        printk("u32 classifier\n");
 #ifdef CONFIG_CLS_U32_PERF
-       printk("    Perfomance counters on\n");
-#endif
-#ifdef CONFIG_NET_CLS_POLICE
-       printk("    OLD policer on \n");
+       printk("    Performance counters on\n");
 #endif
 #ifdef CONFIG_NET_CLS_IND
        printk("    input device check on \n");
@@ -818,7 +791,7 @@ static int __init init_u32(void)
        return register_tcf_proto_ops(&cls_u32_ops);
 }
 
-static void __exit exit_u32(void) 
+static void __exit exit_u32(void)
 {
        unregister_tcf_proto_ops(&cls_u32_ops);
 }