Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[firefly-linux-kernel-4.4.55.git] / net / sched / cls_api.c
index 6b085cf27a65cfbbdcf319c061ce23c174ac4fbe..29a30a14c31596cc51028be8db46eb4df9756f6e 100644 (file)
@@ -40,20 +40,20 @@ static DEFINE_RWLOCK(cls_mod_lock);
 
 static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)
 {
-       const struct tcf_proto_ops *t = NULL;
+       const struct tcf_proto_ops *t, *res = NULL;
 
        if (kind) {
                read_lock(&cls_mod_lock);
                list_for_each_entry(t, &tcf_proto_base, head) {
                        if (nla_strcmp(kind, t->kind) == 0) {
-                               if (!try_module_get(t->owner))
-                                       t = NULL;
+                               if (try_module_get(t->owner))
+                                       res = t;
                                break;
                        }
                }
                read_unlock(&cls_mod_lock);
        }
-       return t;
+       return res;
 }
 
 /* Register(unregister) new classifier type */
@@ -82,15 +82,13 @@ int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
        int rc = -ENOENT;
 
        write_lock(&cls_mod_lock);
-       list_for_each_entry(t, &tcf_proto_base, head)
-               if (t == ops)
+       list_for_each_entry(t, &tcf_proto_base, head) {
+               if (t == ops) {
+                       list_del(&t->head);
+                       rc = 0;
                        break;
-
-       if (!t)
-               goto out;
-       list_del(&t->head);
-       rc = 0;
-out:
+               }
+       }
        write_unlock(&cls_mod_lock);
        return rc;
 }
@@ -342,7 +340,7 @@ errout:
        return err;
 }
 
-static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
+static int tcf_fill_node(struct net *net, struct sk_buff *skb, struct tcf_proto *tp,
                         unsigned long fh, u32 portid, u32 seq, u16 flags, int event)
 {
        struct tcmsg *tcm;
@@ -364,7 +362,7 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
        tcm->tcm_handle = fh;
        if (RTM_DELTFILTER != event) {
                tcm->tcm_handle = 0;
-               if (tp->ops->dump && tp->ops->dump(tp, fh, skb, tcm) < 0)
+               if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0)
                        goto nla_put_failure;
        }
        nlh->nlmsg_len = skb_tail_pointer(skb) - b;
@@ -387,7 +385,7 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
        if (!skb)
                return -ENOBUFS;
 
-       if (tcf_fill_node(skb, tp, fh, portid, n->nlmsg_seq, 0, event) <= 0) {
+       if (tcf_fill_node(net, skb, tp, fh, portid, n->nlmsg_seq, 0, event) <= 0) {
                kfree_skb(skb);
                return -EINVAL;
        }
@@ -406,8 +404,9 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
                         struct tcf_walker *arg)
 {
        struct tcf_dump_args *a = (void *)arg;
+       struct net *net = sock_net(a->skb->sk);
 
-       return tcf_fill_node(a->skb, tp, n, NETLINK_CB(a->cb->skb).portid,
+       return tcf_fill_node(net, a->skb, tp, n, NETLINK_CB(a->cb->skb).portid,
                             a->cb->nlh->nlmsg_seq, NLM_F_MULTI, RTM_NEWTFILTER);
 }
 
@@ -465,7 +464,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
                if (t > s_t)
                        memset(&cb->args[1], 0, sizeof(cb->args)-sizeof(cb->args[0]));
                if (cb->args[1] == 0) {
-                       if (tcf_fill_node(skb, tp, 0, NETLINK_CB(cb->skb).portid,
+                       if (tcf_fill_node(net, skb, tp, 0, NETLINK_CB(cb->skb).portid,
                                          cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                          RTM_NEWTFILTER) <= 0)
                                break;
@@ -579,7 +578,7 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
                } else if (exts->police) {
                        struct tc_action *act = tcf_exts_first_act(exts);
                        nest = nla_nest_start(skb, exts->police);
-                       if (nest == NULL)
+                       if (nest == NULL || !act)
                                goto nla_put_failure;
                        if (tcf_action_dump_old(skb, act, 0, 0) < 0)
                                goto nla_put_failure;