V4L/DVB (13590): cpia: convert it to use proc_fops
[safe/jmp/linux-2.6] / net / sched / act_api.c
index 26c7e1f..64f5e32 100644 (file)
@@ -214,12 +214,14 @@ struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind,
 }
 EXPORT_SYMBOL(tcf_hash_check);
 
-struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a, int size, int bind, u32 *idx_gen, struct tcf_hashinfo *hinfo)
+struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
+                                  struct tc_action *a, int size, int bind,
+                                  u32 *idx_gen, struct tcf_hashinfo *hinfo)
 {
        struct tcf_common *p = kzalloc(size, GFP_KERNEL);
 
        if (unlikely(!p))
-               return p;
+               return ERR_PTR(-ENOMEM);
        p->tcfc_refcnt = 1;
        if (bind)
                p->tcfc_bindcnt = 1;
@@ -228,9 +230,15 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_acti
        p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
        p->tcfc_tm.install = jiffies;
        p->tcfc_tm.lastuse = jiffies;
-       if (est)
-               gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
-                                 &p->tcfc_lock, est);
+       if (est) {
+               int err = gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
+                                           &p->tcfc_lock, est);
+               if (err) {
+                       kfree(p);
+                       return ERR_PTR(err);
+               }
+       }
+
        a->priv = (void *) p;
        return p;
 }
@@ -494,7 +502,7 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
 
        a_o = tc_lookup_action_n(act_name);
        if (a_o == NULL) {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
                rtnl_unlock();
                request_module("act_%s", act_name);
                rtnl_lock();
@@ -590,7 +598,7 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
                goto errout;
 
        /* compat_mode being true specifies a call that is supposed
-        * to add additional backward compatiblity statistic TLVs.
+        * to add additional backward compatibility statistic TLVs.
         */
        if (compat_mode) {
                if (a->type == TCA_OLD_COMPAT)
@@ -610,7 +618,8 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
                        goto errout;
 
        if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 ||
-           gnet_stats_copy_rate_est(&d, &h->tcf_rate_est) < 0 ||
+           gnet_stats_copy_rate_est(&d, &h->tcf_bstats,
+                                    &h->tcf_rate_est) < 0 ||
            gnet_stats_copy_queue(&d, &h->tcf_qstats) < 0)
                goto errout;
 
@@ -751,7 +760,7 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
        struct nlattr *tb[TCA_ACT_MAX+1];
        struct nlattr *kind;
        struct tc_action *a = create_a(0);
-       int err = -EINVAL;
+       int err = -ENOMEM;
 
        if (a == NULL) {
                printk("tca_action_flush: couldnt create tc_action\n");
@@ -762,7 +771,7 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
        if (!skb) {
                printk("tca_action_flush: failed skb alloc\n");
                kfree(a);
-               return -ENOBUFS;
+               return err;
        }
 
        b = skb_tail_pointer(skb);
@@ -790,6 +799,8 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
        err = a->ops->walk(skb, &dcb, RTM_DELACTION, a);
        if (err < 0)
                goto nla_put_failure;
+       if (err == 0)
+               goto noflush_out;
 
        nla_nest_end(skb, nest);
 
@@ -807,6 +818,7 @@ nla_put_failure:
 nlmsg_failure:
        module_put(a->ops->owner);
 err_out:
+noflush_out:
        kfree_skb(skb);
        kfree(a);
        return err;
@@ -824,8 +836,10 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
                return ret;
 
        if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) {
-               if (tb[0] != NULL && tb[1] == NULL)
-                       return tca_action_flush(tb[0], n, pid);
+               if (tb[1] != NULL)
+                       return tca_action_flush(tb[1], n, pid);
+               else
+                       return -EINVAL;
        }
 
        for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
@@ -955,7 +969,7 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
        u32 pid = skb ? NETLINK_CB(skb).pid : 0;
        int ret = 0, ovr = 0;
 
-       if (net != &init_net)
+       if (!net_eq(net, &init_net))
                return -EINVAL;
 
        ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
@@ -998,7 +1012,7 @@ replay:
 }
 
 static struct nlattr *
-find_dump_kind(struct nlmsghdr *n)
+find_dump_kind(const struct nlmsghdr *n)
 {
        struct nlattr *tb1, *tb2[TCA_ACT_MAX+1];
        struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
@@ -1038,7 +1052,7 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
        struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh);
        struct nlattr *kind = find_dump_kind(cb->nlh);
 
-       if (net != &init_net)
+       if (!net_eq(net, &init_net))
                return 0;
 
        if (kind == NULL) {