net: Remove unnecessary returns from void function()s
[safe/jmp/linux-2.6] / net / sched / act_police.c
index 38015b4..654f73d 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/skbuff.h>
 #include <linux/rtnetlink.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <net/act_api.h>
 #include <net/netlink.h>
 
@@ -182,17 +183,31 @@ override:
                R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]);
                if (R_tab == NULL)
                        goto failure;
+
                if (parm->peakrate.rate) {
                        P_tab = qdisc_get_rtab(&parm->peakrate,
                                               tb[TCA_POLICE_PEAKRATE]);
-                       if (P_tab == NULL) {
-                               qdisc_put_rtab(R_tab);
+                       if (P_tab == NULL)
                                goto failure;
-                       }
                }
        }
-       /* No failure allowed after this point */
+
        spin_lock_bh(&police->tcf_lock);
+       if (est) {
+               err = gen_replace_estimator(&police->tcf_bstats,
+                                           &police->tcf_rate_est,
+                                           &police->tcf_lock, est);
+               if (err)
+                       goto failure_unlock;
+       } else if (tb[TCA_POLICE_AVRATE] &&
+                  (ret == ACT_P_CREATED ||
+                   !gen_estimator_active(&police->tcf_bstats,
+                                         &police->tcf_rate_est))) {
+               err = -EINVAL;
+               goto failure_unlock;
+       }
+
+       /* No failure allowed after this point */
        if (R_tab != NULL) {
                qdisc_put_rtab(police->tcfp_R_tab);
                police->tcfp_R_tab = R_tab;
@@ -217,10 +232,6 @@ override:
 
        if (tb[TCA_POLICE_AVRATE])
                police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]);
-       if (est)
-               gen_replace_estimator(&police->tcf_bstats,
-                                     &police->tcf_rate_est,
-                                     &police->tcf_lock, est);
 
        spin_unlock_bh(&police->tcf_lock);
        if (ret != ACT_P_CREATED)
@@ -238,7 +249,13 @@ override:
        a->priv = police;
        return ret;
 
+failure_unlock:
+       spin_unlock_bh(&police->tcf_lock);
 failure:
+       if (P_tab)
+               qdisc_put_rtab(P_tab);
+       if (R_tab)
+               qdisc_put_rtab(R_tab);
        if (ret == ACT_P_CREATED)
                kfree(police);
        return err;
@@ -278,6 +295,8 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
        if (police->tcfp_ewma_rate &&
            police->tcf_rate_est.bps >= police->tcfp_ewma_rate) {
                police->tcf_qstats.overlimits++;
+               if (police->tcf_action == TC_ACT_SHOT)
+                       police->tcf_qstats.drops++;
                spin_unlock(&police->tcf_lock);
                return police->tcf_action;
        }
@@ -311,6 +330,8 @@ static int tcf_act_police(struct sk_buff *skb, struct tc_action *a,
        }
 
        police->tcf_qstats.overlimits++;
+       if (police->tcf_action == TC_ACT_SHOT)
+               police->tcf_qstats.drops++;
        spin_unlock(&police->tcf_lock);
        return police->tcf_action;
 }