netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] act_nat: use stack variable
@ 2010-06-30  9:07 Changli Gao
  2010-06-30 10:25 ` jamal
  0 siblings, 1 reply; 4+ messages in thread
From: Changli Gao @ 2010-06-30  9:07 UTC (permalink / raw)
  To: Jamal Hadi Salim; +Cc: Herbert Xu, David S. Miller, netdev, Changli Gao

act_nat: use stack variable

structure tc_nat isn't too big for stack, so we can put it in stack.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
 net/sched/act_nat.c |   31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 5709494..0be49a4 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -265,40 +265,29 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a,
 {
 	unsigned char *b = skb_tail_pointer(skb);
 	struct tcf_nat *p = a->priv;
-	struct tc_nat *opt;
+	struct tc_nat opt;
 	struct tcf_t t;
-	int s;
 
-	s = sizeof(*opt);
+	opt.old_addr = p->old_addr;
+	opt.new_addr = p->new_addr;
+	opt.mask = p->mask;
+	opt.flags = p->flags;
 
-	/* netlink spinlocks held above us - must use ATOMIC */
-	opt = kzalloc(s, GFP_ATOMIC);
-	if (unlikely(!opt))
-		return -ENOBUFS;
+	opt.index = p->tcf_index;
+	opt.action = p->tcf_action;
+	opt.refcnt = p->tcf_refcnt - ref;
+	opt.bindcnt = p->tcf_bindcnt - bind;
 
-	opt->old_addr = p->old_addr;
-	opt->new_addr = p->new_addr;
-	opt->mask = p->mask;
-	opt->flags = p->flags;
-
-	opt->index = p->tcf_index;
-	opt->action = p->tcf_action;
-	opt->refcnt = p->tcf_refcnt - ref;
-	opt->bindcnt = p->tcf_bindcnt - bind;
-
-	NLA_PUT(skb, TCA_NAT_PARMS, s, opt);
+	NLA_PUT(skb, TCA_NAT_PARMS, sizeof(opt), &opt);
 	t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install);
 	t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse);
 	t.expires = jiffies_to_clock_t(p->tcf_tm.expires);
 	NLA_PUT(skb, TCA_NAT_TM, sizeof(t), &t);
 
-	kfree(opt);
-
 	return skb->len;
 
 nla_put_failure:
 	nlmsg_trim(skb, b);
-	kfree(opt);
 	return -1;
 }
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] act_nat: use stack variable
  2010-06-30  9:07 [PATCH] act_nat: use stack variable Changli Gao
@ 2010-06-30 10:25 ` jamal
  2010-06-30 10:30   ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: jamal @ 2010-06-30 10:25 UTC (permalink / raw)
  To: Changli Gao; +Cc: Herbert Xu, David S. Miller, netdev

On Wed, 2010-06-30 at 17:07 +0800, Changli Gao wrote:
> act_nat: use stack variable
> 
> structure tc_nat isn't too big for stack, so we can put it in stack.
> 
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>

Doesnt look unreasonable - will let Herbert make the call..

cheers,
jamal


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] act_nat: use stack variable
  2010-06-30 10:25 ` jamal
@ 2010-06-30 10:30   ` Herbert Xu
  2010-06-30 19:12     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2010-06-30 10:30 UTC (permalink / raw)
  To: jamal; +Cc: Changli Gao, David S. Miller, netdev

On Wed, Jun 30, 2010 at 06:25:21AM -0400, jamal wrote:
> On Wed, 2010-06-30 at 17:07 +0800, Changli Gao wrote:
> > act_nat: use stack variable
> > 
> > structure tc_nat isn't too big for stack, so we can put it in stack.
> > 
> > Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> 
> Doesnt look unreasonable - will let Herbert make the call..

Looks good to me too.

Thanks!
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] act_nat: use stack variable
  2010-06-30 10:30   ` Herbert Xu
@ 2010-06-30 19:12     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2010-06-30 19:12 UTC (permalink / raw)
  To: herbert; +Cc: hadi, xiaosuo, netdev

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 30 Jun 2010 18:30:05 +0800

> On Wed, Jun 30, 2010 at 06:25:21AM -0400, jamal wrote:
>> On Wed, 2010-06-30 at 17:07 +0800, Changli Gao wrote:
>> > act_nat: use stack variable
>> > 
>> > structure tc_nat isn't too big for stack, so we can put it in stack.
>> > 
>> > Signed-off-by: Changli Gao <xiaosuo@gmail.com>
>> 
>> Doesnt look unreasonable - will let Herbert make the call..
> 
> Looks good to me too.

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-06-30 19:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-30  9:07 [PATCH] act_nat: use stack variable Changli Gao
2010-06-30 10:25 ` jamal
2010-06-30 10:30   ` Herbert Xu
2010-06-30 19:12     ` David Miller

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).