hwmon: add TI ads7871 a/d converter driver
[safe/jmp/linux-2.6] / net / sched / act_pedit.c
index 88d8a15..fdbd0b7 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <net/netlink.h>
 #include <net/pkt_sched.h>
 #include <linux/tc_act/tc_pedit.h>
@@ -33,22 +34,29 @@ static struct tcf_hashinfo pedit_hash_info = {
        .lock   =       &pedit_lock,
 };
 
+static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
+       [TCA_PEDIT_PARMS]       = { .len = sizeof(struct tc_pedit) },
+};
+
 static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
                          struct tc_action *a, int ovr, int bind)
 {
        struct nlattr *tb[TCA_PEDIT_MAX + 1];
        struct tc_pedit *parm;
-       int ret = 0;
+       int ret = 0, err;
        struct tcf_pedit *p;
        struct tcf_common *pc;
        struct tc_pedit_key *keys = NULL;
        int ksize;
 
-       if (nla == NULL || nla_parse_nested(tb, TCA_PEDIT_MAX, nla, NULL) < 0)
+       if (nla == NULL)
                return -EINVAL;
 
-       if (tb[TCA_PEDIT_PARMS] == NULL ||
-           nla_len(tb[TCA_PEDIT_PARMS]) < sizeof(*parm))
+       err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, pedit_policy);
+       if (err < 0)
+               return err;
+
+       if (tb[TCA_PEDIT_PARMS] == NULL)
                return -EINVAL;
        parm = nla_data(tb[TCA_PEDIT_PARMS]);
        ksize = parm->nkeys * sizeof(struct tc_pedit_key);
@@ -61,8 +69,8 @@ static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
                        return -EINVAL;
                pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
                                     &pedit_idx_gen, &pedit_hash_info);
-               if (unlikely(!pc))
-                       return -ENOMEM;
+               if (IS_ERR(pc))
+                   return PTR_ERR(pc);
                p = to_pedit(pc);
                keys = kmalloc(ksize, GFP_KERNEL);
                if (keys == NULL) {
@@ -150,11 +158,13 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
                        }
 
                        if (offset % 4) {
-                               printk("offset must be on 32 bit boundaries\n");
+                               pr_info("tc filter pedit"
+                                       " offset must be on 32 bit boundaries\n");
                                goto bad;
                        }
                        if (offset > 0 && offset > skb->len) {
-                               printk("offset %d cant exceed pkt length %d\n",
+                               pr_info("tc filter pedit"
+                                       " offset %d cant exceed pkt length %d\n",
                                       offset, skb->len);
                                goto bad;
                        }
@@ -168,14 +178,13 @@ static int tcf_pedit(struct sk_buff *skb, struct tc_action *a,
                if (munged)
                        skb->tc_verd = SET_TC_MUNGED(skb->tc_verd);
                goto done;
-       } else {
-               printk("pedit BUG: index %d\n", p->tcf_index);
-       }
+       } else
+               WARN(1, "pedit BUG: index %d\n", p->tcf_index);
 
 bad:
        p->tcf_qstats.overlimits++;
 done:
-       p->tcf_bstats.bytes += skb->len;
+       p->tcf_bstats.bytes += qdisc_pkt_len(skb);
        p->tcf_bstats.packets++;
        spin_unlock(&p->tcf_lock);
        return p->tcf_action;