Skip to contentSkip to conversation

net_sched: move tp->root allocation into route4_init()

PATCH Applied Cong Wang 4 participants 7 messages Mar 5, 2015 – Mar 6, 2015

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: move tp->root allocation into route4_init()

Cc Jamal Hadi Salim <[email protected]>
---
 net/sched/cls_route.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/sched/cls_route.c +7 -7
index 2ecd246..bb8a602 100644
@@ -258,6 +258,13 @@ static unsigned long route4_get(struct tcf_proto *tp, u32 handle)
 
 static int route4_init(struct tcf_proto *tp)
 {
+	struct route4_head *head;
+
+	head = kzalloc(sizeof(struct route4_head), GFP_KERNEL);
+	if (head == NULL)
+		return -ENOBUFS;
+
+	rcu_assign_pointer(tp->root, head);
 	return 0;
 }
 
@@ -484,13 +491,6 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
 			return -EINVAL;
 
 	err = -ENOBUFS;
-	if (head == NULL) {
-		head = kzalloc(sizeof(struct route4_head), GFP_KERNEL);
-		if (head == NULL)
-			goto errout;
-		rcu_assign_pointer(tp->root, head);
-	}
-
 	f = kzalloc(sizeof(struct route4_filter), GFP_KERNEL);
 	if (!f)
 		goto errout;
Signature · 1 line
1.8.1.4
author
#1 lore raw

PATCH 1/1 net_sched: move tp->root allocation into fw_init()

Cc Jamal Hadi Salim <[email protected]>
---
 net/sched/cls_fw.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
net/sched/cls_fw.c +13 -10
index a5269f7..9d9aa3e 100644
@@ -33,6 +33,7 @@
 
 struct fw_head {
 	u32			mask;
+	bool			mask_set;
 	struct fw_filter __rcu	*ht[HTSIZE];
 	struct rcu_head		rcu;
 };
@@ -113,6 +114,14 @@ static unsigned long fw_get(struct tcf_proto *tp, u32 handle)
 
 static int fw_init(struct tcf_proto *tp)
 {
+	struct fw_head *head;
+
+	head = kzalloc(sizeof(struct fw_head), GFP_KERNEL);
+	if (head == NULL)
+		return -ENOBUFS;
+
+	head->mask_set = false;
+	rcu_assign_pointer(tp->root, head);
 	return 0;
 }
 
@@ -286,17 +295,11 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 	if (!handle)
 		return -EINVAL;
 
-	if (head == NULL) {
-		u32 mask = 0xFFFFFFFF;
+	if (!head->mask_set) {
+		head->mask = 0xFFFFFFFF;
 		if (tb[TCA_FW_MASK])
-			mask = nla_get_u32(tb[TCA_FW_MASK]);
-
-		head = kzalloc(sizeof(struct fw_head), GFP_KERNEL);
-		if (head == NULL)
-			return -ENOBUFS;
-		head->mask = mask;
-
-		rcu_assign_pointer(tp->root, head);
+			head->mask = nla_get_u32(tb[TCA_FW_MASK]);
+		head->mask_set = true;
 	}
 
 	f = kzalloc(sizeof(struct fw_filter), GFP_KERNEL);
Signature · 1 line
1.8.1.4
#5 lore raw
In reply to Cong Wang

Hello.

Quoted 11 lines · Cong Wang
Cc Jamal Hadi Salim <[email protected]>
---
  net/sched/cls_route.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
net/sched/cls_route.c +0 -0
index 2ecd246..bb8a602 100644

net/sched/cls_route.c static unsigned long route4_get(struct tcf_proto *tp, u32 handle) · line 263

Quoted 6 lines
net/sched/cls_route.c +3 -0
@@ -258,6 +258,13 @@ static unsigned long route4_get(struct tcf_proto *tp, u32 handle)
 
  static int route4_init(struct tcf_proto *tp)
  {
+	struct route4_head *head;
+
+	head = kzalloc(sizeof(struct route4_head), GFP_KERNEL);

Hm, checkpatch.pl should have suggested using sizeof(*head) instead...

net/sched/cls_route.c static unsigned long route4_get(struct tcf_proto *tp, u32 handle) · line 264

Quoted 1 line
net/sched/cls_route.c +1 -0
+	if (head == NULL)

And using !head instead.

net/sched/cls_route.c static unsigned long route4_get(struct tcf_proto *tp, u32 handle) · line 269

Quoted 5 lines
net/sched/cls_route.c +3 -0
+		return -ENOBUFS;
+
+	rcu_assign_pointer(tp->root, head);
  	return 0;
  }

WBR, Sergei