Message ID | 1410815210-6693-6-git-send-email-xiyou.wangcong@gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
From: Cong Wang <xiyou.wangcong@gmail.com> Date: Mon, 15 Sep 2014 14:06:50 -0700 > We can move the allocation down. > > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> I'll give John time to review this. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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; > -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Sep 15, 2014 at 3:09 PM, John Fastabend <john.r.fastabend@intel.com> wrote: > On 09/15/2014 02:06 PM, Cong Wang wrote: >> - 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. > Right, some operation after that is not undoable so we have to keep it there. So drop this one. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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; - } - 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; f->key = handle; f->result = new_filter_result;
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(-)