Commit aa3fab01 authored by David S. Miller's avatar David S. Miller

Merge branch 'net_sched-redundant-resource-cleanups'

Zhengchao Shao says:

====================
net: sched: remove redundant resource cleanup when init() fails

qdisc_create() calls .init() to initialize qdisc. If the initialization
fails, qdisc_create() will call .destroy() to release resources.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 40c79ce1 d59f4e1d
...@@ -478,26 +478,24 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -478,26 +478,24 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
if (opt) { if (opt) {
err = fq_codel_change(sch, opt, extack); err = fq_codel_change(sch, opt, extack);
if (err) if (err)
goto init_failure; return err;
} }
err = tcf_block_get(&q->block, &q->filter_list, sch, extack); err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
if (err) if (err)
goto init_failure; return err;
if (!q->flows) { if (!q->flows) {
q->flows = kvcalloc(q->flows_cnt, q->flows = kvcalloc(q->flows_cnt,
sizeof(struct fq_codel_flow), sizeof(struct fq_codel_flow),
GFP_KERNEL); GFP_KERNEL);
if (!q->flows) { if (!q->flows)
err = -ENOMEM; return -ENOMEM;
goto init_failure;
}
q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL); q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL);
if (!q->backlogs) { if (!q->backlogs)
err = -ENOMEM; return -ENOMEM;
goto alloc_failure;
}
for (i = 0; i < q->flows_cnt; i++) { for (i = 0; i < q->flows_cnt; i++) {
struct fq_codel_flow *flow = q->flows + i; struct fq_codel_flow *flow = q->flows + i;
...@@ -510,13 +508,6 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -510,13 +508,6 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
else else
sch->flags &= ~TCQ_F_CAN_BYPASS; sch->flags &= ~TCQ_F_CAN_BYPASS;
return 0; return 0;
alloc_failure:
kvfree(q->flows);
q->flows = NULL;
init_failure:
q->flows_cnt = 0;
return err;
} }
static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb) static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
......
...@@ -1102,7 +1102,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -1102,7 +1102,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
err = qdisc_class_hash_init(&q->clhash); err = qdisc_class_hash_init(&q->clhash);
if (err < 0) if (err < 0)
goto err_free_direct_qdiscs; return err;
if (tb[TCA_HTB_DIRECT_QLEN]) if (tb[TCA_HTB_DIRECT_QLEN])
q->direct_qlen = nla_get_u32(tb[TCA_HTB_DIRECT_QLEN]); q->direct_qlen = nla_get_u32(tb[TCA_HTB_DIRECT_QLEN]);
...@@ -1123,8 +1123,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -1123,8 +1123,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops, qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
TC_H_MAKE(sch->handle, 0), extack); TC_H_MAKE(sch->handle, 0), extack);
if (!qdisc) { if (!qdisc) {
err = -ENOMEM; return -ENOMEM;
goto err_free_qdiscs;
} }
htb_set_lockdep_class_child(qdisc); htb_set_lockdep_class_child(qdisc);
...@@ -1142,7 +1141,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -1142,7 +1141,7 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
}; };
err = htb_offload(dev, &offload_opt); err = htb_offload(dev, &offload_opt);
if (err) if (err)
goto err_free_qdiscs; return err;
/* Defer this assignment, so that htb_destroy skips offload-related /* Defer this assignment, so that htb_destroy skips offload-related
* parts (especially calling ndo_setup_tc) on errors. * parts (especially calling ndo_setup_tc) on errors.
...@@ -1150,22 +1149,6 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt, ...@@ -1150,22 +1149,6 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
q->offload = true; q->offload = true;
return 0; return 0;
err_free_qdiscs:
for (ntx = 0; ntx < q->num_direct_qdiscs && q->direct_qdiscs[ntx];
ntx++)
qdisc_put(q->direct_qdiscs[ntx]);
qdisc_class_hash_destroy(&q->clhash);
/* Prevent use-after-free and double-free when htb_destroy gets called.
*/
q->clhash.hash = NULL;
q->clhash.hashsize = 0;
err_free_direct_qdiscs:
kfree(q->direct_qdiscs);
q->direct_qdiscs = NULL;
return err;
} }
static void htb_attach_offload(struct Qdisc *sch) static void htb_attach_offload(struct Qdisc *sch)
...@@ -1688,13 +1671,12 @@ static void htb_destroy(struct Qdisc *sch) ...@@ -1688,13 +1671,12 @@ static void htb_destroy(struct Qdisc *sch)
qdisc_class_hash_destroy(&q->clhash); qdisc_class_hash_destroy(&q->clhash);
__qdisc_reset_queue(&q->direct_queue); __qdisc_reset_queue(&q->direct_queue);
if (!q->offload) if (q->offload) {
return; offload_opt = (struct tc_htb_qopt_offload) {
.command = TC_HTB_DESTROY,
offload_opt = (struct tc_htb_qopt_offload) { };
.command = TC_HTB_DESTROY, htb_offload(dev, &offload_opt);
}; }
htb_offload(dev, &offload_opt);
if (!q->direct_qdiscs) if (!q->direct_qdiscs)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment