netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, Cong Wang <xiyou.wangcong@gmail.com>
Subject: [Patch net v4 6/7] net_sched: unify the init logic for act_police
Date: Sat, 13 Aug 2016 22:35:01 -0700	[thread overview]
Message-ID: <1471152902-12444-7-git-send-email-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <1471152902-12444-1-git-send-email-xiyou.wangcong@gmail.com>

Jamal reported a crash when we create a police action
with a specific index, this is because the init logic
is not correct, we should always create one for this
case. Just unify the logic with other tc actions.

Fixes: a03e6fe56971 ("act_police: fix a crash during removal")
Reported-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/act_police.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index b3c7e97..259352d 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -125,6 +125,7 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
 	struct tcf_police *police;
 	struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
 	struct tc_action_net *tn = net_generic(net, police_net_id);
+	bool exists = false;
 	int size;
 
 	if (nla == NULL)
@@ -139,24 +140,24 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
 	size = nla_len(tb[TCA_POLICE_TBF]);
 	if (size != sizeof(*parm) && size != sizeof(struct tc_police_compat))
 		return -EINVAL;
+
 	parm = nla_data(tb[TCA_POLICE_TBF]);
+	exists = tcf_hash_check(tn, parm->index, a, bind);
+	if (exists && bind)
+		return 0;
 
-	if (parm->index) {
-		if (tcf_hash_check(tn, parm->index, a, bind)) {
-			if (ovr)
-				goto override;
-			/* not replacing */
-			return -EEXIST;
-		}
-	} else {
+	if (!exists) {
 		ret = tcf_hash_create(tn, parm->index, NULL, a,
 				      &act_police_ops, bind, false);
 		if (ret)
 			return ret;
 		ret = ACT_P_CREATED;
+	} else {
+		tcf_hash_release(*a, bind);
+		if (!ovr)
+			return -EEXIST;
 	}
 
-override:
 	police = to_police(*a);
 	if (parm->rate.rate) {
 		err = -ENOMEM;
-- 
1.8.4.5

  parent reply	other threads:[~2016-08-14  9:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-14  5:34 [Patch net v4 0/7] net_sched: tc action fixes and updates Cong Wang
2016-08-14  5:34 ` [Patch net v4 1/7] net_sched: remove the leftover cleanup_a() Cong Wang
2016-08-14 11:01   ` Jamal Hadi Salim
2016-08-14  5:34 ` [Patch net v4 2/7] net_sched: remove an unnecessary list_del() Cong Wang
2016-08-14 11:01   ` Jamal Hadi Salim
2016-08-14  5:34 ` [Patch net v4 3/7] net_sched: fix a typo in tc_for_each_action() Cong Wang
2016-08-14 11:02   ` Jamal Hadi Salim
2016-08-14  5:34 ` [Patch net v4 4/7] net_sched: move tc offload macros to pkt_cls.h Cong Wang
2016-08-14 11:03   ` Jamal Hadi Salim
2016-08-14  5:35 ` [Patch net v4 5/7] net_sched: convert tcf_exts from list to pointer array Cong Wang
2016-08-14 11:04   ` Jamal Hadi Salim
2016-08-14  5:35 ` Cong Wang [this message]
2016-08-14 11:04   ` [Patch net v4 6/7] net_sched: unify the init logic for act_police Jamal Hadi Salim
2016-08-14  5:35 ` [Patch net v4 7/7] net_sched: allow flushing tc police actions Cong Wang
2016-08-14 11:05   ` Jamal Hadi Salim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471152902-12444-7-git-send-email-xiyou.wangcong@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).