]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/sched/cls_route.c
usb gadget: fix platform driver hotplug/coldplug
[linux-2.6-omap-h63xx.git] / net / sched / cls_route.c
index 3aa8109aa3ce67c4c67869f065e97da20d1c7116..784dcb870b98181032e2b40d7a37ab3a60445eb1 100644 (file)
@@ -62,7 +62,7 @@ struct route4_filter
 
 #define ROUTE4_FAILURE ((struct route4_filter*)(-1L))
 
-static struct tcf_ext_map route_ext_map = {
+static const struct tcf_ext_map route_ext_map = {
        .police = TCA_ROUTE4_POLICE,
        .action = TCA_ROUTE4_ACT
 };
@@ -323,6 +323,13 @@ static int route4_delete(struct tcf_proto *tp, unsigned long arg)
        return 0;
 }
 
+static const struct nla_policy route4_policy[TCA_ROUTE4_MAX + 1] = {
+       [TCA_ROUTE4_CLASSID]    = { .type = NLA_U32 },
+       [TCA_ROUTE4_TO]         = { .type = NLA_U32 },
+       [TCA_ROUTE4_FROM]       = { .type = NLA_U32 },
+       [TCA_ROUTE4_IIF]        = { .type = NLA_U32 },
+};
+
 static int route4_set_parms(struct tcf_proto *tp, unsigned long base,
        struct route4_filter *f, u32 handle, struct route4_head *head,
        struct nlattr **tb, struct nlattr *est, int new)
@@ -339,16 +346,10 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base,
                return err;
 
        err = -EINVAL;
-       if (tb[TCA_ROUTE4_CLASSID])
-               if (nla_len(tb[TCA_ROUTE4_CLASSID]) < sizeof(u32))
-                       goto errout;
-
        if (tb[TCA_ROUTE4_TO]) {
                if (new && handle & 0x8000)
                        goto errout;
-               if (nla_len(tb[TCA_ROUTE4_TO]) < sizeof(u32))
-                       goto errout;
-               to = *(u32*)nla_data(tb[TCA_ROUTE4_TO]);
+               to = nla_get_u32(tb[TCA_ROUTE4_TO]);
                if (to > 0xFF)
                        goto errout;
                nhandle = to;
@@ -357,16 +358,12 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base,
        if (tb[TCA_ROUTE4_FROM]) {
                if (tb[TCA_ROUTE4_IIF])
                        goto errout;
-               if (nla_len(tb[TCA_ROUTE4_FROM]) < sizeof(u32))
-                       goto errout;
-               id = *(u32*)nla_data(tb[TCA_ROUTE4_FROM]);
+               id = nla_get_u32(tb[TCA_ROUTE4_FROM]);
                if (id > 0xFF)
                        goto errout;
                nhandle |= id << 16;
        } else if (tb[TCA_ROUTE4_IIF]) {
-               if (nla_len(tb[TCA_ROUTE4_IIF]) < sizeof(u32))
-                       goto errout;
-               id = *(u32*)nla_data(tb[TCA_ROUTE4_IIF]);
+               id = nla_get_u32(tb[TCA_ROUTE4_IIF]);
                if (id > 0x7FFF)
                        goto errout;
                nhandle |= (id | 0x8000) << 16;
@@ -411,7 +408,7 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base,
        tcf_tree_unlock(tp);
 
        if (tb[TCA_ROUTE4_CLASSID]) {
-               f->res.classid = *(u32*)nla_data(tb[TCA_ROUTE4_CLASSID]);
+               f->res.classid = nla_get_u32(tb[TCA_ROUTE4_CLASSID]);
                tcf_bind_filter(tp, &f->res, base);
        }
 
@@ -440,7 +437,7 @@ static int route4_change(struct tcf_proto *tp, unsigned long base,
        if (opt == NULL)
                return handle ? -EINVAL : 0;
 
-       err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, NULL);
+       err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, route4_policy);
        if (err < 0)
                return err;
 
@@ -551,7 +548,7 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh,
 {
        struct route4_filter *f = (struct route4_filter*)fh;
        unsigned char *b = skb_tail_pointer(skb);
-       struct nlattr *nla;
+       struct nlattr *nest;
        u32 id;
 
        if (f == NULL)
@@ -559,27 +556,28 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh,
 
        t->tcm_handle = f->handle;
 
-       nla = (struct nlattr*)b;
-       NLA_PUT(skb, TCA_OPTIONS, 0, NULL);
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
 
        if (!(f->handle&0x8000)) {
                id = f->id&0xFF;
-               NLA_PUT(skb, TCA_ROUTE4_TO, sizeof(id), &id);
+               NLA_PUT_U32(skb, TCA_ROUTE4_TO, id);
        }
        if (f->handle&0x80000000) {
                if ((f->handle>>16) != 0xFFFF)
-                       NLA_PUT(skb, TCA_ROUTE4_IIF, sizeof(f->iif), &f->iif);
+                       NLA_PUT_U32(skb, TCA_ROUTE4_IIF, f->iif);
        } else {
                id = f->id>>16;
-               NLA_PUT(skb, TCA_ROUTE4_FROM, sizeof(id), &id);
+               NLA_PUT_U32(skb, TCA_ROUTE4_FROM, id);
        }
        if (f->res.classid)
-               NLA_PUT(skb, TCA_ROUTE4_CLASSID, 4, &f->res.classid);
+               NLA_PUT_U32(skb, TCA_ROUTE4_CLASSID, f->res.classid);
 
        if (tcf_exts_dump(skb, &f->exts, &route_ext_map) < 0)
                goto nla_put_failure;
 
-       nla->nla_len = skb_tail_pointer(skb) - b;
+       nla_nest_end(skb, nest);
 
        if (tcf_exts_dump_stats(skb, &f->exts, &route_ext_map) < 0)
                goto nla_put_failure;