All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Fastabend <john.r.fastabend@intel.com>
To: Cong Wang <xiyou.wangcong@gmail.com>, netdev@vger.kernel.org
Cc: john.fastabend@gmail.com, "David S. Miller" <davem@davemloft.net>
Subject: Re: [Patch net-next 5/5] net_sched: clean up tcindex_set_parms()
Date: Mon, 15 Sep 2014 15:09:35 -0700	[thread overview]
Message-ID: <5417639F.10008@intel.com> (raw)
In-Reply-To: <1410815210-6693-6-git-send-email-xiyou.wangcong@gmail.com>

On 09/15/2014 02:06 PM, Cong Wang wrote:
> We can move the allocation down.
> 
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  net/sched/cls_tcindex.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
> index 4ec99a6..688ab75 100644
> --- a/net/sched/cls_tcindex.c
> +++ b/net/sched/cls_tcindex.c
> @@ -229,7 +229,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
>  	struct tcindex_filter_result new_filter_result, *old_r = r;
>  	struct tcindex_filter_result cr;
>  	struct tcindex_data *cp, *oldp;
> -	struct tcindex_filter *f = NULL; /* make gcc behave */
>  	struct tcf_exts e;
>  
>  	tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
> @@ -348,12 +347,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
>  	else
>  		r = tcindex_lookup(cp, handle) ? : &new_filter_result;
>  
> -	if (r == &new_filter_result) {
> -		f = kzalloc(sizeof(*f), GFP_KERNEL);
> -		if (!f)
> -			goto errout_alloc;
> -	}
> -

It was put here to avoid having logic to unwind the state when/if the
malloc fails.

>  	if (tb[TCA_TCINDEX_CLASSID]) {
>  		cr.res.classid = nla_get_u32(tb[TCA_TCINDEX_CLASSID]);
>  		tcf_bind_filter(tp, &cr.res, base);
> @@ -374,6 +367,11 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
>  	if (r == &new_filter_result) {
>  		struct tcindex_filter *nfp;
>  		struct tcindex_filter __rcu **fp;
> +		struct tcindex_filter *f;
> +
> +		f = kzalloc(sizeof(*f), GFP_KERNEL);
> +		if (!f)
> +			goto errout_alloc;

I don't think its safe to bail out here, you've already done
the tcf_exts_change and rcu_assign_pointer() then you free it
down below leaving tp->root corrupted?

Thanks,
John

>  
>  		f->key = handle;
>  		f->result = new_filter_result;
> 

  parent reply	other threads:[~2014-09-15 22:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15 21:06 [Patch net-next 0/5] net_sched: some fixes and cleanup for tcindex Cong Wang
2014-09-15 21:06 ` [Patch net-next 1/5] net_sched: fix an allocation bug in tcindex_set_parms() Cong Wang
2014-09-15 21:48   ` David Miller
2014-09-15 21:06 ` [Patch net-next 2/5] net_sched: fix memory leak in cls_tcindex Cong Wang
2014-09-15 21:41   ` John Fastabend
2014-09-15 22:15     ` Cong Wang
2014-09-15 22:46       ` Cong Wang
2014-09-15 21:49   ` David Miller
2014-09-15 21:06 ` [Patch net-next 3/5] net_sched: fix suspicious RCU usage in tcindex_classify() Cong Wang
2014-09-15 21:29   ` John Fastabend
2014-09-15 21:50   ` David Miller
2014-09-15 21:06 ` [Patch net-next 4/5] net_sched: use tcindex_filter_result_init() Cong Wang
2014-09-15 21:51   ` David Miller
2014-09-15 21:06 ` [Patch net-next 5/5] net_sched: clean up tcindex_set_parms() Cong Wang
2014-09-15 21:52   ` David Miller
2014-09-15 22:09   ` John Fastabend [this message]
2014-09-15 23:39     ` Cong Wang

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=5417639F.10008@intel.com \
    --to=john.r.fastabend@intel.com \
    --cc=davem@davemloft.net \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.